[llvm] 58b28fa - [InstCombine] Fold mul of abs intrinsic
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 5 03:39:00 PDT 2020
Author: Nikita Popov
Date: 2020-09-05T12:37:45+02:00
New Revision: 58b28fa7a2fd57051f3d2911878776d6f57b18d8
URL: https://github.com/llvm/llvm-project/commit/58b28fa7a2fd57051f3d2911878776d6f57b18d8
DIFF: https://github.com/llvm/llvm-project/commit/58b28fa7a2fd57051f3d2911878776d6f57b18d8.diff
LOG: [InstCombine] Fold mul of abs intrinsic
Same as the existing SPF_ABS fold. We don't need to explicitly
handle NABS, as the negs will get folded away first.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
llvm/test/Transforms/InstCombine/mul.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index 99f19d9663b7..245fd588a523 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -275,6 +275,9 @@ Instruction *InstCombinerImpl::visitMul(BinaryOperator &I) {
SelectPatternFlavor SPF = matchSelectPattern(Op0, X, Y).Flavor;
if (SPF == SPF_ABS || SPF == SPF_NABS)
return BinaryOperator::CreateMul(X, X);
+
+ if (match(Op0, m_Intrinsic<Intrinsic::abs>(m_Value(X))))
+ return BinaryOperator::CreateMul(X, X);
}
// -X * C --> X * -C
diff --git a/llvm/test/Transforms/InstCombine/mul.ll b/llvm/test/Transforms/InstCombine/mul.ll
index 8d00ad560f9c..9959841f813a 100644
--- a/llvm/test/Transforms/InstCombine/mul.ll
+++ b/llvm/test/Transforms/InstCombine/mul.ll
@@ -862,8 +862,7 @@ define <4 x i32> @combine_mul_nabs_v4i32(<4 x i32> %0) {
define i32 @combine_mul_abs_intrin(i32 %x) {
; CHECK-LABEL: @combine_mul_abs_intrin(
-; CHECK-NEXT: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false)
-; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[ABS]], [[ABS]]
+; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[X:%.*]], [[X]]
; CHECK-NEXT: ret i32 [[MUL]]
;
%abs = call i32 @llvm.abs.i32(i32 %x, i1 false)
@@ -873,8 +872,7 @@ define i32 @combine_mul_abs_intrin(i32 %x) {
define i32 @combine_mul_nabs_intrin(i32 %x) {
; CHECK-LABEL: @combine_mul_nabs_intrin(
-; CHECK-NEXT: [[ABS:%.*]] = call i32 @llvm.abs.i32(i32 [[X:%.*]], i1 false)
-; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[ABS]], [[ABS]]
+; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[X:%.*]], [[X]]
; CHECK-NEXT: ret i32 [[MUL]]
;
%abs = call i32 @llvm.abs.i32(i32 %x, i1 false)
More information about the llvm-commits
mailing list