[llvm] 02455be - [InstCombine] remove unnecessary use check on X >>exact == 0 fold
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 14 09:53:24 PST 2022
Author: Sanjay Patel
Date: 2022-01-14T12:52:16-05:00
New Revision: 02455bea6b9d4bbbb58e9c30f3615cbe472a9477
URL: https://github.com/llvm/llvm-project/commit/02455bea6b9d4bbbb58e9c30f3615cbe472a9477
DIFF: https://github.com/llvm/llvm-project/commit/02455bea6b9d4bbbb58e9c30f3615cbe472a9477.diff
LOG: [InstCombine] remove unnecessary use check on X >>exact == 0 fold
The transform replaces one icmp with another, so we should
not care if the shift has another use.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/icmp-shr.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index c14e28dc4032b..079afa992aa51 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -2213,7 +2213,7 @@ Instruction *InstCombinerImpl::foldICmpShrConstant(ICmpInst &Cmp,
// icmp eq/ne (shr X, Y), 0 --> icmp eq/ne X, 0
Value *X = Shr->getOperand(0);
CmpInst::Predicate Pred = Cmp.getPredicate();
- if (Cmp.isEquality() && Shr->isExact() && Shr->hasOneUse() && C.isZero())
+ if (Cmp.isEquality() && Shr->isExact() && C.isZero())
return new ICmpInst(Pred, X, Cmp.getOperand(1));
const APInt *ShiftVal;
diff --git a/llvm/test/Transforms/InstCombine/icmp-shr.ll b/llvm/test/Transforms/InstCombine/icmp-shr.ll
index 10b7362c9fc2d..45f8eb02b57c9 100644
--- a/llvm/test/Transforms/InstCombine/icmp-shr.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-shr.ll
@@ -508,7 +508,7 @@ define i1 @ashr_exact_ne_0_uses(i32 %X, i32 %Y) {
; CHECK-LABEL: @ashr_exact_ne_0_uses(
; CHECK-NEXT: [[A:%.*]] = ashr exact i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: call void @foo(i32 [[A]])
-; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[A]], 0
+; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[X]], 0
; CHECK-NEXT: ret i1 [[B]]
;
%A = ashr exact i32 %X, %Y
@@ -541,7 +541,7 @@ define i1 @lshr_exact_eq_0_uses(i32 %X, i32 %Y) {
; CHECK-LABEL: @lshr_exact_eq_0_uses(
; CHECK-NEXT: [[A:%.*]] = lshr exact i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: call void @foo(i32 [[A]])
-; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[A]], 0
+; CHECK-NEXT: [[B:%.*]] = icmp eq i32 [[X]], 0
; CHECK-NEXT: ret i1 [[B]]
;
%A = lshr exact i32 %X, %Y
More information about the llvm-commits
mailing list