[llvm] [InstCombine] Fold abs(a * abs(b)) --> abs(a * b) (PR #78110)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat Feb 17 11:32:27 PST 2024
================
@@ -5,7 +5,136 @@ 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)
+declare void @use(i32)
+
+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: [[A1:%.*]] = urem i8 123, [[A:%.*]]
+; CHECK-NEXT: [[TMP1:%.*]] = mul i8 [[A1]], [[B:%.*]]
+; CHECK-NEXT: [[ABS2:%.*]] = call i8 @llvm.abs.i8(i8 [[TMP1]], i1 true)
+; CHECK-NEXT: ret i8 [[ABS2]]
+;
+ %a1 = urem i8 123, %a
+ %abs1 = call i8 @llvm.abs.i8(i8 %b, i1 true)
+ %mul = mul i8 %a1, %abs1 ; thwart complexity-based canonicalization
----------------
nikic wrote:
Put this comment next to the urem instead.
https://github.com/llvm/llvm-project/pull/78110
More information about the llvm-commits
mailing list