@@ -3337,6 +3337,36 @@ void Optimizer::expandIEEEExceptionTrap(INST_LIST_ITER it, G4_BB *bb) {
3337
3337
*it = restoreFlag;
3338
3338
}
3339
3339
3340
+ void Optimizer::insertNopAfterCFInst (BB_LIST_ITER ib, INST_LIST_ITER ii) {
3341
+ // If the CF inst is not the last inst of current BB, simply insert
3342
+ // a nop after it. Otherwise, insert a dummy BB to hold a nop between
3343
+ // the current BB and the fall-through BB.
3344
+ G4_BB *bb = *ib;
3345
+ G4_INST *inst = *ii;
3346
+ if (inst != bb->back ()) {
3347
+ bb->insertAfter (ii, builder.createNop (InstOpt_NoOpt));
3348
+ } else {
3349
+ G4_BB *dummyBB = fg.createNewBBWithLabel (" CFInstWA_BB" );
3350
+ dummyBB->push_back (builder.createNop (InstOpt_NoOpt));
3351
+ BB_LIST_ITER nextBI = std::next (ib);
3352
+ fg.insert (nextBI, dummyBB);
3353
+ // Update the pred/succ edges accordingly.
3354
+ bb->setPhysicalSucc (dummyBB);
3355
+ dummyBB->setPhysicalPred (bb);
3356
+ if (nextBI != fg.end ()) {
3357
+ G4_BB *nextBB = *nextBI;
3358
+ dummyBB->setPhysicalSucc (nextBB);
3359
+ nextBB->setPhysicalPred (dummyBB);
3360
+ if (std::any_of (bb->Succs .begin (), bb->Succs .end (),
3361
+ [=](G4_BB *succ) { return succ == nextBB; } )) {
3362
+ fg.removePredSuccEdges (bb, nextBB);
3363
+ fg.addPredSuccEdges (bb, dummyBB);
3364
+ fg.addPredSuccEdges (dummyBB, nextBB);
3365
+ }
3366
+ }
3367
+ }
3368
+ }
3369
+
3340
3370
// For a subroutine, insert a dummy move with {Switch} option immediately
3341
3371
// before the first non-label instruction in BB. Otherwie, for a following
3342
3372
// basic block, insert a dummy move before *any* instruction to ensure that
@@ -3767,6 +3797,14 @@ void Optimizer::HWWorkaround() {
3767
3797
if (inst->isIEEEExceptionTrap ())
3768
3798
expandIEEEExceptionTrap (ii, bb);
3769
3799
3800
+ // Currently skip adding Nop for the predicated backward goto as IP + 1
3801
+ // of the goto might need to be the join instruction.
3802
+ const bool isPredicatedBwdGoto = inst->opcode () == G4_goto &&
3803
+ inst->getPredicate () && inst->asCFInst ()->isBackward ();
3804
+ if (inst->isCFInst () && !isPredicatedBwdGoto &&
3805
+ builder.needNopAfterCFInstWA ())
3806
+ insertNopAfterCFInst (ib, ii);
3807
+
3770
3808
ii++;
3771
3809
}
3772
3810
}
0 commit comments