@@ -2403,6 +2403,7 @@ namespace {
2403
2403
uint32_t getAlignment () const ;
2404
2404
AddressModel getAddressModel (CodeGenContext* Ctx) const ;
2405
2405
Value* getValueOperand () const ;
2406
+ bool isStore () const { return isa<StoreInst>(Inst); }
2406
2407
};
2407
2408
2408
2409
typedef SmallVector<LdStInfo, 8 > InstAndOffsetPairs;
@@ -2634,23 +2635,32 @@ namespace {
2634
2635
// If true, IGC needs to emulate I64.
2635
2636
bool m_hasI64Emu = false ;
2636
2637
2637
- // All insts that have been combined and will be deleted at the end.
2638
- SmallVector<Instruction*, 16 > m_combinedInsts;
2639
2638
//
2640
2639
// Temporary reused for each BB.
2641
2640
//
2642
2641
// Inst order within a BB.
2643
2642
DenseMap<const Instruction*, int > m_instOrder;
2643
+ // Per-BB: all insts that have been combined and will be deleted.
2644
+ DenseMap<const Instruction*, int > m_combinedInsts;
2645
+ // All root instructions (ie their uses are empty, including stores)
2646
+ // that are to be deleted at the end of each BB.
2647
+ SmallVector<Instruction*, 16 > m_toBeDeleted;
2648
+ void appendToBeDeleted (Instruction* I) {
2649
+ if (I != nullptr )
2650
+ m_toBeDeleted.push_back (I);
2651
+ }
2652
+ // Control the way that a load/store is handled.
2653
+ // [more for future improvement]
2654
+ DenseMap<const Instruction*, int > m_visited;
2644
2655
2645
2656
// a bundle : a group of loads or a group of store.
2646
2657
// Each bundle will be combined into a single load or single store.
2647
2658
std::list<BundleInfo> m_bundles;
2648
2659
2649
- DenseMap<const Instruction*, int > m_visited;
2650
-
2651
2660
void init (BasicBlock* BB) {
2652
2661
m_visited.clear ();
2653
2662
m_instOrder.clear ();
2663
+ m_combinedInsts.clear ();
2654
2664
}
2655
2665
void setInstOrder (BasicBlock* BB);
2656
2666
void setVisited (Instruction* I) { m_visited[I] = 1 ; }
@@ -3499,13 +3509,13 @@ void LdStCombine::createBundles(BasicBlock* BB, InstAndOffsetPairs& LoadStores)
3499
3509
return ;
3500
3510
}
3501
3511
3502
- auto isBundled = [](const LdStInfo* LSI, SmallVector< Instruction*, 16 >& L) {
3503
- return (std::find (L. begin (), L. end (), LSI->Inst ) != L. end () );
3512
+ auto isBundled = [](const LdStInfo* LSI, DenseMap< const Instruction*, int >& L) {
3513
+ return (L. count ( LSI->Inst ) > 0 );
3504
3514
};
3505
3515
auto setBundled = [&isBundled](LdStInfo* LSI,
3506
- SmallVector< Instruction*, 16 >& L) {
3516
+ DenseMap< const Instruction*, int >& L) {
3507
3517
if (!isBundled (LSI, L)) {
3508
- L. push_back ( LSI->Inst ) ;
3518
+ L[ LSI->Inst ] = 1 ;
3509
3519
}
3510
3520
};
3511
3521
@@ -3666,6 +3676,9 @@ void LdStCombine::createBundles(BasicBlock* BB, InstAndOffsetPairs& LoadStores)
3666
3676
LdStInfo& tlsi = LoadStores[k];
3667
3677
newBundle.LoadStores .push_back (tlsi);
3668
3678
setBundled (&tlsi, m_combinedInsts);
3679
+ if (tlsi.isStore ()) {
3680
+ appendToBeDeleted (tlsi.Inst );
3681
+ }
3669
3682
setVisited (tlsi.Inst );
3670
3683
}
3671
3684
i = e + 1 ;
@@ -4531,14 +4544,7 @@ void LdStCombine::scatterCopy(
4531
4544
Type* aTy = nV->getType ();
4532
4545
Value* newV = getValueFromStruct (aTy);
4533
4546
nV->replaceAllUsesWith (newV);
4534
-
4535
- // V (all Vals) will be deleted at the end. Here, only delete
4536
- // its uses so that V will have empty use later.
4537
- if (Instruction* tI = dyn_cast<Instruction>(nV)) {
4538
- if (tI != V) {
4539
- tI->eraseFromParent ();
4540
- }
4541
- }
4547
+ appendToBeDeleted (dyn_cast<Instruction>(nV));
4542
4548
}
4543
4549
}
4544
4550
} else {
@@ -4595,14 +4601,7 @@ void LdStCombine::scatterCopy(
4595
4601
}
4596
4602
Value* newV = createValueFromElements (vecElts, aTy);
4597
4603
nV->replaceAllUsesWith (newV);
4598
-
4599
- // V (all Vals) will be deleted at the end.
4600
- // Here, just delete its uses so that V will have empty use.
4601
- if (Instruction* tI = dyn_cast<Instruction>(nV)) {
4602
- if (tI != V) {
4603
- tI->eraseFromParent ();
4604
- }
4605
- }
4604
+ appendToBeDeleted (dyn_cast<Instruction>(nV));
4606
4605
}
4607
4606
}
4608
4607
}
@@ -4868,8 +4867,8 @@ void LdStCombine::createCombinedLoads(Function& F)
4868
4867
4869
4868
void LdStCombine::eraseDeadInsts ()
4870
4869
{
4871
- RecursivelyDeleteDeadInstructions (m_combinedInsts );
4872
- m_combinedInsts .clear ();
4870
+ RecursivelyDeleteDeadInstructions (m_toBeDeleted );
4871
+ m_toBeDeleted .clear ();
4873
4872
}
4874
4873
4875
4874
void BundleInfo::print (raw_ostream& O, int BundleID) const
0 commit comments