-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Closed
Labels
Description
In #82738, the user raised an issue about commutable instructions.
I have created a PR (#82751) to fix it, but it comes another problem: what if the μ-arch can fuse the instruction pair only if rs1
matches?
For example, for slli+add
fusion (see https://godbolt.org/z/xo6xEoPKe):
slli r0, r0, 1
add r0, r0, r1 // fusible
slli r0, r0, 1
add r0, r1, r0 // not fusible
The μ-arch may not check rs2
, but add
is commutable, we can't guarantee that r0
will always be in rs1
.
In InstCombine, we have InstCombinerImpl::SimplifyAssociativeOrCommutative
:
/// This performs a few simplifications for operators that are associative or
/// commutative:
///
/// Commutative operators:
///
/// 1. Order operands such that they are listed from right (least complex) to
/// left (most complex). This puts constants before unary operators before
/// binary operators.
But do we need or have a way in backend to change the operands order of second instruction when it's commutable?
cc @dtcxzyw @topperc