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 @@ -2239,7 +2239,7 @@ // those conditions rather than checking them. This is difficult because of // undef/poison (PR34838). if (IsAShr) { - if (Pred == CmpInst::ICMP_SLT || (Pred == CmpInst::ICMP_SGT && IsExact)) { + if (Pred == CmpInst::ICMP_SLT || Pred == CmpInst::ICMP_ULT || IsExact) { // icmp slt (ashr X, ShAmtC), C --> icmp slt X, (C << ShAmtC) // icmp sgt (ashr exact X, ShAmtC), C --> icmp sgt X, (C << ShAmtC) APInt ShiftedC = C.shl(ShAmtVal); 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 @@ -2216,6 +2216,96 @@ ret i1 %c } +define i1 @lashr_00_00_noexact(i8 %x) { +; CHECK-LABEL: @lashr_00_00_noexact( +; CHECK-NEXT: [[C:%.*]] = icmp sgt i8 [[X:%.*]], 79 +; CHECK-NEXT: ret i1 [[C]] +; + %s = ashr i8 %x, 3 + %c = icmp sge i8 %s, 10 + ret i1 %c +} + +define i1 @lashr_00_01_noexact(i8 %x) { +; CHECK-LABEL: @lashr_00_01_noexact( +; CHECK-NEXT: [[C:%.*]] = icmp slt i8 [[X:%.*]], 80 +; CHECK-NEXT: ret i1 [[C]] +; + %s = ashr i8 %x, 3 + %c = icmp slt i8 %s, 10 + ret i1 %c +} + +define i1 @lashr_00_03_noexact(i8 %x) { +; CHECK-LABEL: @lashr_00_03_noexact( +; CHECK-NEXT: [[C:%.*]] = icmp ult i8 [[X:%.*]], 80 +; CHECK-NEXT: ret i1 [[C]] +; + %s = ashr i8 %x, 3 + %c = icmp ult i8 %s, 10 + ret i1 %c +} + +define i1 @lashr_00_00_exact(i8 %x) { +; CHECK-LABEL: @lashr_00_00_exact( +; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[X:%.*]], 80 +; CHECK-NEXT: ret i1 [[C]] +; + %s = ashr exact i8 %x, 3 + %c = icmp ne i8 %s, 10 + ret i1 %c +} + +define i1 @lashr_00_01_exact(i8 %x) { +; CHECK-LABEL: @lashr_00_01_exact( +; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[X:%.*]], 80 +; CHECK-NEXT: ret i1 [[C]] +; + %s = ashr exact i8 %x, 3 + %c = icmp eq i8 %s, 10 + ret i1 %c +} + +define i1 @lashr_00_02_exact(i8 %x) { +; CHECK-LABEL: @lashr_00_02_exact( +; CHECK-NEXT: [[C:%.*]] = icmp sgt i8 [[X:%.*]], 80 +; CHECK-NEXT: ret i1 [[C]] +; + %s = ashr exact i8 %x, 3 + %c = icmp sgt i8 %s, 10 + ret i1 %c +} + +define i1 @lashr_00_03_exact(i8 %x) { +; CHECK-LABEL: @lashr_00_03_exact( +; CHECK-NEXT: [[C:%.*]] = icmp slt i8 [[X:%.*]], 88 +; CHECK-NEXT: ret i1 [[C]] +; + %s = ashr exact i8 %x, 3 + %c = icmp sle i8 %s, 10 + ret i1 %c +} + +define i1 @lashr_00_04_exact(i8 %x) { +; CHECK-LABEL: @lashr_00_04_exact( +; CHECK-NEXT: [[C:%.*]] = icmp ugt i8 [[X:%.*]], 80 +; CHECK-NEXT: ret i1 [[C]] +; + %s = ashr exact i8 %x, 3 + %c = icmp ugt i8 %s, 10 + ret i1 %c +} + +define i1 @lashr_00_05_exact(i8 %x) { +; CHECK-LABEL: @lashr_00_05_exact( +; CHECK-NEXT: [[C:%.*]] = icmp ult i8 [[X:%.*]], 88 +; CHECK-NEXT: ret i1 [[C]] +; + %s = ashr exact i8 %x, 3 + %c = icmp ule i8 %s, 10 + ret i1 %c +} + define i1 @lshrult_01_00_exact(i4 %x) { ; CHECK-LABEL: @lshrult_01_00_exact( ; CHECK-NEXT: ret i1 false 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 @@ -717,8 +717,7 @@ define i1 @ashr_ult_2(i4 %x) { ; CHECK-LABEL: @ashr_ult_2( -; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1 -; CHECK-NEXT: [[R:%.*]] = icmp ult i4 [[S]], 2 +; CHECK-NEXT: [[R:%.*]] = icmp ult i4 [[X:%.*]], 4 ; CHECK-NEXT: ret i1 [[R]] ; %s = ashr i4 %x, 1 @@ -730,8 +729,7 @@ define i1 @ashr_ult_3(i4 %x) { ; CHECK-LABEL: @ashr_ult_3( -; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1 -; CHECK-NEXT: [[R:%.*]] = icmp ult i4 [[S]], 3 +; CHECK-NEXT: [[R:%.*]] = icmp ult i4 [[X:%.*]], 6 ; CHECK-NEXT: ret i1 [[R]] ; %s = ashr i4 %x, 1 @@ -824,8 +822,7 @@ define i1 @ashr_ult_12(i4 %x) { ; CHECK-LABEL: @ashr_ult_12( -; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1 -; CHECK-NEXT: [[R:%.*]] = icmp ult i4 [[S]], -4 +; CHECK-NEXT: [[R:%.*]] = icmp sgt i4 [[X:%.*]], -1 ; CHECK-NEXT: ret i1 [[R]] ; %s = ashr i4 %x, 1 @@ -837,8 +834,7 @@ define i1 @ashr_ult_13(i4 %x) { ; CHECK-LABEL: @ashr_ult_13( -; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1 -; CHECK-NEXT: [[R:%.*]] = icmp ult i4 [[S]], -3 +; CHECK-NEXT: [[R:%.*]] = icmp ult i4 [[X:%.*]], -6 ; CHECK-NEXT: ret i1 [[R]] ; %s = ashr i4 %x, 1 @@ -850,8 +846,7 @@ define i1 @ashr_ult_14(i4 %x) { ; CHECK-LABEL: @ashr_ult_14( -; CHECK-NEXT: [[S:%.*]] = ashr i4 [[X:%.*]], 1 -; CHECK-NEXT: [[R:%.*]] = icmp ult i4 [[S]], -2 +; CHECK-NEXT: [[R:%.*]] = icmp ult i4 [[X:%.*]], -4 ; CHECK-NEXT: ret i1 [[R]] ; %s = ashr i4 %x, 1