Index: lib/CodeGen/GlobalISel/Legalizer.cpp =================================================================== --- lib/CodeGen/GlobalISel/Legalizer.cpp +++ lib/CodeGen/GlobalISel/Legalizer.cpp @@ -142,6 +142,7 @@ // Populate Insts InstListTy InstList; + SmallVector RetryInstList; ArtifactListTy ArtifactList; ReversePostOrderTraversal RPOT(&MF); // Perform legalization bottom up so we can DCE as we legalize. @@ -195,6 +196,8 @@ }; bool Changed = false; do { + assert(RetryInstList.empty() && + "Retry instructions should have been pushed into InstList"); while (!InstList.empty()) { MachineInstr &MI = *InstList.pop_back_val(); assert(isPreISelGenericOpcode(MI.getOpcode()) && "Expecting generic opcode"); @@ -209,10 +212,14 @@ // Error out if we couldn't legalize this instruction. We may want to // fall back to DAG ISel instead in the future. if (Res == LegalizerHelper::UnableToLegalize) { - Helper.MIRBuilder.stopObservingChanges(); - reportGISelFailure(MF, TPC, MORE, "gisel-legalize", - "unable to legalize instruction", MI); - return false; + if (ArtifactList.empty()) { + Helper.MIRBuilder.stopObservingChanges(); + reportGISelFailure(MF, TPC, MORE, "gisel-legalize", + "unable to legalize instruction", MI); + return false; + } + LLVM_DEBUG(dbgs() << "Artifacts may prevent legalization to happen\n"); + RetryInstList.push_back(&MI); } Changed |= Res == LegalizerHelper::Legalized; } @@ -241,6 +248,9 @@ else InstList.insert(&MI); } + for (MachineInstr *MI : RetryInstList) + InstList.insert(MI); + RetryInstList.clear(); } while (!InstList.empty()); // For now don't support if new blocks are inserted - we would need to fix the