[PATCH] D32143: [InstSimplify] use ConstantRange to simplify more and-of-icmps

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 18 06:42:02 PDT 2017


spatel added a comment.

In https://reviews.llvm.org/D32143#728857, @sanjoy wrote:

> > I initially thought I could use equivalence of the intersection with one of the input ranges rather than 'contains', but ConstantRange intersection doesn't work like I expected
>
> Do you mean there are cases where `A.contains(B)` is true but `A.intersect(B)` is not `B`?  If so, that does sound fishy.


I saw the inverse: A.contains(B) is false, but A.intersectsWith(B) is B.

Example:

  define i1 @and_ne_ne(i8 %x) {
    %a = icmp ne i8 %x, 13
    %b = icmp ne i8 %x, 17
    %c = and i1 %a, %b
    ret i1 %c
  }

ConstantRange shows:
A: Lower = 14, Upper = 13
B: Lower = 18, Upper = 17
A.intersectsWith(B) returns B (Lower = 18, Upper = 17).
I thought this would return Lower = 18, Upper = 13 based on the header comment for intersectsWith:
"Return the range that results from the intersection of this range with another range.  
The resultant range is guaranteed to include all elements contained in both input ranges, and to
have the smallest possible set size that does so."


https://reviews.llvm.org/D32143





More information about the llvm-commits mailing list