[PATCH] D138708: [SROA] Assert the AllocSize of i8 to be 1
Jannik Silvanus via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 25 05:57:00 PST 2022
jsilvanus created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
jsilvanus requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
When SROA rewrites GEPs, it tries to generate "natural"
GEPs that apply to the underlying type of the alloca.
If that fails, SROA falls back to using an i8-based GEP
with the byte-offset as index.
This however requires the AllocSize of i8 to be 1, which
is not the case with nontrivial alignment requirements,
which may e.g. occur with DXIL.
Add assertions checking this assumption.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D138708
Files:
llvm/lib/Transforms/Scalar/SROA.cpp
Index: llvm/lib/Transforms/Scalar/SROA.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/SROA.cpp
+++ llvm/lib/Transforms/Scalar/SROA.cpp
@@ -1549,9 +1549,13 @@
const Twine &NamePrefix) {
// Create i8 GEP for opaque pointers.
if (Ptr->getType()->isOpaquePointerTy()) {
- if (Offset != 0)
- Ptr = IRB.CreateInBoundsGEP(IRB.getInt8Ty(), Ptr, IRB.getInt(Offset),
+ if (Offset != 0) {
+ Type *Int8Ty = IRB.getInt8Ty();
+ // This may fail due to alignment
+ assert(DL.getTypeAllocSize(Int8Ty) == 1 && "Unexpected I8 size!");
+ Ptr = IRB.CreateInBoundsGEP(Int8Ty, Ptr, IRB.getInt(Offset),
NamePrefix + "sroa_idx");
+ }
return IRB.CreatePointerBitCastOrAddrSpaceCast(Ptr, PointerTy,
NamePrefix + "sroa_cast");
}
@@ -1640,11 +1644,14 @@
Int8PtrOffset = Offset;
}
- OffsetPtr = Int8PtrOffset == 0
- ? Int8Ptr
- : IRB.CreateInBoundsGEP(IRB.getInt8Ty(), Int8Ptr,
- IRB.getInt(Int8PtrOffset),
- NamePrefix + "sroa_raw_idx");
+ Type *Int8Ty = IRB.getInt8Ty();
+ // This may fail due to alignment
+ assert(DL.getTypeAllocSize(Int8Ty) == 1 && "Unexpected I8 size!");
+ OffsetPtr =
+ Int8PtrOffset == 0
+ ? Int8Ptr
+ : IRB.CreateInBoundsGEP(Int8Ty, Int8Ptr, IRB.getInt(Int8PtrOffset),
+ NamePrefix + "sroa_raw_idx");
}
Ptr = OffsetPtr;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138708.477933.patch
Type: text/x-patch
Size: 1663 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221125/d4630bd8/attachment.bin>
More information about the llvm-commits
mailing list