@@ -10246,82 +10246,6 @@ MachineInstr *llvm::getVRegSubRegDef(const TargetInstrInfo::RegSubRegPair &P,
1024610246 return nullptr ;
1024710247}
1024810248
10249- // helper function to checkIfExecMayBeModifiedBeforeUseAcrossBB and
10250- // execMayBeModifiedBeforeUse. This checks possible EXEC register modifications
10251- // for a straight-line sequence of instructions between BeginIterator and
10252- // EndIterator (both inclusive) upto a pre-defined limit MaxInstScan
10253- bool execMayBeModifiedBeforeUseUtil (
10254- const TargetRegisterInfo *TRI,
10255- const MachineInstrBundleIterator<const MachineInstr> BeginIterator,
10256- const MachineInstrBundleIterator<const MachineInstr> EndIterator,
10257- const int MaxInstScan) {
10258-
10259- int NumInst = 0 ;
10260- for (auto I = BeginIterator; I != EndIterator; ++I) {
10261- if (I->isMetaInstruction ())
10262- continue ;
10263-
10264- if (++NumInst > MaxInstScan)
10265- return true ;
10266-
10267- if (I->modifiesRegister (AMDGPU::EXEC, TRI))
10268- return true ;
10269- }
10270- return false ;
10271- }
10272-
10273- // Variant of execMayBeModifiedBeforeUse(), where DefMI and UseMI belong to
10274- // different basic blocks. Current code is limited to a very simple case: DefMI
10275- // in the predecessor BB of the single BB loop where UseMI resides.
10276- bool llvm::checkIfExecMayBeModifiedBeforeUseAcrossBB (
10277- const MachineRegisterInfo &MRI, Register VReg, const MachineInstr &DefMI,
10278- const MachineInstr &UseMI, const int SIFoldOperandsPreheaderThreshold) {
10279-
10280- assert (MRI.isSSA () && " Must be run on SSA" );
10281- auto *TRI = MRI.getTargetRegisterInfo ();
10282- auto *DefBB = DefMI.getParent ();
10283- const int MaxInstScan = (SIFoldOperandsPreheaderThreshold > 10000 )
10284- ? 10000
10285- : SIFoldOperandsPreheaderThreshold;
10286-
10287- // Check whether EXEC is modified along all possible control flow between
10288- // DefMI and UseMI, which may include loop backedge
10289- // 1. UseBB is the only successor of DefBB
10290- // 2. UseBB is a single basic block loop (only two predecessor blocks: DefBB
10291- // and UseBB)
10292- // 3. check if EXEC is modified
10293- auto *UseBB = UseMI.getParent ();
10294- if (UseBB != DefBB) {
10295- if (!(DefBB->isSuccessor (UseBB) && (DefBB->succ_size () == 1 )))
10296- return true ;
10297-
10298- if (!((UseBB->pred_size () == 2 ) && UseBB->isPredecessor (UseBB) &&
10299- UseBB->isPredecessor (DefBB)))
10300- return true ;
10301-
10302- bool canExecBeModifiedBeforeUse = execMayBeModifiedBeforeUseUtil (
10303- TRI, UseBB->begin (), UseBB->end (), MaxInstScan);
10304- if (canExecBeModifiedBeforeUse)
10305- return true ;
10306-
10307- // Stop scan at the end of the DEF basic block.
10308- // If we are here, we know for sure that the instructions in focus are in
10309- // the same basic block. Scan them to be safe.
10310- canExecBeModifiedBeforeUse = execMayBeModifiedBeforeUseUtil (
10311- TRI, std::next (DefMI.getIterator ()), DefBB->end (), MaxInstScan);
10312- if (canExecBeModifiedBeforeUse)
10313- return true ;
10314-
10315- } else {
10316- // Stop scan at the use.
10317- bool canExecBeModifiedBeforeUse = execMayBeModifiedBeforeUseUtil (
10318- TRI, std::next (DefMI.getIterator ()), UseMI.getIterator (), MaxInstScan);
10319- if (canExecBeModifiedBeforeUse)
10320- return true ;
10321- }
10322- return false ;
10323- }
10324-
1032510249bool llvm::execMayBeModifiedBeforeUse (const MachineRegisterInfo &MRI,
1032610250 Register VReg,
1032710251 const MachineInstr &DefMI,
@@ -10337,12 +10261,20 @@ bool llvm::execMayBeModifiedBeforeUse(const MachineRegisterInfo &MRI,
1033710261 return true ;
1033810262
1033910263 const int MaxInstScan = 20 ;
10264+ int NumInst = 0 ;
1034010265
1034110266 // Stop scan at the use.
10342- bool canExecBeModifiedBeforeUse = execMayBeModifiedBeforeUseUtil (
10343- TRI, std::next (DefMI.getIterator ()), UseMI.getIterator (), MaxInstScan);
10344- if (canExecBeModifiedBeforeUse)
10345- return true ;
10267+ auto E = UseMI.getIterator ();
10268+ for (auto I = std::next (DefMI.getIterator ()); I != E; ++I) {
10269+ if (I->isDebugInstr ())
10270+ continue ;
10271+
10272+ if (++NumInst > MaxInstScan)
10273+ return true ;
10274+
10275+ if (I->modifiesRegister (AMDGPU::EXEC, TRI))
10276+ return true ;
10277+ }
1034610278
1034710279 return false ;
1034810280}
@@ -10379,7 +10311,7 @@ bool llvm::execMayBeModifiedBeforeAnyUse(const MachineRegisterInfo &MRI,
1037910311 for (auto I = std::next (DefMI.getIterator ()); ; ++I) {
1038010312 assert (I != DefBB->end ());
1038110313
10382- if (I->isMetaInstruction ())
10314+ if (I->isDebugInstr ())
1038310315 continue ;
1038410316
1038510317 if (++NumInst > MaxInstScan)
0 commit comments