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

Benjamin Kramer benny.kra at googlemail.com
Sun Mar 25 04:12:58 PDT 2012


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

- Ben
> <simplify-ptr-cmp.diff>_______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits





More information about the llvm-commits mailing list