[llvm] [RISCV] Expand multiplication by `2^N * 3/5/9 + 1` with SHL_ADD (PR #166933)

Piotr Fusik via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 10 07:27:03 PST 2025


================
@@ -944,6 +944,58 @@ define i64 @addmul146(i64 %a, i64 %b) {
   ret i64 %d
 }
 
+define i64 @mul49(i64 %a) {
+; RV64I-LABEL: mul49:
+; RV64I:       # %bb.0:
+; RV64I-NEXT:    li a1, 49
+; RV64I-NEXT:    mul a0, a0, a1
+; RV64I-NEXT:    ret
+;
+; RV64ZBA-LABEL: mul49:
+; RV64ZBA:       # %bb.0:
+; RV64ZBA-NEXT:    slli a1, a0, 4
+; RV64ZBA-NEXT:    sh1add a1, a1, a1
+; RV64ZBA-NEXT:    add a0, a1, a0
----------------
pfusik wrote:

This PR expands mul into 3 instructions, with a possible fold of `zext` into `slli.uw`.
Most of the transforms in `expandMul` expand into three instructions, so I assumed it's okay.
If not (for reasons other than `hasMinSize()` which is handled), I think we should handle that together with the other 3-instruction expansions.

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


More information about the llvm-commits mailing list