[llvm] [InstCombine]combine mul(abs(x), abs(y)) to abs(mul(x, y)) (PR #78395)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 17 01:23:17 PST 2024
================
@@ -1649,6 +1649,19 @@ define <vscale x 2 x i64> @mul_scalable_splat_zero(<vscale x 2 x i64> %z) {
ret <vscale x 2 x i64> %t3
}
+; fold mul(abs(x),abs(y)) -> abs(mul(x,y))
+define i32 @combine_mul_abs_x_abs_y(i32 %x, i32 %y) {
+; CHECK-LABEL: @combine_mul_abs_x_abs_y(
+; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[MUL:%.*]] = call i32 @llvm.abs.i32(i32 [[TMP1]], i1 true)
+; CHECK-NEXT: ret i32 [[MUL]]
+;
+ %abs_x = call i32 @llvm.abs.i32(i32 %x, i1 false)
+ %abs_y = call i32 @llvm.abs.i32(i32 %y, i1 false)
+ %mul = mul i32 %abs_x, %abs_y
----------------
nikic wrote:
This is a miscompile: https://alive2.llvm.org/ce/z/K3phUB Note that the proof you link in the patch description requires the `nsw` flag, but you fail to check for it. It also requires the abs flags to be true, which you also don't check for.
https://github.com/llvm/llvm-project/pull/78395
More information about the llvm-commits
mailing list