summaryrefslogtreecommitdiffstats
path: root/dynamic-layers/clang-layer/recipes-opencl/igc/files/0001-Don-t-accept-nullptr-as-GEP-element-type.patch
diff options
context:
space:
mode:
Diffstat (limited to 'dynamic-layers/clang-layer/recipes-opencl/igc/files/0001-Don-t-accept-nullptr-as-GEP-element-type.patch')
-rw-r--r--dynamic-layers/clang-layer/recipes-opencl/igc/files/0001-Don-t-accept-nullptr-as-GEP-element-type.patch182
1 files changed, 182 insertions, 0 deletions
diff --git a/dynamic-layers/clang-layer/recipes-opencl/igc/files/0001-Don-t-accept-nullptr-as-GEP-element-type.patch b/dynamic-layers/clang-layer/recipes-opencl/igc/files/0001-Don-t-accept-nullptr-as-GEP-element-type.patch
new file mode 100644
index 00000000..0e90023f
--- /dev/null
+++ b/dynamic-layers/clang-layer/recipes-opencl/igc/files/0001-Don-t-accept-nullptr-as-GEP-element-type.patch
@@ -0,0 +1,182 @@
1From 9c68deb3f913a3d055112a28103ec2933ca7b09c Mon Sep 17 00:00:00 2001
2From: Marcin Naczk <marcin.naczk@intel.com>
3Date: Tue, 17 May 2022 10:36:56 +0000
4Subject: [PATCH 1/2] Don't accept nullptr as GEP element type
5
6LLVM13 IR don't accept nullptr as GEP element type
7https://reviews.llvm.org/D105653
8
9Upstream-Status: Backport
10Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
11---
12 IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp | 5 +++--
13 IGC/Compiler/CustomSafeOptPass.cpp | 8 +++++---
14 IGC/Compiler/LegalizationPass.cpp | 3 ++-
15 .../IGCInstCombiner/7.0/InstructionCombining.cpp | 3 ++-
16 .../OpenCLPasses/LocalBuffers/InlineLocalsResolution.cpp | 5 +++--
17 .../ProgramScopeConstantResolution.cpp | 3 ++-
18 IGC/Compiler/Optimizer/Scalarizer.cpp | 3 ++-
19 IGC/Compiler/PromoteResourceToDirectAS.cpp | 6 +++---
20 8 files changed, 22 insertions(+), 14 deletions(-)
21
22diff --git a/IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp b/IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp
23index ae5510c6a..0f4fca87c 100644
24--- a/IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp
25+++ b/IGC/AdaptorOCL/SPIRV/SPIRVReader.cpp
26@@ -3368,17 +3368,18 @@ SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
27 case OpInBoundsPtrAccessChain: {
28 auto AC = static_cast<SPIRVAccessChainBase *>(BV);
29 auto Base = transValue(AC->getBase(), F, BB);
30+ Type *BaseTy = cast<PointerType>(Base->getType())->getPointerElementType();
31 auto Index = transValue(AC->getIndices(), F, BB);
32 if (!AC->hasPtrIndex())
33 Index.insert(Index.begin(), getInt32(M, 0));
34 auto IsInbound = AC->isInBounds();
35 Value *V = nullptr;
36 if (BB) {
37- auto GEP = GetElementPtrInst::Create(nullptr, Base, Index, BV->getName(), BB);
38+ auto GEP = GetElementPtrInst::Create(BaseTy, Base, Index, BV->getName(), BB);
39 GEP->setIsInBounds(IsInbound);
40 V = GEP;
41 } else {
42- V = ConstantExpr::getGetElementPtr(nullptr, dyn_cast<Constant>(Base), Index, IsInbound);
43+ V = ConstantExpr::getGetElementPtr(BaseTy, dyn_cast<Constant>(Base), Index, IsInbound);
44 }
45 return mapValue(BV, V);
46 }
47diff --git a/IGC/Compiler/CustomSafeOptPass.cpp b/IGC/Compiler/CustomSafeOptPass.cpp
48index 83223b3cb..33547077e 100644
49--- a/IGC/Compiler/CustomSafeOptPass.cpp
50+++ b/IGC/Compiler/CustomSafeOptPass.cpp
51@@ -410,7 +410,8 @@ void CustomSafeOptPass::visitAllocaInst(AllocaInst& I)
52 gepArg1 = BinaryOperator::CreateSub(pGEP->getOperand(2), IRB.getInt32(index_lb), "reducedIndex", pGEP);
53 }
54 llvm::Value* gepArg[] = { pGEP->getOperand(1), gepArg1 };
55- llvm::Value* pGEPnew = GetElementPtrInst::Create(nullptr, newAlloca, gepArg, "", pGEP);
56+ Type *BaseTy = cast<PointerType>(newAlloca->getType())->getPointerElementType();
57+ llvm::Value* pGEPnew = GetElementPtrInst::Create(BaseTy, newAlloca, gepArg, "", pGEP);
58 pGEP->replaceAllUsesWith(pGEPnew);
59 }
60 }
61@@ -478,10 +479,11 @@ void CustomSafeOptPass::visitLoadInst(LoadInst& load)
62 SmallVector<Value*, 8> indices;
63 indices.append(gep->idx_begin(), gep->idx_end());
64 indices[selIdx] = sel->getOperand(1);
65- GetElementPtrInst* gep1 = GetElementPtrInst::Create(nullptr, gep->getPointerOperand(), indices, gep->getName(), gep);
66+ Type *BaseTy = cast<PointerType>(gep->getPointerOperand()->getType())->getPointerElementType();
67+ GetElementPtrInst* gep1 = GetElementPtrInst::Create(BaseTy, gep->getPointerOperand(), indices, gep->getName(), gep);
68 gep1->setDebugLoc(gep->getDebugLoc());
69 indices[selIdx] = sel->getOperand(2);
70- GetElementPtrInst* gep2 = GetElementPtrInst::Create(nullptr, gep->getPointerOperand(), indices, gep->getName(), gep);
71+ GetElementPtrInst* gep2 = GetElementPtrInst::Create(BaseTy, gep->getPointerOperand(), indices, gep->getName(), gep);
72 gep2->setDebugLoc(gep->getDebugLoc());
73 LoadInst* load1 = cast<LoadInst>(load.clone());
74 load1->insertBefore(&load);
75diff --git a/IGC/Compiler/LegalizationPass.cpp b/IGC/Compiler/LegalizationPass.cpp
76index 0586e1b40..fbb3fe894 100644
77--- a/IGC/Compiler/LegalizationPass.cpp
78+++ b/IGC/Compiler/LegalizationPass.cpp
79@@ -1568,7 +1568,8 @@ void Legalization::RecursivelyChangePointerType(Instruction* oldPtr, Instruction
80 if (GetElementPtrInst * gep = dyn_cast<GetElementPtrInst>(*II))
81 {
82 SmallVector<Value*, 8> Idx(gep->idx_begin(), gep->idx_end());
83- GetElementPtrInst* newGep = GetElementPtrInst::Create(nullptr, newPtr, Idx, "", gep);
84+ Type *BaseTy = cast<PointerType>(newPtr->getType())->getPointerElementType();
85+ GetElementPtrInst* newGep = GetElementPtrInst::Create(BaseTy, newPtr, Idx, "", gep);
86 RecursivelyChangePointerType(gep, newGep);
87 }
88 else if (LoadInst * load = dyn_cast<LoadInst>(*II))
89diff --git a/IGC/Compiler/Optimizer/IGCInstCombiner/7.0/InstructionCombining.cpp b/IGC/Compiler/Optimizer/IGCInstCombiner/7.0/InstructionCombining.cpp
90index ea5c450fb..94b6bd2be 100644
91--- a/IGC/Compiler/Optimizer/IGCInstCombiner/7.0/InstructionCombining.cpp
92+++ b/IGC/Compiler/Optimizer/IGCInstCombiner/7.0/InstructionCombining.cpp
93@@ -1675,7 +1675,8 @@ Instruction* InstCombiner::visitGetElementPtrInst(GetElementPtrInst& GEP) {
94 auto* NewSrc = cast<GetElementPtrInst>(
95 Builder.CreateGEP(SO0, GO1, Src->getName()));
96 NewSrc->setIsInBounds(Src->isInBounds());
97- auto* NewGEP = GetElementPtrInst::Create(nullptr, NewSrc, { SO1 });
98+ Type *BaseTy = cast<PointerType>(NewSrc->getType())->getPointerElementType();
99+ auto* NewGEP = GetElementPtrInst::Create(BaseTy, NewSrc, { SO1 });
100 NewGEP->setIsInBounds(GEP.isInBounds());
101 return NewGEP;
102 }
103diff --git a/IGC/Compiler/Optimizer/OpenCLPasses/LocalBuffers/InlineLocalsResolution.cpp b/IGC/Compiler/Optimizer/OpenCLPasses/LocalBuffers/InlineLocalsResolution.cpp
104index be585df75..4a31ca474 100644
105--- a/IGC/Compiler/Optimizer/OpenCLPasses/LocalBuffers/InlineLocalsResolution.cpp
106+++ b/IGC/Compiler/Optimizer/OpenCLPasses/LocalBuffers/InlineLocalsResolution.cpp
107@@ -179,9 +179,10 @@ bool InlineLocalsResolution::runOnModule(Module& M)
108 Value* sizeConstant = ConstantInt::get(Type::getInt32Ty(C), Offset);
109 SmallVector<Value*, 1> idx(1, sizeConstant);
110 Instruction* pInsertBefore = &(*F.begin()->getFirstInsertionPt());
111- Type* pLocalCharPtrType = Type::getInt8Ty(C)->getPointerTo(ADDRESS_SPACE_LOCAL);
112+ Type* pCharType = Type::getInt8Ty(C);
113+ Type* pLocalCharPtrType = pCharType->getPointerTo(ADDRESS_SPACE_LOCAL);
114 Instruction* pCharPtr = BitCastInst::CreatePointerCast(arg, pLocalCharPtrType, "localToChar", pInsertBefore);
115- Value* pMovedCharPtr = GetElementPtrInst::Create(nullptr, pCharPtr, idx, "movedLocal", pInsertBefore);
116+ Value* pMovedCharPtr = GetElementPtrInst::Create(pCharType, pCharPtr, idx, "movedLocal", pInsertBefore);
117
118 Value* pMovedPtr = CastInst::CreatePointerCast(pMovedCharPtr, ptrType, "charToLocal", pInsertBefore);
119
120diff --git a/IGC/Compiler/Optimizer/OpenCLPasses/ProgramScopeConstants/ProgramScopeConstantResolution.cpp b/IGC/Compiler/Optimizer/OpenCLPasses/ProgramScopeConstants/ProgramScopeConstantResolution.cpp
121index 64e48a247..d56472191 100644
122--- a/IGC/Compiler/Optimizer/OpenCLPasses/ProgramScopeConstants/ProgramScopeConstantResolution.cpp
123+++ b/IGC/Compiler/Optimizer/OpenCLPasses/ProgramScopeConstants/ProgramScopeConstantResolution.cpp
124@@ -190,7 +190,8 @@ bool ProgramScopeConstantResolution::runOnModule(Module& M)
125 Instruction* pEntryPoint = &(*userFunc->getEntryBlock().getFirstInsertionPt());
126
127 // Create a GEP to get to the right offset in the constant buffer
128- GetElementPtrInst* gep = GetElementPtrInst::Create(nullptr, &*bufArg, pOffset, "off" + pGlobalVar->getName(), pEntryPoint);
129+ Type *BaseTy = cast<PointerType>((&*bufArg)->getType())->getPointerElementType();
130+ GetElementPtrInst* gep = GetElementPtrInst::Create(BaseTy, &*bufArg, pOffset, "off" + pGlobalVar->getName(), pEntryPoint);
131 // Cast it back to the correct type.
132 CastInst* pNewVal = CastInst::CreatePointerCast(gep, pGlobalVar->getType(), "cast" + pGlobalVar->getName(), pEntryPoint);
133
134diff --git a/IGC/Compiler/Optimizer/Scalarizer.cpp b/IGC/Compiler/Optimizer/Scalarizer.cpp
135index 768cb6da2..75ec2ff0d 100644
136--- a/IGC/Compiler/Optimizer/Scalarizer.cpp
137+++ b/IGC/Compiler/Optimizer/Scalarizer.cpp
138@@ -994,7 +994,8 @@ void ScalarizeFunction::scalarizeInstruction(GetElementPtrInst* GI)
139 auto op1 = baseValue->getType()->isVectorTy() ? operand1[i] : baseValue;
140 auto op2 = indexValue->getType()->isVectorTy() ? operand2[i] : indexValue;
141
142- Value* newGEP = GetElementPtrInst::Create(nullptr, op1, op2, "", GI);
143+ Type *BaseTy = cast<PointerType>(op1->getType())->getPointerElementType();
144+ Value* newGEP = GetElementPtrInst::Create(BaseTy, op1, op2, "", GI);
145 Value* constIndex = ConstantInt::get(Type::getInt32Ty(context()), i);
146 Instruction* insert = InsertElementInst::Create(assembledVector,
147 newGEP, constIndex, "assembled.vect", GI);
148diff --git a/IGC/Compiler/PromoteResourceToDirectAS.cpp b/IGC/Compiler/PromoteResourceToDirectAS.cpp
149index 4d9ccf20c..555b1f9a8 100644
150--- a/IGC/Compiler/PromoteResourceToDirectAS.cpp
151+++ b/IGC/Compiler/PromoteResourceToDirectAS.cpp
152@@ -297,6 +297,7 @@ bool PatchGetElementPtr(const std::vector<Value*>& instList, Type* dstTy, unsign
153 unsigned numInstructions = instList.size();
154 Value* patchedInst = patchedSourcePtr;
155 dstPtr = nullptr;
156+ Type* patchTy = nullptr;
157
158 // Find all the instructions we need to patch, starting from the top.
159 // If there is more than one GEP instruction, we need to patch all of them, as well
160@@ -326,7 +327,6 @@ bool PatchGetElementPtr(const std::vector<Value*>& instList, Type* dstTy, unsign
161
162 if (!patchedInst)
163 {
164- Type* patchTy = nullptr;
165 if (patchInstructions.size() > 0)
166 {
167 // Get the original pointer type before any GEPs or bitcasts modifies it
168@@ -349,9 +349,9 @@ bool PatchGetElementPtr(const std::vector<Value*>& instList, Type* dstTy, unsign
169 llvm::SmallVector<llvm::Value*, 4> gepArgs(gepInst->idx_begin(), gepInst->idx_end());
170 // Create the new GEP instruction
171 if (gepInst->isInBounds())
172- patchedInst = GetElementPtrInst::CreateInBounds(nullptr, patchedInst, gepArgs, "", gepInst);
173+ patchedInst = GetElementPtrInst::CreateInBounds(patchTy, patchedInst, gepArgs, "", gepInst);
174 else
175- patchedInst = GetElementPtrInst::Create(nullptr, patchedInst, gepArgs, "", gepInst);
176+ patchedInst = GetElementPtrInst::Create(patchTy, patchedInst, gepArgs, "", gepInst);
177
178 if (GetElementPtrInst* gepPatchedInst = dyn_cast<GetElementPtrInst>(patchedInst))
179 {
180--
1812.35.3
182