[llvm-commits] PATCH: Simplify comparisons of constant-related pointers, similar to simplifying their difference

Chandler Carruth chandlerc at gmail.com
Sun Mar 25 04:28:44 PDT 2012


On Mar 25, 2012 4:14 AM, "Benjamin Kramer" <benny.kra at googlemail.com> wrote:
>
>
> On 25.03.2012, at 12:51, Chandler Carruth wrote:
>
> > I recently taught instsimplify to compute the constant difference of
two pointers which are constant-derived from a common base. This uses the
same logic to handle comparisons. These show up all over the place due to
C++ pointers-as-iterators comparing against the end iterator.
> >
> > I'll add a test case before committing, but it's nothing surprising.
Just wanted to double check the actual code before moving forward.
>
> Compares are a bit more complicated than subs ;)
>
> - The resulting predicate should be signed, "&foo[-1] u> &foo[0]" --> "-1
s> 0" --> false

Good catch!

> - It should ignore signed pointer compares. We can't reason about them
due to GEP's overflow rules. "&foo[0] <s &foo[1]" can't be folded to "true"
because "foo" could be the maximum signed value for the pointer type.
> - It's only safe with inbounds GEPs, so we don't wrap around at the end
of address space.

Yep. It's actually a bug with the existing logic I suspect; I'll fix the
strip routine to only operate on inbounds geps first and add a test.

However, given inbounds geps, why can't we handle signed comparisons?

>
> - Ben
> > <simplify-ptr-cmp.diff>_______________________________________________
> > llvm-commits mailing list
> > llvm-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20120325/780d0121/attachment.html>


More information about the llvm-commits mailing list