[PATCH] D13177: [Bug 24848] Use range metadata to constant fold comparisons between two values
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 25 17:06:12 PDT 2015
sanjoy added inline comments.
================
Comment at: lib/Analysis/InstructionSimplify.cpp:2427
@@ +2426,3 @@
+ return ConstantInt::getTrue(RHS->getContext());
+ if (InversedSatisfied_CR.contains(LHS_CR))
+ return ConstantInt::getFalse(RHS->getContext());
----------------
I don't think this second is correct. `makeSatisfiedRegion` returns the range of LHS values that is *guaranteed* to satisfy the predicate "Pred RHS". So if `RHS`'s range is `[2, 5)` and `Pred` is `ULT`, then `Satisfied_CR` is `[0, 2)`. `InversedSatisfied_CR` will then be `[2, 0)` (i.e. all integers unsigned greater than or equal to `2`) and so you'll fold the equality to false if `LHS_CR` is `[3,4)`, even though in that case there is a value of `LHS` = `3` for which the equality is `true`.
I think for the negative check you need to do `InverseAllowed_CR.contains(LHS_CR)` where `InverseAllowed_CR` is the inverse of what is returned by `makeAllowedRegion`.
http://reviews.llvm.org/D13177
More information about the llvm-commits
mailing list