[llvm] [MacroFusion] Support commutable instructions (PR #82751)
Wang Pengcheng via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 15 02:57:44 PDT 2024
wangpc-pp wrote:
> > I added a `IsCommutable` to control the generation of checking commutable operands, because we may not need it in all cases. @arsenm WDYT?
>
> Wouldn't that be implied by the opcode in the first place? The instruction will already have isCommutable set
We can't simply use the `isCommutable` of `Instruction`, because `CheckOpcode` predicate accepts a list of `Instruction`, we don't know if all opcodes are commutable. And it's hard to get the opcodes in TableGen emitter, we will need to iterate over the `Predicates` to see if there is a `CheckOpcode` predicate.
A workaroud can be like:
```
class SingleFusion<string name, string fieldName, string desc,
Instruction firstInst, Instruction secondInst,
MCInstPredicate firstInstPred = TruePred,
MCInstPredicate secondInstPred = TruePred,
list<FusionPredicate> prolog = [],
list<FusionPredicate> epilog = []>
: SimpleFusion<name, fieldName, desc,
CheckAll<!listconcat(
[CheckOpcode<[firstInst]>],
[firstInstPred])>,
CheckAll<!listconcat(
[CheckOpcode<[secondInst]>],
[secondInstPred])>,
prolog, epilog> {
let IsCommutable = secondInst.isCommutable;
}
def ShiftNAddFusion
: SingleFusion<"shift-n-add-fusion", "HasShiftNAddFusion",
"Enable SLLI+ADD to be fused to shift left by 1/2/3 and add",
SLLI, ADD,
CheckAny<[CheckImmOperand<2, 1>,
CheckImmOperand<2, 2>,
CheckImmOperand<2, 3>]>>;
```
https://github.com/llvm/llvm-project/pull/82751
More information about the llvm-commits
mailing list