[llvm-dev] missing opt in DAGCombiner ?

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Tue Jul 5 15:58:15 PDT 2016

On 5 July 2016 at 15:42, Lawrence, Peter via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> But IIUC the C/C++ languages require pointer1 and pointer2 to be addresses
> of elements in the same array, So their difference must be (0 mod element-size),

LLVM IR is much less strict about type punning (overlapping objects
wouldn't be a problem, for example) so the DAG combiner is rather
limited in what it can do.

But Clang ought to be emitting "exact" modifiers on the relevant
instructions so that LLVM's mid-end can do the right thing. When I

    unsigned long foo(int *idx1, int *idx2) {
      return 4 * (idx1 - idx2);

I find the shifts get eliminated based on reasoning very similar to yours.



More information about the llvm-dev mailing list