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

Sanjoy Das via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 18 12:12:57 PDT 2017


sanjoy added a comment.

In https://reviews.llvm.org/D32143#729140, @spatel wrote:

> 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.


Okay, //that// does not look fishy. :)

> 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."

In that case, (Lower = 18, Upper = 17) is one of the right answer(s).  (Lower = 18, Upper = 13) would be wrong because, e.g., 15 is both in A and in B, but not in (Lower = 18, Upper = 13), and the contract is that "The resultant range is guaranteed to include all elements contained in both input ranges".


https://reviews.llvm.org/D32143





More information about the llvm-commits mailing list