[llvm] [InstCombine] Fold abs(a * abs(b)) --> abs(a * b) (PR #78110)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 15 02:05:44 PST 2024
================
@@ -5,8 +5,57 @@ declare i8 @llvm.abs.i8(i8, i1)
declare i32 @llvm.abs.i32(i32, i1)
declare <4 x i32> @llvm.abs.v4i32(<4 x i32>, i1)
declare <3 x i82> @llvm.abs.v3i82(<3 x i82>, i1)
+declare <2 x i8> @llvm.abs.v2i8(<2 x i8>, i1)
declare void @llvm.assume(i1)
+define i8 @test_abs_abs_a_mul_b_i8(i8 %a, i8 %b) {
+; CHECK-LABEL: @test_abs_abs_a_mul_b_i8(
+; CHECK-NEXT: [[TMP1:%.*]] = mul i8 [[B:%.*]], [[A:%.*]]
+; CHECK-NEXT: [[ABS2:%.*]] = call i8 @llvm.abs.i8(i8 [[TMP1]], i1 true)
+; CHECK-NEXT: ret i8 [[ABS2]]
+;
+ %abs1 = call i8 @llvm.abs.i8(i8 %a, i1 true)
+ %mul = mul i8 %abs1, %b
+ %abs2 = call i8 @llvm.abs.i8(i8 %mul, i1 true)
+ ret i8 %abs2
+}
+
+define i8 @test_abs_a_mul_abs_b_i8(i8 %a, i8 %b) {
+; CHECK-LABEL: @test_abs_a_mul_abs_b_i8(
+; CHECK-NEXT: [[TMP1:%.*]] = mul i8 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[ABS2:%.*]] = call i8 @llvm.abs.i8(i8 [[TMP1]], i1 true)
+; CHECK-NEXT: ret i8 [[ABS2]]
+;
+ %abs1 = call i8 @llvm.abs.i8(i8 %b, i1 true)
+ %mul = mul i8 %abs1, %a
----------------
nikic wrote:
This test variant doesn't really makes sense to me -- it's the same as the previous one, just with different variable *names*. I think what you actually wanted to test is the case where the abs is on the right, so `mul i8 %a, %abs1`. (You'll likely need to "thwart complexity-based canonicalization" for this).
https://github.com/llvm/llvm-project/pull/78110
More information about the llvm-commits
mailing list