[all-commits] [llvm/llvm-project] 2de812: [LangRef] Always allow getelementptr inbounds with...
Nikita Popov via All-commits
all-commits at lists.llvm.org
Thu Jul 6 05:46:59 PDT 2023
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 2de812f3f4e5ffe6557ebcd891517551b08954ea
https://github.com/llvm/llvm-project/commit/2de812f3f4e5ffe6557ebcd891517551b08954ea
Author: Nikita Popov <npopov at redhat.com>
Date: 2023-07-06 (Thu, 06 Jul 2023)
Changed paths:
M llvm/docs/LangRef.rst
Log Message:
-----------
[LangRef] Always allow getelementptr inbounds with zero offset
Currently, our GEP specification has a special case that makes
gep inbounds (null, 0) legal. This patch proposes to expand this
special case to all gep inbounds (ptr, 0), where ptr is no longer
required to point to an allocated object.
This was previously discussed in some detail at
https://discourse.llvm.org/t/question-about-getelementptr-inbounds-with-offset-0/62533.
The motivation for this change is twofold:
* Rust relies on getelementptr inbounds with zero offset to be
legal for arbitrary pointers to support zero-sized types. The
current rules are unclear on whether this is legal or not
(saying that there is a zero-size "allocated object" at every
address may be consistent with our current rules, but more
clarity is desired here).
* The current semantics require us to drop the inbounds flag
when materializing zero-index GEPs, which is done by some
InstCombine transforms. Preserving the inbounds flag can
substantially improve optimization quality in some cases, as
illustrated in D154055.
As far as I know, the only analysis/transforms affected by this
semantics change are:
* A special-case for comparisons with null in CaptureTracking,
which is fixed by D154054. As far as I can tell, that special
case is not particularly valuable and should be recovered by
other transforms.
* Folding gep inbounds undef, idx to poison. We now need to fold
to undef instead (D154215).
Differential Revision: https://reviews.llvm.org/D154051
More information about the All-commits
mailing list