diff --git a/llvm/include/llvm/CodeGen/TargetInstrInfo.h b/llvm/include/llvm/CodeGen/TargetInstrInfo.h --- a/llvm/include/llvm/CodeGen/TargetInstrInfo.h +++ b/llvm/include/llvm/CodeGen/TargetInstrInfo.h @@ -1022,6 +1022,11 @@ /// even if it has glue. virtual bool canCopyGluedNodeDuringSchedule(SDNode *N) const { return false; } + /// Return true if speculative execution of target instructions is forbidden. + /// This prevents MIR code from SimplePRE optimization leading to possible + /// speculative execution of instructions. + virtual bool shouldDoPartialRedundancyElimination() const { return false; } + protected: /// Target-dependent implementation for foldMemoryOperand. /// Target-independent code in foldMemoryOperand will diff --git a/llvm/lib/CodeGen/MachineCSE.cpp b/llvm/lib/CodeGen/MachineCSE.cpp --- a/llvm/lib/CodeGen/MachineCSE.cpp +++ b/llvm/lib/CodeGen/MachineCSE.cpp @@ -887,8 +887,10 @@ DT = &getAnalysis(); MBFI = &getAnalysis(); LookAheadLimit = TII->getMachineCSELookAheadLimit(); - bool ChangedPRE, ChangedCSE; - ChangedPRE = PerformSimplePRE(DT); + bool ChangedPRE = false, ChangedCSE; + if (!TII->shouldDoPartialRedundancyElimination()) { + ChangedPRE = PerformSimplePRE(DT); + } ChangedCSE = PerformCSE(DT->getRootNode()); return ChangedPRE || ChangedCSE; }