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 @@ -2868,6 +2868,11 @@ if (isImpliedCondition(LHS, RHS, Q.DL).value_or(false)) return getTrue(ITy); break; + case ICmpInst::ICMP_SLE: + /// SLE follows the same logic as SGE with the LHS and RHS swapped. + if (isImpliedCondition(RHS, LHS, Q.DL).value_or(false)) + return getTrue(ITy); + break; } return nullptr; diff --git a/llvm/test/Transforms/InstSimplify/implies.ll b/llvm/test/Transforms/InstSimplify/implies.ll --- a/llvm/test/Transforms/InstSimplify/implies.ll +++ b/llvm/test/Transforms/InstSimplify/implies.ll @@ -255,3 +255,15 @@ %res = icmp sge i1 %var30, %var29 ret i1 %res } + +; X <=(s) Y == Y ==> X (i1 1 becomes -1 for reasoning) +define i1 @test_sle(i32 %length.i, i32 %i) { +; CHECK-LABEL: @test_sle( +; CHECK-NEXT: ret i1 true +; + %iplus1 = add nsw nuw i32 %i, 1 + %var29 = icmp ult i32 %i, %length.i + %var30 = icmp ult i32 %iplus1, %length.i + %res = icmp sle i1 %var29, %var30 + ret i1 %res +}