Skip to content

Commit 1f22866

Browse files
jsantillan2017igcbot
authored andcommitted
[Autobackout][FuncReg]Revert of change: be86ca2
Implementation of ICB OOB access code ICBs which are accessed need code to protect agaainst OOB access.
1 parent e8e9345 commit 1f22866

File tree

5 files changed

+40
-129
lines changed

5 files changed

+40
-129
lines changed

IGC/Compiler/CISACodeGen/ShaderCodeGen.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,7 @@ void OptimizeIR(CodeGenContext* const pContext)
14591459
mpm.add(new BreakConstantExpr());
14601460
mpm.add(new IGCConstProp(IGC_IS_FLAG_ENABLED(EnableSimplifyGEP)));
14611461

1462-
if (IGC_IS_FLAG_DISABLED(DisableImmConstantOpt))
1462+
if (IGC_IS_FLAG_DISABLED(DisableImmConstantOpt) && pContext->platform.enableImmConstantOpt())
14631463
{
14641464
mpm.add(createIGCIndirectICBPropagaionPass());
14651465
}
@@ -1570,7 +1570,7 @@ void OptimizeIR(CodeGenContext* const pContext)
15701570
mpm.add(llvm::createGVNPass());
15711571
}
15721572
}
1573-
if (IGC_IS_FLAG_DISABLED(DisableImmConstantOpt))
1573+
if (IGC_IS_FLAG_DISABLED(DisableImmConstantOpt) && pContext->platform.enableImmConstantOpt())
15741574
{
15751575
mpm.add(createIGCIndirectICBPropagaionPass());
15761576
}
@@ -1586,12 +1586,6 @@ void OptimizeIR(CodeGenContext* const pContext)
15861586
mpm.add(createInsertBranchOptPass());
15871587
}
15881588

1589-
// If we have ICBs, need to emit clamp code so OOB access doesn't occur
1590-
if (pContext->getModuleMetaData()->immConstant.data.size())
1591-
{
1592-
mpm.add(createClampICBOOBAccess());
1593-
}
1594-
15951589
if (pContext->m_instrTypes.hasRuntimeValueVector)
15961590
{
15971591
// Optimize extracts from RuntimeValue vectors. It should be executed

IGC/Compiler/CustomSafeOptPass.cpp

Lines changed: 38 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -4382,124 +4382,6 @@ bool IGCConstProp::runOnFunction(Function& F)
43824382
return Changed;
43834383
}
43844384

