Nuno
_________________________________________
From: Nikita Popov via llvm-dev
Sent: 04 September 2021 10:17
To: llvm-dev <llvm...@lists.llvm.org>; Arthur Eubanks <aeub...@google.com>
Subject: [llvm-dev] Opaque pointers and i8 GEPs
Hi everyone,
Regards,
Nikita
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
I completely agree. Eventually, I’d like GEP to lose the ability to have multiple type arguments and I think this is a good first step in that direction:
1. Always generate GEPs with i8 offsets with all address calculation in the arithmetic leading up to the operation.
2. Canonicalise all other GEPs to this form.
3. Remove support for other kinds of GEP.
In the back end, a GEP is just a {PTR} + {expression that evaluates to an integer} add operation. That’s what it looks like in any target and it’s the most that we guarantee about memory in the IR, so everything that looks as if it supports more than this adds complexity for no benefit. It also means that we sometimes miss optimisation opportunities because GEPs can encode complex arithmetic expressions that are not CSE’d because they’re a separate and special kind of arithmetic.
David
Does this break the inrange specifier for GEPs? I don't see how we'd be able to use inrange to specify that a GEP can only access a certain element in an allocated object if we use i8 GEPs. CC'ing Peter for more thoughts.Initial inrange proposal: https://lists.llvm.org/pipermail/llvm-dev/2016-July/102472.html
For those not wanting to read the proposal, the idea is to provide a
stricter version of inbounds where the bounds are within some sub-object.
I don't really like the way that this proposal is using LLVM type
information, because LLVM type information is not something that we're
able to make any strong guarantees about for in-memory types and so
anything using LLVM types to define semantics is quite fragile.
I'd much rather see this expressed as a range. You could express this
with llvm.assume with a pair of integer comparisons, there's no need to
tie it to the type info, though it may be desirable to provide a range
as an attribute to avoid needing 5 instructions for the GEP.