This is a patch for InstCombine. It tries to simplify range checks.
Examples:
(icmp sge x, 0) & (icmp slt x, n) --> icmp ult x, n
(icmp slt x, 0) | (icmp sgt x, n) --> icmp ugt x, n
Details
- Reviewers
reames
Diff Detail
Event Timeline
This is already the second version of the patch. The first version was discussed by email.
The main difference to the first version is that I added support for the inverted case: icmp | icmp (in addition to icmp & icmp).
My comments to the original email from Philip:
Is there a reason you're only handling the upper bound phrased as a sgt/sge? Do we canonicalize away the alternate slt/sle formation?
Yes, but as I'm now also handling the inverted case, I have to deal with all the possibilities anyway.
This doesn't need to be a member function does it? A static function would be preferred.
It's a member function because it uses the DL, AT and DT members.
LGTM.
lib/Transforms/InstCombine/InstCombineAndOrXor.cpp | ||
---|---|---|
792 | Minor style: I might hide the boolean parameter behind a helper function. It would help readability at the call site. simplifyRangeCheck(A,B) { return simplifyRangeCheckImpl(A,B,false); } | |
806 | This would be clearer as: Minor, feel free to ignore if you disagree. |
Minor style: I might hide the boolean parameter behind a helper function. It would help readability at the call site.
simplifyRangeCheck(A,B) { return simplifyRangeCheckImpl(A,B,false); }
simplifyInvertedRangeCheck(A,B) { return simplifyRangeCheckImpl(A,B, true); }