diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index ec05fa99b1b3f..1a15ad4bb6aa6 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -8144,12 +8144,26 @@ isImpliedCondOperands(CmpInst::Predicate Pred, const Value *ALHS, return true; return std::nullopt; + case CmpInst::ICMP_SGT: + case CmpInst::ICMP_SGE: + if (isTruePredicate(CmpInst::ICMP_SLE, ALHS, BLHS, DL, Depth) && + isTruePredicate(CmpInst::ICMP_SLE, BRHS, ARHS, DL, Depth)) + return true; + return std::nullopt; + case CmpInst::ICMP_ULT: case CmpInst::ICMP_ULE: if (isTruePredicate(CmpInst::ICMP_ULE, BLHS, ALHS, DL, Depth) && isTruePredicate(CmpInst::ICMP_ULE, ARHS, BRHS, DL, Depth)) return true; return std::nullopt; + + case CmpInst::ICMP_UGT: + case CmpInst::ICMP_UGE: + if (isTruePredicate(CmpInst::ICMP_ULE, ALHS, BLHS, DL, Depth) && + isTruePredicate(CmpInst::ICMP_ULE, BRHS, ARHS, DL, Depth)) + return true; + return std::nullopt; } } diff --git a/llvm/test/Transforms/InstSimplify/implies.ll b/llvm/test/Transforms/InstSimplify/implies.ll index a7949cc77495e..e94ad62e5e32c 100644 --- a/llvm/test/Transforms/InstSimplify/implies.ll +++ b/llvm/test/Transforms/InstSimplify/implies.ll @@ -271,11 +271,7 @@ define i1 @test_sle(i32 %length.i, i32 %i) { ; X +_{nsw} 1 <(s) Y ==> X <(s) Y define i1 @test_sgt_icmp(i32 %length.i, i32 %i) { ; CHECK-LABEL: @test_sgt_icmp( -; CHECK-NEXT: [[IPLUS1:%.*]] = add nsw i32 [[I:%.*]], 1 -; CHECK-NEXT: [[VAR29:%.*]] = icmp sgt i32 [[LENGTH_I:%.*]], [[I]] -; CHECK-NEXT: [[VAR30:%.*]] = icmp sgt i32 [[LENGTH_I]], [[IPLUS1]] -; CHECK-NEXT: [[RES:%.*]] = icmp ule i1 [[VAR30]], [[VAR29]] -; CHECK-NEXT: ret i1 [[RES]] +; CHECK-NEXT: ret i1 true ; %iplus1 = add nsw i32 %i, 1 %var29 = icmp sgt i32 %length.i, %i @@ -287,11 +283,7 @@ define i1 @test_sgt_icmp(i32 %length.i, i32 %i) { ; X +_{nsw} 1 <=(s) Y ==> X <=(s) Y define i1 @test_sge_icmp(i32 %length.i, i32 %i) { ; CHECK-LABEL: @test_sge_icmp( -; CHECK-NEXT: [[IPLUS1:%.*]] = add nsw i32 [[I:%.*]], 1 -; CHECK-NEXT: [[VAR29:%.*]] = icmp sge i32 [[LENGTH_I:%.*]], [[I]] -; CHECK-NEXT: [[VAR30:%.*]] = icmp sge i32 [[LENGTH_I]], [[IPLUS1]] -; CHECK-NEXT: [[RES:%.*]] = icmp ule i1 [[VAR30]], [[VAR29]] -; CHECK-NEXT: ret i1 [[RES]] +; CHECK-NEXT: ret i1 true ; %iplus1 = add nsw i32 %i, 1 %var29 = icmp sge i32 %length.i, %i @@ -303,11 +295,7 @@ define i1 @test_sge_icmp(i32 %length.i, i32 %i) { ; X +_{nuw} 1 <(u) Y ==> X <(u) Y define i1 @test_ugt_icmp(i32 %length.i, i32 %i) { ; CHECK-LABEL: @test_ugt_icmp( -; CHECK-NEXT: [[IPLUS1:%.*]] = add nuw i32 [[I:%.*]], 1 -; CHECK-NEXT: [[VAR29:%.*]] = icmp ugt i32 [[LENGTH_I:%.*]], [[I]] -; CHECK-NEXT: [[VAR30:%.*]] = icmp ugt i32 [[LENGTH_I]], [[IPLUS1]] -; CHECK-NEXT: [[RES:%.*]] = icmp ule i1 [[VAR30]], [[VAR29]] -; CHECK-NEXT: ret i1 [[RES]] +; CHECK-NEXT: ret i1 true ; %iplus1 = add nuw i32 %i, 1 %var29 = icmp ugt i32 %length.i, %i @@ -319,11 +307,7 @@ define i1 @test_ugt_icmp(i32 %length.i, i32 %i) { ; X +_{nuw} 1 <=(u) Y ==> X <=(u) Y define i1 @test_uge_icmp(i32 %length.i, i32 %i) { ; CHECK-LABEL: @test_uge_icmp( -; CHECK-NEXT: [[IPLUS1:%.*]] = add nuw i32 [[I:%.*]], 1 -; CHECK-NEXT: [[VAR29:%.*]] = icmp uge i32 [[LENGTH_I:%.*]], [[I]] -; CHECK-NEXT: [[VAR30:%.*]] = icmp uge i32 [[LENGTH_I]], [[IPLUS1]] -; CHECK-NEXT: [[RES:%.*]] = icmp ule i1 [[VAR30]], [[VAR29]] -; CHECK-NEXT: ret i1 [[RES]] +; CHECK-NEXT: ret i1 true ; %iplus1 = add nuw i32 %i, 1 %var29 = icmp uge i32 %length.i, %i