diff --git a/llvm/include/llvm/CodeGen/GlobalISel/CSEInfo.h b/llvm/include/llvm/CodeGen/GlobalISel/CSEInfo.h index 87dae64c5f902..09d6192a2bd5c 100644 --- a/llvm/include/llvm/CodeGen/GlobalISel/CSEInfo.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/CSEInfo.h @@ -111,6 +111,8 @@ class GISelCSEInfo : public GISelChangeObserver { /// into the CSEMap. MI should return true for shouldCSE(MI->getOpcode()) void insertInstr(MachineInstr *MI, void *InsertPos = nullptr); + bool HandlingRecordedInstrs = false; + public: GISelCSEInfo() = default; diff --git a/llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp b/llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp index 356d208fc881d..6d8f5d55ad8ad 100644 --- a/llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp @@ -217,10 +217,14 @@ void GISelCSEInfo::handleRemoveInst(MachineInstr *MI) { } void GISelCSEInfo::handleRecordedInsts() { + if (HandlingRecordedInstrs) + return; + HandlingRecordedInstrs = true; while (!TemporaryInsts.empty()) { auto *MI = TemporaryInsts.pop_back_val(); handleRecordedInst(MI); } + HandlingRecordedInstrs = false; } bool GISelCSEInfo::shouldCSE(unsigned Opc) const {