diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -2979,15 +2979,21 @@ case ICmpInst::ICMP_UGE: return getTrue(ITy); case ICmpInst::ICMP_EQ: - case ICmpInst::ICMP_ULE: + case ICmpInst::ICMP_ULE: { if (isKnownNonZero(LHS, Q.DL, 0, Q.AC, Q.CxtI, Q.DT, Q.IIQ.UseInstrInfo)) return getFalse(ITy); - break; + KnownBits LHSKnown = computeKnownBits(LHS, Q.DL, 0, Q.AC, Q.CxtI, Q.DT); + if (LHSKnown.Zero.isAllOnes()) + return getTrue(ITy); + } break; case ICmpInst::ICMP_NE: - case ICmpInst::ICMP_UGT: + case ICmpInst::ICMP_UGT: { if (isKnownNonZero(LHS, Q.DL, 0, Q.AC, Q.CxtI, Q.DT, Q.IIQ.UseInstrInfo)) return getTrue(ITy); - break; + KnownBits LHSKnown = computeKnownBits(LHS, Q.DL, 0, Q.AC, Q.CxtI, Q.DT); + if (LHSKnown.Zero.isAllOnes()) + return getFalse(ITy); + } break; case ICmpInst::ICMP_SLT: { KnownBits LHSKnown = computeKnownBits(LHS, Q.DL, 0, Q.AC, Q.CxtI, Q.DT); if (LHSKnown.isNegative()) diff --git a/llvm/test/Transforms/InstSimplify/icmp-constant.ll b/llvm/test/Transforms/InstSimplify/icmp-constant.ll --- a/llvm/test/Transforms/InstSimplify/icmp-constant.ll +++ b/llvm/test/Transforms/InstSimplify/icmp-constant.ll @@ -1144,11 +1144,7 @@ define i1 @cmp_ne_0_is_false(i32 %x) { ; CHECK-LABEL: @cmp_ne_0_is_false( -; CHECK-NEXT: [[Y:%.*]] = add i32 [[X:%.*]], 1 -; CHECK-NEXT: [[Z:%.*]] = and i32 [[X]], [[Y]] -; CHECK-NEXT: [[B:%.*]] = and i32 [[Z]], 1 -; CHECK-NEXT: [[E:%.*]] = icmp ne i32 [[B]], 0 -; CHECK-NEXT: ret i1 [[E]] +; CHECK-NEXT: ret i1 false ; %y = add i32 %x, 1 %z = and i32 %x, %y @@ -1159,11 +1155,7 @@ define i1 @cmp_eq_0_is_true(i32 %x) { ; CHECK-LABEL: @cmp_eq_0_is_true( -; CHECK-NEXT: [[Y:%.*]] = add i32 [[X:%.*]], 1 -; CHECK-NEXT: [[Z:%.*]] = and i32 [[X]], [[Y]] -; CHECK-NEXT: [[B:%.*]] = and i32 [[Z]], 1 -; CHECK-NEXT: [[E:%.*]] = icmp eq i32 [[B]], 0 -; CHECK-NEXT: ret i1 [[E]] +; CHECK-NEXT: ret i1 true ; %y = add i32 %x, 1 %z = and i32 %x, %y @@ -1174,11 +1166,7 @@ define <2 x i1> @cmp_ule_0_is_true(<2 x i32> %x) { ; CHECK-LABEL: @cmp_ule_0_is_true( -; CHECK-NEXT: [[Y:%.*]] = add <2 x i32> [[X:%.*]], -; CHECK-NEXT: [[Z:%.*]] = and <2 x i32> [[X]], [[Y]] -; CHECK-NEXT: [[B:%.*]] = and <2 x i32> [[Z]], -; CHECK-NEXT: [[E:%.*]] = icmp ule <2 x i32> [[B]], zeroinitializer -; CHECK-NEXT: ret <2 x i1> [[E]] +; CHECK-NEXT: ret <2 x i1> ; %y = add <2 x i32> %x, %z = and <2 x i32> %x, %y @@ -1189,11 +1177,7 @@ define <2 x i1> @cmp_ugt_0_is_false(<2 x i32> %x) { ; CHECK-LABEL: @cmp_ugt_0_is_false( -; CHECK-NEXT: [[Y:%.*]] = add <2 x i32> [[X:%.*]], -; CHECK-NEXT: [[Z:%.*]] = and <2 x i32> [[X]], [[Y]] -; CHECK-NEXT: [[B:%.*]] = and <2 x i32> [[Z]], -; CHECK-NEXT: [[E:%.*]] = icmp ugt <2 x i32> [[B]], zeroinitializer -; CHECK-NEXT: ret <2 x i1> [[E]] +; CHECK-NEXT: ret <2 x i1> zeroinitializer ; %y = add <2 x i32> %x, %z = and <2 x i32> %x, %y