[llvm] [InstCombine] Add one-use limitation to box multiply fold (PR #72876)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 30 01:34:36 PST 2023


================
@@ -177,6 +177,7 @@ define i64 @mul_full_64_variant2(i64 %a, i64 %b, ptr nocapture %rhi) {
   ret i64 %add27
 }
 
+; Negative test case for mul_fold function: MUL7 is used in more than one place
----------------
nikic wrote:

Taking this test as the base: https://github.com/llvm/llvm-project/blob/81713e893a33ac2807d95addaab0f3c8bb15d911/llvm/test/Transforms/InstCombine/mul_fold.ll#L470-L486C2

You'd want something like this:
```llvm
define i32 @mul32_low_extra_shl_use(i32 %in0, i32 %in1) {
  %In0Lo = and i32 %in0, 65535
  %In0Hi = lshr i32 %in0, 16
  %In1Lo = and i32 %in1, 65535
  %In1Hi = lshr i32 %in1, 16
  %m10 = mul i32 %In1Hi, %In0Lo
  %m01 = mul i32 %In1Lo, %In0Hi
  %m00 = mul i32 %In1Lo, %In0Lo
  %addc = add i32 %m10, %m01
  %shl = shl i32 %addc, 16
  call void @use(i32 %shl)
  %retLo = add i32 %shl, %m00
  ret i32 %retLo
}
```

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


More information about the llvm-commits mailing list