diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/lib/Transforms/InstCombine/InstCombineCompares.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -2247,8 +2247,8 @@ if (ShiftedC.ashr(ShAmtVal) == C) return new ICmpInst(Pred, X, ConstantInt::get(ShrTy, ShiftedC)); } - if (Pred == CmpInst::ICMP_SGT) { - // icmp sgt (ashr X, ShAmtC), C --> icmp sgt X, ((C + 1) << ShAmtC) - 1 + if (Pred == CmpInst::ICMP_SGT || Pred == CmpInst::ICMP_UGT) { + // icmp xgt (ashr X, ShAmtC), C --> icmp xgt X, ((C + 1) << ShAmtC) - 1 APInt ShiftedC = (C + 1).shl(ShAmtVal) - 1; if (!C.isMaxSignedValue() && !(C + 1).shl(ShAmtVal).isMinSignedValue() && (ShiftedC + 1).ashr(ShAmtVal) == (C + 1)) diff --git a/llvm/test/Transforms/InstCombine/icmp-shr-lt-gt.ll b/test/Transforms/InstCombine/icmp-shr-lt-gt.ll --- a/llvm/test/Transforms/InstCombine/icmp-shr-lt-gt.ll +++ b/test/Transforms/InstCombine/icmp-shr-lt-gt.ll @@ -2344,8 +2344,7 @@ define i1 @ashr_ugt_noexact(i8 %x) { ; CHECK-LABEL: @ashr_ugt_noexact( -; CHECK-NEXT: [[S:%.*]] = ashr i8 [[X:%.*]], 3 -; CHECK-NEXT: [[C:%.*]] = icmp ugt i8 [[S]], 10 +; CHECK-NEXT: [[C:%.*]] = icmp ugt i8 [[X:%.*]], 87 ; CHECK-NEXT: ret i1 [[C]] ; %s = ashr i8 %x, 3 @@ -2356,8 +2355,7 @@ define i1 @ashr_uge_noexact(i8 %x) { ; CHECK-LABEL: @ashr_uge_noexact( -; CHECK-NEXT: [[S:%.*]] = ashr i8 [[X:%.*]], 3 -; CHECK-NEXT: [[C:%.*]] = icmp ugt i8 [[S]], 9 +; CHECK-NEXT: [[C:%.*]] = icmp ugt i8 [[X:%.*]], 79 ; CHECK-NEXT: ret i1 [[C]] ; %s = ashr i8 %x, 3 diff --git a/llvm/test/Transforms/InstCombine/icmp-shr.ll b/test/Transforms/InstCombine/icmp-shr.ll --- a/llvm/test/Transforms/InstCombine/icmp-shr.ll +++ b/test/Transforms/InstCombine/icmp-shr.ll @@ -578,8 +578,7 @@ define i1 @ashr_ugt_1(i4 %x) { ; CHECK-LABEL: @ashr_ugt_1( -; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1 -; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[S]], 1 +; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[X:%.*]], 3 ; CHECK-NEXT: ret i1 [[R]] ; %s = ashr i4 %x, 1 @@ -591,8 +590,7 @@ define i1 @ashr_ugt_2(i4 %x) { ; CHECK-LABEL: @ashr_ugt_2( -; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1 -; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[S]], 2 +; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[X:%.*]], 5 ; CHECK-NEXT: ret i1 [[R]] ; %s = ashr i4 %x, 1 @@ -698,8 +696,7 @@ define i1 @ashr_ugt_12(i4 %x) { ; CHECK-LABEL: @ashr_ugt_12( -; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1 -; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[S]], -4 +; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[X:%.*]], -7 ; CHECK-NEXT: ret i1 [[R]] ; %s = ashr i4 %x, 1 @@ -711,8 +708,7 @@ define i1 @ashr_ugt_13(i4 %x) { ; CHECK-LABEL: @ashr_ugt_13( -; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1 -; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[S]], -3 +; CHECK-NEXT: [[R:%.*]] = icmp ugt i4 [[X:%.*]], -5 ; CHECK-NEXT: ret i1 [[R]] ; %s = ashr i4 %x, 1