Skip to content

Commit a84a7c2

Browse files
committed
adjust alloca logic and test
1 parent 1554fca commit a84a7c2

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

llvm/lib/Target/DirectX/DXILPrepare.cpp

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -154,20 +154,18 @@ class DXILPrepareModule : public ModulePass {
154154
return nullptr;
155155
}
156156

157+
Type *ValTy = Operand->getType();
157158
// Also omit the bitcast for matching global array types
158-
if (auto *GlobalVar = dyn_cast<GlobalVariable>(Operand)) {
159-
Type *ValTy = GlobalVar->getValueType();
159+
if (auto *GlobalVar = dyn_cast<GlobalVariable>(Operand))
160+
ValTy = GlobalVar->getValueType();
160161

161-
if (auto *ArrTy = dyn_cast<ArrayType>(ValTy)) {
162-
Type *ElTy = ArrTy->getElementType();
163-
if (ElTy == Ty)
164-
return nullptr;
165-
}
166-
}
162+
if (auto *AI = dyn_cast<AllocaInst>(Operand))
163+
ValTy = AI->getAllocatedType();
167164

168-
// Also omit the bitcast for alloca instructions
169-
if (auto *AI = dyn_cast<AllocaInst>(Operand)) {
170-
return nullptr;
165+
if (auto *ArrTy = dyn_cast<ArrayType>(ValTy)) {
166+
Type *ElTy = ArrTy->getElementType();
167+
if (ElTy == Ty)
168+
return nullptr;
171169
}
172170

173171
// finally, drill down GEP instructions until we get the array
@@ -180,13 +178,14 @@ class DXILPrepareModule : public ModulePass {
180178
continue;
181179
}
182180

183-
if (auto *GlobalVar = dyn_cast<GlobalVariable>(OpArg)) {
184-
Type *ValTy = GlobalVar->getValueType();
185-
if (auto *ArrTy = dyn_cast<ArrayType>(ValTy)) {
186-
Type *ElTy = ArrTy->getElementType();
187-
if (ElTy == Ty)
188-
return nullptr;
189-
}
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;
190189
}
191190
break;
192191
}

llvm/test/CodeGen/DirectX/noop_bitcast_global_array_type.ll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,13 @@ define float @testGEPNonConst(i32 %i) local_unnamed_addr {
4141

4242
ret float %v
4343
}
44+
45+
; CHECK-LABEL: testAlloca
46+
define float @testAlloca(i32 %i) local_unnamed_addr {
47+
; CHECK-NEXT: alloca [3 x float], align 4
48+
%arr = alloca [3 x float], align 4
49+
; CHECK-NEXT: getelementptr [3 x float], ptr %arr, i32 1
50+
%gep = getelementptr [3 x float], ptr %arr, i32 1
51+
%v = load float, ptr %gep
52+
ret float %v
53+
}

0 commit comments

Comments
 (0)