[llvm] [RISCV] Move strength reduction of mul X, 3/5/9*2^N to combine (PR #89966)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 24 11:23:01 PDT 2024


================
@@ -555,8 +555,9 @@ define i64 @add_mul_combine_infinite_loop(i64 %x) {
 ; RV32IMB-NEXT:    sh3add a1, a1, a2
 ; RV32IMB-NEXT:    sh1add a0, a0, a0
 ; RV32IMB-NEXT:    slli a2, a0, 3
-; RV32IMB-NEXT:    addi a0, a2, 2047
-; RV32IMB-NEXT:    addi a0, a0, 1
+; RV32IMB-NEXT:    li a3, 1
+; RV32IMB-NEXT:    slli a3, a3, 11
+; RV32IMB-NEXT:    sh3add a0, a0, a3
----------------
preames wrote:

This case was previously not caught by the "add mul X, 24, Y" pattern because there's two multiplies by 24, and thus it failed the one use check.  Instead, it went through generic "mul X, 3 << 2" expansion, and thus ended with the shift/add.  

With the change, we hit the "(add_like_non_imm12 (shl GPR:$rs1, (XLenVT i)), GPR:$rs2)" pattern - which critically doesn't check if the immediate could be split across two addi.  We should probably adjust this, but it seems a) minor, and b) very very separate.  (And if we had zbb, this would be a bseti anyways.)

https://github.com/llvm/llvm-project/pull/89966


More information about the llvm-commits mailing list