Skip to content

Commit 76c4ba6

Browse files
authored
Revert "[DirectX] Array GEPs need two indices (#142853)" and "Adjust bit cast instruction filter for DXIL Prepare pass (#142678)" (#143043)
- This reverts commit 9ab4c16. - This reverts commit 1d6e8ec. Noticed a really weird behavior where release and debug builds have different codegen for loads with geps after this PR. This is going to take a minute to debug and figure out why so revert seems to make the most sense. ```diff diff --git a/llvm/test/CodeGen/DirectX/flatten-array.ll b/llvm/test/CodeGen/DirectX/flatten-array.ll index 47d7b50..efa9efeff13a 100644 --- a/llvm/test/CodeGen/DirectX/flatten-array.ll +++ b/llvm/test/CodeGen/DirectX/flatten-array.ll @@ -123,7 +123,8 @@ define void @gep_4d_test () { @b = internal global [2 x [3 x [4 x i32]]] zeroinitializer, align 16 define void @global_gep_load() { - ; CHECK: load i32, ptr getelementptr inbounds ([24 x i32], ptr @a.1dim, i32 0, i32 6), align 4 + ; CHECK: %1 = getelementptr inbounds [24 x i32], ptr @a.1dim, i32 0, i32 6 + ; CHECK-NEXT: %2 = load i32, ptr %1, align 4 ; CHECK-NEXT: ret void %1 = getelementptr inbounds [2 x [3 x [4 x i32]]], [2 x [3 x [4 x i32]]]* @A, i32 0, i32 0 %2 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i32 0, i32 1 @@ -176,7 +177,8 @@ define void @global_incomplete_gep_chain(i32 %row, i32 %col) { } define void @global_gep_store() { - ; CHECK: store i32 1, ptr getelementptr inbounds ([24 x i32], ptr @b.1dim, i32 0, i32 13), align 4 + ; CHECK: %1 = getelementptr inbounds [24 x i32], ptr @b.1dim, i32 0, i32 13 + ; CHECK-NEXT: store i32 1, ptr %1, align 4 ; CHECK-NEXT: ret void ```
1 parent c212183 commit 76c4ba6

File tree

7 files changed

+82
-158
lines changed

7 files changed

+82
-158
lines changed

llvm/lib/Target/DirectX/DXILFlattenArrays.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,8 @@ bool DXILFlattenArraysVisitor::visitGetElementPtrInstInGEPChainBase(
272272

273273
ArrayType *FlattenedArrayType = GEPInfo.ParentArrayType;
274274
Value *FlatGEP =
275-
Builder.CreateGEP(FlattenedArrayType, GEPInfo.ParendOperand,
276-
{Builder.getInt32(0), FlatIndex},
277-
GEP.getName() + ".flat", GEP.getNoWrapFlags());
275+
Builder.CreateGEP(FlattenedArrayType, GEPInfo.ParendOperand, FlatIndex,
276+
GEP.getName() + ".flat", GEP.isInBounds());
278277

279278
GEP.replaceAllUsesWith(FlatGEP);
280279
GEP.eraseFromParent();

llvm/lib/Target/DirectX/DXILPrepare.cpp

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -148,49 +148,9 @@ class DXILPrepareModule : public ModulePass {
148148
Type *Ty) {
149149
// Omit bitcasts if the incoming value matches the instruction type.
150150
auto It = PointerTypes.find(Operand);
151-
if (It != PointerTypes.end()) {
152-
auto *OpTy = cast<TypedPointerType>(It->second)->getElementType();
153-
if (OpTy == Ty)
151+
if (It != PointerTypes.end())
152+
if (cast<TypedPointerType>(It->second)->getElementType() == Ty)
154153
return nullptr;
155-
}
156-
157-
Type *ValTy = Operand->getType();
158-
// Also omit the bitcast for matching global array types
159-
if (auto *GlobalVar = dyn_cast<GlobalVariable>(Operand))
160-
ValTy = GlobalVar->getValueType();
161-
162-
if (auto *AI = dyn_cast<AllocaInst>(Operand))
163-
ValTy = AI->getAllocatedType();
164-
165-
if (auto *ArrTy = dyn_cast<ArrayType>(ValTy)) {
166-
Type *ElTy = ArrTy->getElementType();
167-
if (ElTy == Ty)
168-
return nullptr;
169-
}
170-
171-
// finally, drill down GEP instructions until we get the array
172-
// that is being accessed, and compare element types
173-
if (ConstantExpr *GEPInstr = dyn_cast<ConstantExpr>(Operand)) {
174-
while (GEPInstr->getOpcode() == Instruction::GetElementPtr) {
175-
Value *OpArg = GEPInstr->getOperand(0);
176-
if (ConstantExpr *NewGEPInstr = dyn_cast<ConstantExpr>(OpArg)) {
177-
GEPInstr = NewGEPInstr;
178-
continue;
179-
}
180-
181-
if (auto *GlobalVar = dyn_cast<GlobalVariable>(OpArg))
182-
ValTy = GlobalVar->getValueType();
183-
if (auto *AI = dyn_cast<AllocaInst>(Operand))
184-
ValTy = AI->getAllocatedType();
185-
if (auto *ArrTy = dyn_cast<ArrayType>(ValTy)) {
186-
Type *ElTy = ArrTy->getElementType();
187-
if (ElTy == Ty)
188-
return nullptr;
189-
}
190-
break;
191-
}
192-
}
193-
194154
// Insert bitcasts where we are removing the instruction.
195155
Builder.SetInsertPoint(&Inst);
196156
// This code only gets hit in opaque-pointer mode, so the type of the

llvm/test/CodeGen/DirectX/flatten-array.ll

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ define void @alloca_4d_test () {
3131
; CHECK-LABEL: gep_2d_test
3232
define void @gep_2d_test () {
3333
; CHECK: [[a:%.*]] = alloca [9 x i32], align 4
34-
; CHECK-COUNT-9: getelementptr inbounds [9 x i32], ptr [[a]], i32 0, i32 {{[0-8]}}
34+
; CHECK-COUNT-9: getelementptr inbounds [9 x i32], ptr [[a]], i32 {{[0-8]}}
3535
; CHECK-NEXT: ret void
3636
%1 = alloca [3 x [3 x i32]], align 4
3737
%g2d0 = getelementptr inbounds [3 x [3 x i32]], [3 x [3 x i32]]* %1, i32 0, i32 0
@@ -53,7 +53,7 @@ define void @gep_2d_test () {
5353
; CHECK-LABEL: gep_3d_test
5454
define void @gep_3d_test () {
5555
; CHECK: [[a:%.*]] = alloca [8 x i32], align 4
56-
; CHECK-COUNT-8: getelementptr inbounds [8 x i32], ptr [[a]], i32 0, i32 {{[0-7]}}
56+
; CHECK-COUNT-8: getelementptr inbounds [8 x i32], ptr [[a]], i32 {{[0-7]}}
5757
; CHECK-NEXT: ret void
5858
%1 = alloca [2 x[2 x [2 x i32]]], align 4
5959
%g3d0 = getelementptr inbounds [2 x[2 x [2 x i32]]], [2 x[2 x [2 x i32]]]* %1, i32 0, i32 0
@@ -76,7 +76,7 @@ define void @gep_3d_test () {
7676
; CHECK-LABEL: gep_4d_test
7777
define void @gep_4d_test () {
7878
; CHECK: [[a:%.*]] = alloca [16 x i32], align 4
79-
; CHECK-COUNT-16: getelementptr inbounds [16 x i32], ptr [[a]], i32 0, i32 {{[0-9]|1[0-5]}}
79+
; CHECK-COUNT-16: getelementptr inbounds [16 x i32], ptr [[a]], i32 {{[0-9]|1[0-5]}}
8080
; CHECK-NEXT: ret void
8181
%1 = alloca [2x[2 x[2 x [2 x i32]]]], align 4
8282
%g4d0 = getelementptr inbounds [2x[2 x[2 x [2 x i32]]]], [2x[2 x[2 x [2 x i32]]]]* %1, i32 0, i32 0
@@ -123,7 +123,8 @@ define void @gep_4d_test () {
123123
@b = internal global [2 x [3 x [4 x i32]]] zeroinitializer, align 16
124124

125125
define void @global_gep_load() {
126-
; CHECK: load i32, ptr getelementptr inbounds ([24 x i32], ptr @a.1dim, i32 0, i32 6), align 4
126+
; CHECK: [[GEP_PTR:%.*]] = getelementptr inbounds [24 x i32], ptr @a.1dim, i32 6
127+
; CHECK: load i32, ptr [[GEP_PTR]], align 4
127128
; CHECK-NEXT: ret void
128129
%1 = getelementptr inbounds [2 x [3 x [4 x i32]]], [2 x [3 x [4 x i32]]]* @a, i32 0, i32 0
129130
%2 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i32 0, i32 1
@@ -141,7 +142,7 @@ define void @global_gep_load_index(i32 %row, i32 %col, i32 %timeIndex) {
141142
; CHECK-NEXT: [[TMP4:%.*]] = add i32 [[TMP2]], [[TMP3]]
142143
; CHECK-NEXT: [[TMP5:%.*]] = mul i32 [[ROW]], 12
143144
; CHECK-NEXT: [[TMP6:%.*]] = add i32 [[TMP4]], [[TMP5]]
144-
; CHECK-NEXT: [[DOTFLAT:%.*]] = getelementptr inbounds [24 x i32], ptr @a.1dim, i32 0, i32 [[TMP6]]
145+
; CHECK-NEXT: [[DOTFLAT:%.*]] = getelementptr inbounds [24 x i32], ptr @a.1dim, i32 [[TMP6]]
145146
; CHECK-NOT: getelementptr inbounds [2 x [3 x [4 x i32]]]{{.*}}
146147
; CHECK-NOT: getelementptr inbounds [3 x [4 x i32]]{{.*}}
147148
; CHECK-NOT: getelementptr inbounds [4 x i32]{{.*}}
@@ -162,7 +163,7 @@ define void @global_incomplete_gep_chain(i32 %row, i32 %col) {
162163
; CHECK-NEXT: [[TMP2:%.*]] = add i32 0, [[TMP1]]
163164
; CHECK-NEXT: [[TMP3:%.*]] = mul i32 [[ROW]], 3
164165
; CHECK-NEXT: [[TMP4:%.*]] = add i32 [[TMP2]], [[TMP3]]
165-
; CHECK-NEXT: [[DOTFLAT:%.*]] = getelementptr inbounds [24 x i32], ptr @a.1dim, i32 0, i32 [[TMP4]]
166+
; CHECK-NEXT: [[DOTFLAT:%.*]] = getelementptr inbounds [24 x i32], ptr @a.1dim, i32 [[TMP4]]
166167
; CHECK-NOT: getelementptr inbounds [2 x [3 x [4 x i32]]]{{.*}}
167168
; CHECK-NOT: getelementptr inbounds [3 x [4 x i32]]{{.*}}
168169
; CHECK-NOT: getelementptr inbounds [4 x i32]{{.*}}
@@ -176,7 +177,8 @@ define void @global_incomplete_gep_chain(i32 %row, i32 %col) {
176177
}
177178

178179
define void @global_gep_store() {
179-
; CHECK: store i32 1, ptr getelementptr inbounds ([24 x i32], ptr @b.1dim, i32 0, i32 13), align 4
180+
; CHECK: [[GEP_PTR:%.*]] = getelementptr inbounds [24 x i32], ptr @b.1dim, i32 13
181+
; CHECK: store i32 1, ptr [[GEP_PTR]], align 4
180182
; CHECK-NEXT: ret void
181183
%1 = getelementptr inbounds [2 x [3 x [4 x i32]]], [2 x [3 x [4 x i32]]]* @b, i32 0, i32 1
182184
%2 = getelementptr inbounds [3 x [4 x i32]], [3 x [4 x i32]]* %1, i32 0, i32 0

llvm/test/CodeGen/DirectX/flatten-bug-117273.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
define internal void @main() {
99
; CHECK-LABEL: define internal void @main() {
1010
; CHECK-NEXT: [[ENTRY:.*:]]
11-
; CHECK-NEXT: [[TMP0:%.*]] = getelementptr [24 x float], ptr @ZerroInitArr.1dim, i32 0, i32 1
11+
; CHECK-NEXT: [[TMP0:%.*]] = getelementptr [24 x float], ptr @ZerroInitArr.1dim, i32 1
1212
; CHECK-NEXT: [[DOTI0:%.*]] = load float, ptr [[TMP0]], align 16
13-
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr [24 x float], ptr @ZerroInitArr.1dim, i32 0, i32 2
13+
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr [24 x float], ptr @ZerroInitArr.1dim, i32 2
1414
; CHECK-NEXT: [[DOTI03:%.*]] = load float, ptr [[TMP1]], align 16
1515
; CHECK-NEXT: ret void
1616
;

0 commit comments

Comments
 (0)