[PATCH] D13177: [Bug 24848] Use range metadata to constant fold comparisons between two values
email@example.com via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 25 17:48:48 PDT 2015
hfinkel 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`.
I don't understand your example. If we have:
x <u 2
then Satisfied_CR is indeed [0, 2), and the inverse (x >=u 2) should indeed be [2, 0). But if LHS_CR is [3, 4), then the original predicate is false, because 3 is not less than 2.
More information about the llvm-commits