[llvm-dev] Question on Aliasing and invariant load hoisting

Tim Northover via llvm-dev llvm-dev at lists.llvm.org
Mon Jul 8 12:28:15 PDT 2019


Hi Venkataramanan,

On Mon, 8 Jul 2019 at 19:31, Venkataramanan Kumar via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> is it because the "obj.a" can alias with "ptr" ?

Yes. At the IR level there's nothing to stop @bar from
getelementptring backwards and accessing other parts of %1.

I believe it would be somewhere between invalid and
implementation-defined[*] at the C or C++ levels, but modelling that
would be quite tricky. I thnk you'd need some kind of finer-grained
escape analysis, supported by metadata (because there are constructs
with otherwise very similar IR that *are* valid, for example if obj
was an int[2]).

Cheers.

Tim.

[*] Casts to/from ints are implementation-defined, so a compiler could
allow it via "(int *)((uintptr_t)x - 4)" regardless of what the
standard otherwise says. I don't recall seeing any discussion on
whether Clang does or wants to do that.


More information about the llvm-dev mailing list