[PATCH] D19341: Add micro-optimization for 'icmp slt (or A, B), A' to instsimplify.
Nick Lewycky via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 20 15:06:33 PDT 2016
nlewycky marked 3 inline comments as done.
================
Comment at: lib/Analysis/InstructionSimplify.cpp:2630-2639
@@ +2629,12 @@
+ 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);
+ }
+ }
----------------
Counterexample "(-2|1)<-2" --> "-1<-2" --> "false".
To sanity-check, I wrote a program that enumerates A=[-128..127], B=[-128..127] and emits all the results. That's what convinced me that only the sign bit matters.
http://reviews.llvm.org/D19341
More information about the llvm-commits
mailing list