@@ -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.\n Instruction: " ;
76- MI->print (OS);
77- OS << " Operand: " ;
78- Op.print (OS);
79- OS << " \n Operand 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.\n Instruction: " ;
90+ MI->print (OS);
91+ OS << " Operand: " ;
92+ Op.print (OS);
93+ OS << " \n Operand 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