4385-
static bool isICBOffseted(llvm::LoadInst* inst, uint offset, uint& offsetIntoMergedBuffer)
4386-
{
4387-
Value* ptrVal = inst->getPointerOperand();
4388-
std::vector<Value*> srcInstList;
4389-
IGC::TracePointerSource(ptrVal, false, true, true, srcInstList);
4390-
if (srcInstList.size())
4391-
{
4392-
CallInst* inst = dyn_cast<CallInst>(srcInstList.back());
4393-
GenIntrinsicInst* genIntr = inst ? dyn_cast<GenIntrinsicInst>(inst) : nullptr;
4394-
if (!genIntr || (genIntr->getIntrinsicID() != GenISAIntrinsic::GenISA_RuntimeValue))
4395-
return false;
4396-
4397-
// ICB may contain multiple ICBs merged into one
4398-
// find getelementptr after GenISA_RuntimeValue to find offset to needed ICB in merged ICB
4399-
if (srcInstList.size() >= 2)
4400-
{
4401-
GetElementPtrInst* gep = dyn_cast<GetElementPtrInst>(srcInstList[srcInstList.size() - 2]);
4402-
4403-
if (gep &&
4404-
gep->getNumOperands() == 2 &&
4405-
gep->getOperand(0) == genIntr &&
4406-
genIntr->getType() == PointerType::get(Type::getInt8Ty(inst->getContext()), ADDRESS_SPACE_CONSTANT))
4407-
{
4408-
llvm::ConstantInt* ci = dyn_cast<llvm::ConstantInt>(gep->getOperand(1));
4409-
4410-
if (ci)
4411-
offsetIntoMergedBuffer = (uint)ci->getZExtValue();
4412-
}
4413-
}
4414-
4415-
llvm::ConstantInt* ci = dyn_cast<llvm::ConstantInt>(inst->getOperand(0));
4416-
return ci && (uint)ci->getZExtValue() == offset;
4417-
}
4418-
4419-
return false;
4420-
}
4421-
4422-
namespace {
4423-
4424-
class ClampICBOOBAccess : public FunctionPass
4425-
{
4426-
public:
4427-
static char ID;
4428-
ClampICBOOBAccess() : FunctionPass(ID)
4429-
{
4430-
initializeClampICBOOBAccessPass(*PassRegistry::getPassRegistry());
4431-
}
4432-
virtual llvm::StringRef getPassName() const { return "Clamp ICB OOB Access"; }
4433-
virtual bool runOnFunction(Function& F);
4434-
virtual void getAnalysisUsage(llvm::AnalysisUsage& AU) const
4435-
{
4436-
AU.setPreservesCFG();
4437-
AU.addRequired<CodeGenContextWrapper>();
4438-
}
4439-
};
4440-
4441-
} // namespace
4442-
4443-
char ClampICBOOBAccess::ID = 0;
4444-
FunctionPass* IGC::createClampICBOOBAccess() { return new ClampICBOOBAccess(); }
4445-
4446-
IGC_INITIALIZE_PASS_BEGIN(ClampICBOOBAccess, "ClampICBOOBAccess", "ClampICBOOBAccess", false, false)
4447-
IGC_INITIALIZE_PASS_END(ClampICBOOBAccess, "ClampICBOOBAccess", "ClampICBOOBAccess", false, false)
4448-
4449-
bool ClampICBOOBAccess::runOnFunction(Function& F)
4450-
{
4451-
CodeGenContext* ctx = getAnalysis<CodeGenContextWrapper>().getCodeGenContext();
4452-
ModuleMetaData* modMD = ctx->getModuleMetaData();
4453-
IRBuilder<> m_builder(F.getContext());
4454-
bool changed = false;
4455-
4456-
for (auto& BB : F)
4457-
{
4458-
for (auto BI = BB.begin(), BE = BB.end(); BI != BE;)
4459-
{
4460-
if (llvm::LoadInst* inst = llvm::dyn_cast<llvm::LoadInst>(&(*BI++)))
4461-
{
4462-
unsigned offsetIntoMergedBuffer = 0;
4463-
4464-
if (isICBOffseted(inst, modMD->pushInfo.inlineConstantBufferOffset, offsetIntoMergedBuffer))
4465-
{
4466-
Value* ptrVal = inst->getPointerOperand();
4467-
4468-
if (GetElementPtrInst* gep = dyn_cast<GetElementPtrInst>(ptrVal))
4469-
{
4470-
if (gep->getNumOperands() != 3)
4471-
{
4472-
continue;
4473-
}
4474-
4475-
Type* eleType = gep->getPointerOperandType()->getPointerElementType();
4476-
if (!eleType->isArrayTy() ||
4477-
!(eleType->getArrayElementType()->isFloatTy() || eleType->getArrayElementType()->isIntegerTy(32)))
4478-
{
4479-
continue;
4480-
}
4481-
4482-
// Want to compare index into ICB to ensure index doesn't go past the size of the ICB
4483-
// If it does clamp to some index where a zero is stored
4484-
m_builder.SetInsertPoint(gep);
4485-
uint64_t arrSize = gep->getPointerOperandType()->getPointerElementType()->getArrayNumElements();
4486-
Value* eltIdx = gep->getOperand(2);
4487-
Value* isOOB = m_builder.CreateICmp(ICmpInst::ICMP_UGE, eltIdx, llvm::ConstantInt::get(eltIdx->getType(), arrSize));
4488-
unsigned zeroIndex = modMD->immConstant.zeroIdxs[offsetIntoMergedBuffer];
4489-
Value* eltIdxClampped = m_builder.CreateSelect(isOOB, llvm::ConstantInt::get(eltIdx->getType(), zeroIndex), eltIdx);
4490-
4491-
gep->replaceUsesOfWith(eltIdx, eltIdxClampped);
4492-
4493-
changed = true;
4494-
}
4495-
}
4496-
}
4497-
}
4498-
}
4499-
4500-
return changed;
4501-
}
4502-
45034385
namespace {
45044386

45054387
class IGCIndirectICBPropagaion : public FunctionPass
@@ -4517,6 +4399,8 @@ namespace {
45174399
AU.setPreservesCFG();
45184400
AU.addRequired<CodeGenContextWrapper>();
45194401
}
4402+
private:
4403+
bool isICBOffseted(llvm::LoadInst* inst, uint offset, uint& offsetIntoMergedBuffer);
45204404
};
45214405

