@@ -191,19 +191,19 @@ bool SPIRVInstrInfo::analyzeBranch(MachineBasicBlock &MBB,
191191 auto MI = MBB.getLastNonDebugInstr ();
192192 if (!MI.isValid ())
193193 return false ;
194- if (MI->getOpcode () == SPIRV::OpBranch) {
195- TBB = MI->getOperand (0 ).getMBB ();
196- return false ;
197- } else if (MI->getOpcode () == SPIRV::OpBranchConditional) {
198- Cond.push_back (MI->getOperand (0 ));
199- TBB = MI->getOperand (1 ).getMBB ();
200- FBB = MI->getOperand (2 ).getMBB ();
201- for (unsigned I = 3 , E = MI->getNumOperands (); I < E; ++I)
202- Cond.push_back (MI->getOperand (I));
203- return false ;
204- } else {
194+
195+ // We do not allow to restructure blocks ending with OpBranchConditional,
196+ // because there is no way to encode `if (Cond) then Stmt` logic, only
197+ // full if-then-else is supported by OpBranchConditional.
198+ // If we supported splitting of blocks ending with OpBranchConditional
199+ // MachineBasicBlock.cpp would expect successfull implementation of calls
200+ // to insertBranch() setting FBB to null that is not feasible.
201+ if (MI->getOpcode () != SPIRV::OpBranch)
205202 return true ;
206- }
203+
204+ // Allow only 'unconditional branch' modifications of the basic block.
205+ TBB = MI->getOperand (0 ).getMBB ();
206+ return false ;
207207}
208208
209209// Remove the branching code at the end of the specific MBB.
@@ -217,8 +217,7 @@ unsigned SPIRVInstrInfo::removeBranch(MachineBasicBlock &MBB,
217217 if (I == MBB.end ())
218218 return 0 ;
219219
220- unsigned Opcode = I->getOpcode ();
221- if (Opcode == SPIRV::OpBranch || Opcode == SPIRV::OpBranchConditional) {
220+ if (I->getOpcode () == SPIRV::OpBranch) {
222221 I->eraseFromParent ();
223222 return 1 ;
224223 }
@@ -246,16 +245,7 @@ unsigned SPIRVInstrInfo::insertBranch(MachineBasicBlock &MBB,
246245 int * /* BytesAdded*/ ) const {
247246 if (!TBB)
248247 return 0 ;
249- if (Cond.empty ()) {
250- BuildMI (&MBB, DL, get (SPIRV::OpBranch)).addMBB (TBB);
251- } else {
252- auto MIB = BuildMI (&MBB, DL, get (SPIRV::OpBranchConditional))
253- .add (Cond[0 ])
254- .addMBB (TBB)
255- .addMBB (FBB);
256- for (unsigned i = 1 ; i < Cond.size (); ++i)
257- MIB.add (Cond[i]);
258- }
248+ BuildMI (&MBB, DL, get (SPIRV::OpBranch)).addMBB (TBB);
259249 return 1 ;
260250}
261251
0 commit comments