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

Allen zhong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 22 18:04:55 PDT 2022


Allen marked 2 inline comments as done.
Allen added inline comments.


================
Comment at: llvm/lib/Target/AArch64/AArch64ISelLowering.cpp:13599
+    if ((Imm + 1).isPowerOf2() || (Imm - 1).isPowerOf2() ||
+        (1 - Imm).isPowerOf2() || (-1 - Imm).isPowerOf2())
+      return true;
----------------
hiraditya wrote:
> What is the rationale behind checking `Imm+1` etc?
I think it can use **shl + sub** to replace **mul**, such as
https://gcc.godbolt.org/z/szh7Eb9K8

BTW: some other target, such as **RISCVTargetLowering::decomposeMulByConstant** also has such logic


================
Comment at: llvm/test/CodeGen/AArch64/mul_pow2.ll:226
 
+; TODO: mov w8, w0 + lsl x8, x8, #2 should combine into lsl x8, x0, #2
 define i64 @test6_umsubl(i32 %x, i64 %y) {
----------------
will be fixed with D132325


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

https://reviews.llvm.org/D132322



More information about the llvm-commits mailing list