Skip to content

Commit e178e82

Browse files
authored
[DirectX] Do not flatten GEP chains for unsupported types (#150484)
Fixes #150463 by not processing GEPs for unsupported types such as structs in the DXILFlattenArrays pass.
1 parent 2f53125 commit e178e82

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

llvm/lib/Target/DirectX/DXILFlattenArrays.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,13 @@ bool DXILFlattenArraysVisitor::visitGetElementPtrInst(GetElementPtrInst &GEP) {
263263
// merge the byte offsets. Otherwise, this GEP is itself the root of a GEP
264264
// chain and we need to deterine the root array type
265265
if (auto *PtrOpGEP = dyn_cast<GEPOperator>(PtrOperand)) {
266-
assert(GEPChainInfoMap.contains(PtrOpGEP) &&
267-
"Expected parent GEP to be visited before this GEP");
266+
267+
// If the parent GEP was not processed, then we do not want to process its
268+
// descendants. This can happen if the GEP chain is for an unsupported type
269+
// such as a struct -- we do not flatten structs nor GEP chains for structs
270+
if (!GEPChainInfoMap.contains(PtrOpGEP))
271+
return false;
272+
268273
GEPInfo &PGEPInfo = GEPChainInfoMap[PtrOpGEP];
269274
Info.RootFlattenedArrayType = PGEPInfo.RootFlattenedArrayType;
270275
Info.RootPointerOperand = PGEPInfo.RootPointerOperand;

llvm/test/CodeGen/DirectX/issue-145408-gep-struct-fix.ll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ define void @test_no_transform_of_struct() {
88
; CHECK-NEXT: [[ENTRY:.*:]]
99
; CHECK-NEXT: [[OUTPUTSIZESLOCAL_I:%.*]] = alloca [[STRUCT_RAWSTRUCT8D:%.*]], align 4
1010
; CHECK-NEXT: [[ARRAYINIT_ELEMENT13_I76:%.*]] = getelementptr inbounds nuw [1 x %struct.RawStruct8D], ptr [[OUTPUTSIZESLOCAL_I]], i32 0, i32 0
11+
; CHECK-NEXT: [[ARRAYINIT_ELEMENT13_I76_I1:%.*]] = getelementptr inbounds nuw [8 x i32], ptr [[ARRAYINIT_ELEMENT13_I76]], i32 0, i32 1
1112
; CHECK-NEXT: ret void
1213
;
1314
entry:
1415
%outputSizesLocal.i = alloca %struct.RawStruct8D, align 4
1516
%arrayinit.element13.i76 = getelementptr inbounds nuw [1 x %struct.RawStruct8D], ptr %outputSizesLocal.i, i32 0, i32 0
17+
%arrayinit.element13.i76.i1 = getelementptr inbounds nuw [8 x i32], ptr %arrayinit.element13.i76, i32 0, i32 1
1618
ret void
1719
}

0 commit comments

Comments
 (0)