@@ -526,6 +526,7 @@ class TransposeHelperPromote : public TransposeHelper
526
526
StoreInst* pStore,
527
527
Value* pScalarizedIdx);
528
528
AllocaInst* pVecAlloca;
529
+ std::set<BasicBlock*> StoreBBs; // location of all stores
529
530
TransposeHelperPromote (AllocaInst* pAI) : TransposeHelper(false ) { pVecAlloca = pAI; }
530
531
};
531
532
@@ -551,7 +552,16 @@ void LowerGEPForPrivMem::handleAllocaInst(llvm::AllocaInst* pAlloca)
551
552
// to keep the promoted vector as uniform in the next round of WIAnalysis
552
553
bool isUniformAlloca = pAlloca->getMetadata (" uniform" ) != nullptr ;
553
554
if (isUniformAlloca && pAlloca->getAllocatedType ()->isArrayTy ()) {
554
- IRBuilder<> IRB1 (pAlloca);
555
+ BasicBlock* CommonDomBB = nullptr ;
556
+ for (auto * SB : helper.StoreBBs )
557
+ {
558
+ if (!CommonDomBB)
559
+ CommonDomBB = SB;
560
+ else
561
+ CommonDomBB = m_DT->findNearestCommonDominator (CommonDomBB, SB);
562
+ }
563
+ assert (CommonDomBB);
564
+ IRBuilder<> IRB1 (CommonDomBB->getFirstNonPHI ());
555
565
auto pVecF = GenISAIntrinsic::getDeclaration (m_pFunc->getParent (),
556
566
GenISAIntrinsic::GenISA_vectorUniform, pVecAlloca->getAllocatedType ());
557
567
auto pVecInit = IRB1.CreateCall (pVecF);
@@ -710,10 +720,11 @@ void TransposeHelperPromote::handleStoreInst(
710
720
llvm::StoreInst* pStore,
711
721
llvm::Value* pScalarizedIdx)
712
722
{
713
- // Add Store instruction to remove list
714
723
IGC_ASSERT (nullptr != pStore);
715
724
IGC_ASSERT (pStore->isSimple ());
716
-
725
+ // remember the location of the stores in order to
726
+ // compute the nearest dominator
727
+ StoreBBs.insert (pStore->getParent ());
717
728
IRBuilder<> IRB (pStore);
718
729
llvm::Value* pStoreVal = pStore->getValueOperand ();
719
730
llvm::Value* pLoadVecAlloca = IRB.CreateLoad (pVecAlloca);
0 commit comments