[llvm] b543d28 - [InstCombine] Add one use limitation for (X * C2) << C1 --> X * (C2 << C1)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 21 09:33:57 PDT 2022
Author: chenglin.bi
Date: 2022-04-22T00:32:36+08:00
New Revision: b543d28df7b067dcda833c717a59faa28c1151a1
URL: https://github.com/llvm/llvm-project/commit/b543d28df7b067dcda833c717a59faa28c1151a1
DIFF: https://github.com/llvm/llvm-project/commit/b543d28df7b067dcda833c717a59faa28c1151a1.diff
LOG: [InstCombine] Add one use limitation for (X * C2) << C1 --> X * (C2 << C1)
Follow up D123453, add one-use limitation for
(X * C2) << C1 --> X * (C2 << C1)
to make consistent with
lshr (mul nuw x, MulC), ShAmtC -> mul nuw x, (MulC >> ShAmtC)
Reviewed By: spatel
Differential Revision: https://reviews.llvm.org/D124183
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
llvm/test/Transforms/InstCombine/apint-shift.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
index 89558ee06745c..c58c494ab550d 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp
@@ -972,7 +972,10 @@ Instruction *InstCombinerImpl::visitShl(BinaryOperator &I) {
return BinaryOperator::CreateShl(ConstantExpr::getShl(C2, C1), X);
// (X * C2) << C1 --> X * (C2 << C1)
- if (match(Op0, m_Mul(m_Value(X), m_Constant(C2))))
+ // The one-use check is not strictly necessary, but codegen may not be
+ // able to invert the transform and perf may suffer with an extra mul
+ // instruction.
+ if (match(Op0, m_OneUse(m_Mul(m_Value(X), m_Constant(C2)))))
return BinaryOperator::CreateMul(X, ConstantExpr::getShl(C2, C1));
// shl (zext i1 X), C1 --> select (X, 1 << C1, 0)
diff --git a/llvm/test/Transforms/InstCombine/apint-shift.ll b/llvm/test/Transforms/InstCombine/apint-shift.ll
index 039f263101f53..78f78fcee95d6 100644
--- a/llvm/test/Transforms/InstCombine/apint-shift.ll
+++ b/llvm/test/Transforms/InstCombine/apint-shift.ll
@@ -28,7 +28,7 @@ declare void @use(i55 %0)
define i55 @test6a_negative_oneuse(i55 %A) {
; CHECK-LABEL: @test6a_negative_oneuse(
; CHECK-NEXT: [[B:%.*]] = mul i55 [[A:%.*]], 3
-; CHECK-NEXT: [[C:%.*]] = mul i55 [[A]], 6
+; CHECK-NEXT: [[C:%.*]] = shl i55 [[B]], 1
; CHECK-NEXT: call void @use(i55 [[B]])
; CHECK-NEXT: ret i55 [[C]]
;
More information about the llvm-commits
mailing list