[PATCH] D19341: Add micro-optimization for 'icmp slt (or A, B), A' to instsimplify.

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 20 14:39:48 PDT 2016


majnemer added a subscriber: majnemer.

================
Comment at: lib/Analysis/InstructionSimplify.cpp:2630-2639
@@ +2629,12 @@
+      if (Pred == ICmpInst::ICMP_SLT || Pred == ICmpInst::ICMP_SGE) {
+        bool RHSKnownNonNegative, RHSKnownNegative;
+        bool YKnownNonNegative, YKnownNegative;
+        ComputeSignBit(RHS, RHSKnownNonNegative, RHSKnownNegative, Q.DL, 0,
+                       Q.AC, Q.CxtI, Q.DT);
+        ComputeSignBit(Y, YKnownNonNegative, YKnownNegative, Q.DL, 0, Q.AC,
+                       Q.CxtI, Q.DT);
+        if (RHSKnownNonNegative && YKnownNegative)
+          return Pred == ICmpInst::ICMP_SLT ? getTrue(ITy) : getFalse(ITy);
+        if (RHSKnownNegative || YKnownNonNegative)
+          return Pred == ICmpInst::ICMP_SLT ? getFalse(ITy) : getTrue(ITy);
+      }
----------------
If I understand correctly, you are saying that x|y < x is true if x is negative and y is not negative.
At first blush, this appears to be a specific case of a more general transform: x|y < x is true if x is negative and y has any bits set which are known not to be set in x.


http://reviews.llvm.org/D19341





More information about the llvm-commits mailing list