Skip to content

Commit 2108fc5

Browse files
authored
Fix GEP generation for reverse translation of OpCompositeConstruct (#2300)
1 parent 0aab124 commit 2108fc5

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

lib/SPIRV/SPIRVReader.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,7 +2262,7 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
22622262
// store the result of argument
22632263
for (size_t I = 0; I < Constituents.size(); I++) {
22642264
auto *GEP = GetElementPtrInst::Create(
2265-
Constituents[I]->getType(), Alloca, {getInt32(M, I)}, "gep", BB);
2265+
AT, Alloca, {getInt32(M, 0), getInt32(M, I)}, "gep", BB);
22662266
GEP->setIsInBounds(true);
22672267
new StoreInst(Constituents[I], GEP, false, BB);
22682268
}
@@ -2281,7 +2281,7 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
22812281
// store the result of argument
22822282
for (size_t I = 0; I < Constituents.size(); I++) {
22832283
auto *GEP = GetElementPtrInst::Create(
2284-
Constituents[I]->getType(), Alloca, {getInt32(M, I)}, "gep", BB);
2284+
ST, Alloca, {getInt32(M, 0), getInt32(M, I)}, "gep", BB);
22852285
GEP->setIsInBounds(true);
22862286
new StoreInst(Constituents[I], GEP, false, BB);
22872287
}

test/composite_construct_array_non_constant.spvasm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
; CHECK: define spir_func [4 x i8] @non_constant_array_elements(i8 %[[#ARG0:]], i8 %[[#ARG1:]])
99
; CHECK: %[[#ArrayPtr:]] = alloca [4 x i8]
10-
; CHECK: %[[GEP:[0-9a-z.]+]] = getelementptr inbounds i8, ptr %[[#ArrayPtr]], i32 0
10+
; CHECK: %[[GEP:[0-9a-z.]+]] = getelementptr inbounds [4 x i8], ptr %[[#ArrayPtr]], i32 0, i32 0
1111
; CHECK: store i8 %[[#ARG1]], ptr %[[GEP]]
12-
; CHECK: %[[GEP1:[0-9a-z.]+]] = getelementptr inbounds i8, ptr %[[#ArrayPtr]], i32 1
12+
; CHECK: %[[GEP1:[0-9a-z.]+]] = getelementptr inbounds [4 x i8], ptr %[[#ArrayPtr]], i32 0, i32 1
1313
; CHECK: store i8 %[[#ARG0]], ptr %[[GEP1]]
14-
; CHECK: %[[GEP2:[0-9a-z.]+]] = getelementptr inbounds i8, ptr %[[#ArrayPtr]], i32 2
14+
; CHECK: %[[GEP2:[0-9a-z.]+]] = getelementptr inbounds [4 x i8], ptr %[[#ArrayPtr]], i32 0, i32 2
1515
; CHECK: store i8 0, ptr %[[GEP2]]
16-
; CHECK: %[[GEP3:[0-9a-z.]+]] = getelementptr inbounds i8, ptr %[[#ArrayPtr]], i32 3
16+
; CHECK: %[[GEP3:[0-9a-z.]+]] = getelementptr inbounds [4 x i8], ptr %[[#ArrayPtr]], i32 0, i32 3
1717
; CHECK: store i8 10, ptr %[[GEP3]]
1818

1919
; CHECK: %[[LoadArr:[0-9a-z.]+]] = load [4 x i8], ptr %[[#ArrayPtr]]

test/composite_construct_struct_non_constant.spt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
; RUN: llvm-spirv %s -to-binary -o %t.spv
22
; RUN: spirv-val %t.spv
3-
; RUN: llvm-spirv -r %t.spv -o %t.bc
4-
; RUN: llvm-dis %t.bc
5-
; RUN: FileCheck < %t.ll %s
3+
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
4+
; RUN: llvm-dis %t.rev.bc
5+
; RUN: FileCheck < %t.rev.ll %s
66

77
; CHECK: %[[StructTy:[0-9a-z.]+]] = type { float, i32 }
88
; CHECK: %[[#StructPtr:]] = alloca %[[StructTy]]
9-
; CHECK: %[[GEP:[0-9a-z.]+]] = getelementptr inbounds float, ptr %[[#StructPtr]], i32 0
9+
; CHECK: %[[GEP:[0-9a-z.]+]] = getelementptr inbounds %[[StructTy]], ptr %[[#StructPtr]], i32 0, i32 0
1010
; CHECK: store float %[[#]], ptr %[[GEP]]
11-
; CHECK: %[[GEP1:[0-9a-z.]+]] = getelementptr inbounds i32, ptr %[[#StructPtr]], i32 1
11+
; CHECK: %[[GEP1:[0-9a-z.]+]] = getelementptr inbounds %[[StructTy]], ptr %[[#StructPtr]], i32 0, i32 1
1212
; CHECK: store i32 %[[#]], ptr %[[GEP1]]
1313
; CHECK: %[[LoadStr:[0-9a-z.]+]] = load %[[StructTy]], ptr %[[#StructPtr]]
1414
; CHECK: ret %[[StructTy]] %[[LoadStr]]

0 commit comments

Comments
 (0)