[PATCH] D114988: [IR] `GetElementPtrInst`: per-index `inrange` support
Roman Lebedev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 2 12:24:22 PST 2021
lebedev.ri created this revision.
lebedev.ri added reviewers: courbet, nlopes, efriedma, reames, jdoerfert, nikic, aaron.ballman, pcc, majnemer.
lebedev.ri added a project: LLVM.
Herald added subscribers: dexonsmith, arphaman, hiraditya.
lebedev.ri requested review of this revision.
This is a follow-up for D22793 <https://reviews.llvm.org/D22793>, and the `[llvm-dev] [RFC] Adding range metadata to array subscripts.`: https://groups.google.com/g/llvm-dev/c/T9o51zB1JHY
As per C 6.5.6p9 / http://eel.is/c++draft/expr.add#4, given
struct S {
int a[3];
int b[3];
int c[3];
};
void bar(int*);
void foo(S* s) {
bar(&s.b[1]);
}
even though the pointer the `bar` receives has 4 `int`s to the left of it and 4 to the right of it,
the only `int`s it can access are one to the left and one to the right.
I.e. it can not go outside of the `S::b`.
But, there is currently no way to represent this in LLVM IR,
and this makes some optimizations impossible.
In my case, i'd like to improve `alloca` splitting,
but this also affects alias analysis.
While that RFC proposed a number of implementation variants,
i think it is obvious that the `inrange` approach is superiour,
because constant expr GEP's already support that,
and because encoding such knowledge via assumes will make it impossible to make use of it.
Now, GEP's can have a large number of indices,
so even though we have (7-1)+(16-1)=21 vacant bits total in `SubclassOptionalData` and `SubclassData`,
we have to support storing the arbitary number of `is index inrange` bits,
so we have to allocate additional trailing objects.
(I suspect there are bugs in this logic, will add better tests.)
I will add clang support in later changes.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D114988
Files:
llvm/docs/LangRef.rst
llvm/include/llvm/Bitcode/LLVMBitCodes.h
llvm/include/llvm/IR/Instructions.h
llvm/include/llvm/IR/Operator.h
llvm/lib/Analysis/ValueTracking.cpp
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/IR/AsmWriter.cpp
llvm/lib/IR/Instruction.cpp
llvm/lib/IR/Instructions.cpp
llvm/lib/IR/Operator.cpp
llvm/test/Assembler/getelementptr.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114988.391422.patch
Type: text/x-patch
Size: 27350 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211202/f755f7a4/attachment.bin>
More information about the llvm-commits
mailing list