[PATCH] D131805: [InstSimplify] sle on i1 also encodes implication

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 15 08:27:59 PDT 2022


This revision was automatically updated to reflect the committed changes.
Closed by commit rGef8c34e9543b: [InstSimplify] sle on i1 also encodes implication (authored by craig.topper).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131805/new/

https://reviews.llvm.org/D131805

Files:
  llvm/lib/Analysis/InstructionSimplify.cpp
  llvm/test/Transforms/InstSimplify/implies.ll


Index: llvm/test/Transforms/InstSimplify/implies.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/implies.ll
+++ 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
+}
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D131805.452685.patch
Type: text/x-patch
Size: 1192 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220815/51161620/attachment.bin>


More information about the llvm-commits mailing list