45224406
} // namespace
@@ -4632,6 +4516,42 @@ bool IGCIndirectICBPropagaion::runOnFunction(Function& F)
46324516
return false;
46334517
}
46344518

4519+
bool IGCIndirectICBPropagaion::isICBOffseted(llvm::LoadInst* inst, uint offset, uint& offsetIntoMergedBuffer) {
4520+
Value* ptrVal = inst->getPointerOperand();
4521+
std::vector<Value*> srcInstList;
4522+
IGC::TracePointerSource(ptrVal, false, true, true, srcInstList);
4523+
if (srcInstList.size())
4524+
{
4525+
CallInst* inst = dyn_cast<CallInst>(srcInstList.back());
4526+
GenIntrinsicInst* genIntr = inst ? dyn_cast<GenIntrinsicInst>(inst) : nullptr;
4527+
if (!genIntr || (genIntr->getIntrinsicID() != GenISAIntrinsic::GenISA_RuntimeValue))
4528+
return false;
4529+
4530+
// ICB may contain multiple ICBs merged into one
4531+
// find getelementptr after GenISA_RuntimeValue to find offset to needed ICB in merged ICB
4532+
if (srcInstList.size() >= 2)
4533+
{
4534+
GetElementPtrInst* gep = dyn_cast<GetElementPtrInst>(srcInstList[srcInstList.size() - 2]);
4535+
4536+
if (gep &&
4537+
gep->getNumOperands() == 2 &&
4538+
gep->getOperand(0) == genIntr &&
4539+
genIntr->getType() == PointerType::get(Type::getInt8Ty(inst->getContext()), ADDRESS_SPACE_CONSTANT))
4540+
{
4541+
llvm::ConstantInt* ci = dyn_cast<llvm::ConstantInt>(gep->getOperand(1));
4542+
4543+
if (ci)
4544+
offsetIntoMergedBuffer = (uint)ci->getZExtValue();
4545+
}
4546+
}
4547+
4548+
llvm::ConstantInt* ci = dyn_cast<llvm::ConstantInt>(inst->getOperand(0));
4549+
return ci && (uint)ci->getZExtValue() == offset;
4550+
}
4551+
4552+
return false;
4553+
}
4554+
46354555
IGC_INITIALIZE_PASS_BEGIN(IGCIndirectICBPropagaion, "IGCIndirectICBPropagaion",
46364556
"IGCIndirectICBPropagaion", false, false)
46374557
IGC_INITIALIZE_PASS_END(IGCIndirectICBPropagaion, "IGCIndirectICBPropagaion",

IGC/Compiler/CustomSafeOptPass.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ namespace IGC
248248
llvm::FunctionPass* createNanHandlingPass();
249249
llvm::FunctionPass* createFlattenSmallSwitchPass();
250250
llvm::FunctionPass* createSplitIndirectEEtoSelPass();
251-
llvm::FunctionPass* createClampICBOOBAccess();
252251
llvm::FunctionPass* createIGCIndirectICBPropagaionPass();
253252
llvm::FunctionPass* createBlendToDiscardPass();
254253
llvm::FunctionPass* createMarkReadOnlyLoadPass();

IGC/Compiler/InitializePasses.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ void initializeGenIRLoweringPass(llvm::PassRegistry&);
5858
void initializeGEPLoweringPass(llvm::PassRegistry&);
5959
void initializeGenSpecificPatternPass(llvm::PassRegistry&);
6060
void initializeGreedyLiveRangeReductionPass(llvm::PassRegistry&);
61-
void initializeClampICBOOBAccessPass(llvm::PassRegistry&);
6261
void initializeIGCIndirectICBPropagaionPass(llvm::PassRegistry&);
6362
void initializeGenUpdateCBPass(llvm::PassRegistry&);
6463
void initializeGenStrengthReductionPass(llvm::PassRegistry&);

IGC/common/MDFrameWork.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,6 @@ namespace IGC
585585
{
586586
std::vector<char> data;
587587
std::map<unsigned, unsigned> sizes;
588-
std::map<unsigned, unsigned> zeroIdxs;
589588
};
590589

591590
struct PointerProgramBinaryInfo

0 commit comments

Comments
 (0)