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,8 @@ // 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_SGE || Pred == CmpInst::ICMP_UGE || + 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,87 @@ 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 +; + %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 +; + %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 +; + %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 +; + %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 +; + %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 +; + %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 +; + %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 +; + %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 +; + %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