Skip to content

Commit b81fb09

Browse files
try to repair the unexpected code pattern in Duplicate Tracker
1 parent 05061fb commit b81fb09

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

llvm/lib/Target/SPIRV/SPIRVDuplicatesTracker.cpp

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,31 @@ void SPIRVGeneralDuplicatesTracker::buildDepsGraph(
6969
MachineOperand *RegOp = &VRegDef->getOperand(0);
7070
if (Reg2Entry.count(RegOp) == 0 &&
7171
(MI->getOpcode() != SPIRV::OpVariable || i != 3)) {
72-
std::string DiagMsg;
73-
raw_string_ostream OS(DiagMsg);
74-
OS << "Unexpected pattern while building a dependency "
75-
"graph.\nInstruction: ";
76-
MI->print(OS);
77-
OS << "Operand: ";
78-
Op.print(OS);
79-
OS << "\nOperand definition: ";
80-
VRegDef->print(OS);
81-
report_fatal_error(DiagMsg.c_str());
72+
// try to repair the unexpected code pattern
73+
bool IsFixed = false;
74+
if (VRegDef->getOpcode() == TargetOpcode::G_CONSTANT &&
75+
RegOp->isReg() && MRI.getType(RegOp->getReg()).isScalar()) {
76+
const Constant *C = VRegDef->getOperand(1).getCImm();
77+
add(C, MI->getParent()->getParent(), RegOp->getReg());
78+
auto Iter = CT.Storage.find(C);
79+
if (Iter != CT.Storage.end()) {
80+
SPIRV::DTSortableEntry &MissedEntry = Iter->second;
81+
Reg2Entry[RegOp] = &MissedEntry;
82+
IsFixed = true;
83+
}
84+
}
85+
if (!IsFixed) {
86+
std::string DiagMsg;
87+
raw_string_ostream OS(DiagMsg);
88+
OS << "Unexpected pattern while building a dependency "
89+
"graph.\nInstruction: ";
90+
MI->print(OS);
91+
OS << "Operand: ";
92+
Op.print(OS);
93+
OS << "\nOperand definition: ";
94+
VRegDef->print(OS);
95+
report_fatal_error(DiagMsg.c_str());
96+
}
8297
}
8398
if (Reg2Entry.count(RegOp))
8499
E->addDep(Reg2Entry[RegOp]);

0 commit comments

Comments
 (0)