@@ -225,7 +225,7 @@ class SIWholeQuadMode : public MachineFunctionPass {
225
225
void lowerCopyInstrs ();
226
226
void lowerKillInstrs (bool IsWQM);
227
227
void lowerInitExec (MachineInstr &MI);
228
- void lowerInitExecInstrs ();
228
+ MachineBasicBlock::iterator lowerInitExecInstrs (MachineBasicBlock &Entry );
229
229
230
230
public:
231
231
static char ID;
@@ -1648,9 +1648,23 @@ void SIWholeQuadMode::lowerInitExec(MachineInstr &MI) {
1648
1648
LIS->createAndComputeVirtRegInterval (CountReg);
1649
1649
}
1650
1650
1651
- void SIWholeQuadMode::lowerInitExecInstrs () {
1652
- for (MachineInstr *MI : InitExecInstrs)
1651
+ // / Lower INIT_EXEC instructions. Return a suitable insert point in \p Entry
1652
+ // / for instructions that depend on EXEC.
1653
+ MachineBasicBlock::iterator
1654
+ SIWholeQuadMode::lowerInitExecInstrs (MachineBasicBlock &Entry) {
1655
+ MachineBasicBlock::iterator InsertPt = Entry.getFirstNonPHI ();
1656
+
1657
+ for (MachineInstr *MI : InitExecInstrs) {
1658
+ // Try to handle undefined cases gracefully:
1659
+ // - multiple INIT_EXEC instructions
1660
+ // - INIT_EXEC instructions not in the entry block
1661
+ if (MI->getParent () == &Entry)
1662
+ InsertPt = std::next (MI->getIterator ());
1663
+
1653
1664
lowerInitExec (*MI);
1665
+ }
1666
+
1667
+ return InsertPt;
1654
1668
}
1655
1669
1656
1670
bool SIWholeQuadMode::runOnMachineFunction (MachineFunction &MF) {
@@ -1701,19 +1715,16 @@ bool SIWholeQuadMode::runOnMachineFunction(MachineFunction &MF) {
1701
1715
1702
1716
LiveMaskReg = Exec;
1703
1717
1718
+ MachineBasicBlock &Entry = MF.front ();
1719
+ MachineBasicBlock::iterator EntryMI = lowerInitExecInstrs (Entry);
1720
+
1704
1721
// Shader is simple does not need any state changes or any complex lowering
1705
1722
if (!(GlobalFlags & (StateWQM | StateStrict)) && LowerToCopyInstrs.empty () &&
1706
1723
LowerToMovInstrs.empty () && KillInstrs.empty ()) {
1707
- lowerInitExecInstrs ();
1708
1724
lowerLiveMaskQueries ();
1709
1725
return !InitExecInstrs.empty () || !LiveMaskQueries.empty ();
1710
1726
}
1711
1727
1712
- lowerInitExecInstrs ();
1713
-
1714
- MachineBasicBlock &Entry = MF.front ();
1715
- MachineBasicBlock::iterator EntryMI = Entry.getFirstNonPHI ();
1716
-
1717
1728
// Store a copy of the original live mask when required
1718
1729
if (NeedsLiveMask || (GlobalFlags & StateWQM)) {
1719
1730
LiveMaskReg = MRI->createVirtualRegister (TRI->getBoolRC ());
0 commit comments