@@ -4382,124 +4382,6 @@ bool IGCConstProp::runOnFunction(Function& F)
4382
4382
return Changed;
4383
4383
}
4384
4384
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
-
4503
4385
namespace {
4504
4386
4505
4387
class IGCIndirectICBPropagaion : public FunctionPass
@@ -4517,6 +4399,8 @@ namespace {
4517
4399
AU.setPreservesCFG ();
4518
4400
AU.addRequired <CodeGenContextWrapper>();
4519
4401
}
4402
+ private:
4403
+ bool isICBOffseted (llvm::LoadInst* inst, uint offset, uint& offsetIntoMergedBuffer);
4520
4404
};
4521
4405
4522
4406
} // namespace
@@ -4632,6 +4516,42 @@ bool IGCIndirectICBPropagaion::runOnFunction(Function& F)
4632
4516
return false ;
4633
4517
}
4634
4518
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
+
4635
4555
IGC_INITIALIZE_PASS_BEGIN (IGCIndirectICBPropagaion, " IGCIndirectICBPropagaion" ,
4636
4556
" IGCIndirectICBPropagaion" , false , false )
4637
4557
IGC_INITIALIZE_PASS_END(IGCIndirectICBPropagaion, " IGCIndirectICBPropagaion" ,
0 commit comments