Skip to content

Commit dcdb867

Browse files
jgu222pszymich
authored andcommitted
Fixed assertion in call wa code.
call wa needs to keep certain BBs without deleting/merging, etc. visa optimization ifcvt merged them, therefore, causing assertion in the later phase of callwa. This submit does: 1. fixed assertion by setting BB type to G4_BB_KEEP_TYPE, so that ifcvt can avoid if-conversion for BBs involving this type. 2. call wa inserts join and set this join's jip to the next join instruction. Although this is correct functionally, it breaks if-conversion as if-conversion only checks control-flow and ignore any jump due to jip. Igorning jip caused SWSB assertion later. As the new join inserted by call wa will never jump, it is safe to set its JIP to null. Doing so will not break ifcvt. Thus, SWSB assertion will not happen.
1 parent 7ab102d commit dcdb867

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

visa/G4_BB.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,8 @@ std::string G4_BB::getBBTypeStr() const {
12961296
addTyString("FCALL");
12971297
if ((bbTy & G4_BB_NM_WA_TYPE) != 0)
12981298
addTyString("NoMaskWA");
1299+
if ((bbTy & G4_BB_KEEP_TYPE) != 0)
1300+
addTyString("KEEP");
12991301
return ss.str();
13001302
}
13011303

visa/G4_BB.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ enum G4_BB_TYPE {
3232
G4_BB_INIT_TYPE = 0x04,
3333
G4_BB_EXIT_TYPE = 0x08,
3434
G4_BB_NM_WA_TYPE = 0x10, // For NoMaskWA
35-
G4_BB_FCALL_TYPE = 0x20 // For NoMaskWA
35+
G4_BB_FCALL_TYPE = 0x20, // For NoMaskWA
36+
37+
// Keep BB without deleting. Its instructions stay and are not moved out.
38+
// Moving instructions into BB are okay.
39+
G4_BB_KEEP_TYPE = 0x40
3640
};
3741

3842
class FuncInfo;

visa/Optimizer.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12655,20 +12655,6 @@ void Optimizer::applyNoMaskWA() {
1265512655
// running the inst always.)
1265612656
//
1265712657
void Optimizer::applyFusedCallWA() {
12658-
auto getNextJoinLabel = [&](BB_LIST_ITER ITER) -> G4_Label * {
12659-
for (auto II = ITER, IE = fg.end(); II != IE; ++II) {
12660-
G4_BB *B = (*II);
12661-
if (G4_INST *Inst = B->getFirstInst()) {
12662-
if (Inst->opcode() == G4_join || Inst->opcode() == G4_endif ||
12663-
Inst->opcode() == G4_while) {
12664-
G4_INST *labelInst = B->front();
12665-
return labelInst->getLabel();
12666-
}
12667-
}
12668-
}
12669-
return nullptr;
12670-
};
12671-
1267212658
auto updateSubroutineTableIfNeeded = [&](G4_BB *aLeadBB, G4_BB *aB0,
1267312659
G4_BB *aB1, G4_BB *aS0, G4_BB *aS1,
1267412660
G4_BB *aEndB_or_null) {
@@ -12775,10 +12761,11 @@ void Optimizer::applyFusedCallWA() {
1277512761
bigB1->push_back(gotoEnd);
1277612762

1277712763
// Need to insert a join in nextBB
12764+
// This join will never jump, thus set its JIP to nullptr.
1277812765
G4_INST *tjoin = nextBB->getFirstInst();
1277912766
if (tjoin == nullptr || tjoin->opcode() != G4_join) {
1278012767
G4_INST *finalJoin = builder.createCFInst(nullptr, G4_join, simdsz,
12781-
getNextJoinLabel(nextBI),
12768+
nullptr,
1278212769
nullptr, InstOpt_NoOpt, false);
1278312770
if (tjoin == nullptr) {
1278412771
nextBB->insertBefore(nextBB->end(), finalJoin);
@@ -12943,6 +12930,12 @@ void Optimizer::applyFusedCallWA() {
1294312930
kernel.m_indirectCallWAInfo.emplace(
1294412931
BB, IndirectCallWAInfo(bigB0, smallB0, nullptr, nullptr, nullptr,
1294512932
nullptr, nullptr, callI, nCallI));
12933+
// BB, bigB0, smallB0 should not be deleted and its instructions shall
12934+
// stay inside. Set BB type to G4_BB_KEEP_TYPE so the other optim passes
12935+
// will not delete them.
12936+
BB->setBBType(G4_BB_KEEP_TYPE);
12937+
bigB0->setBBType(G4_BB_KEEP_TYPE);
12938+
smallB0->setBBType(G4_BB_KEEP_TYPE);
1294612939
} else {
1294712940
// relative target: need to patch offset after SWSB in
1294812941
// finishFusedCallWA()

visa/ifcvt.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,13 @@ void IfConverter::analyze(std::vector<IfConvertible> &list) {
451451
continue;
452452
}
453453

454+
// Conservatively skip if BB is set with G4_BB_KEEP_TYPE
455+
if ((t && (t->getBBType() & G4_BB_KEEP_TYPE)) ||
456+
(s0 && (s0->getBBType() & G4_BB_KEEP_TYPE)) ||
457+
(s1 && (s1->getBBType() & G4_BB_KEEP_TYPE))) {
458+
continue;
459+
}
460+
454461
G4_Predicate *pred = ifInst->getPredicate();
455462

456463
unsigned n0 = getPredictableInsts(s0, ifInst);

0 commit comments

Comments
 (0)