[PATCH] D132322: [AArch64][SelectionDAG] Optimize multiplication by constant

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 14 14:24:46 PDT 2022


efriedma added inline comments.


================
Comment at: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:14562
+      // the operand of madd/msub should not be const value.
+      if (!AddSub->hasOneUse() || !isIntOrFPConstant(AddSub->getOperand(1)))
+        return SDValue();
----------------
Do you want to check specifically for a constant that fits into the immediate operand of an add/sub?  If it doesn't fit, it doesn't really matter if it's constant.


================
Comment at: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:14617
+                                    DAG.getConstant(ShiftAmt, DL, MVT::i64));
+  SDValue ShiftedVal1 = DAG.getNode(
+      ISD::SHL, DL, VT, N0, DAG.getConstant(TrailingZeroes, DL, MVT::i64));
----------------
Move computation of "ShiftedVal1" into the if statment?


================
Comment at: llvm/test/CodeGen/AArch64/mul_pow2.ll:306
+; GISEL-NEXT:    sub w0, w8, #1
+; GISEL-NEXT:    ret
+  %mul = mul nsw i32 %x, 6
----------------
There is one other possible sequence here:

```
mov w8, #6
mov w9, #-1
madd w0, w0, w8, w9
```

This is obviously not that exciting in isolation, but it might make sense if we can hoist the "mov" instructions out of a loop.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D132322/new/

https://reviews.llvm.org/D132322



More information about the llvm-commits mailing list