LoopBlocksRPO Worklist(CurLoop);
Worklist.perform(LI);
bool Changed = false;
+ BasicBlock *Preheader = CurLoop->getLoopPreheader();
for (BasicBlock *BB : Worklist) {
// Only need to process the contents of this block if it is not part of a
// subloop (which would already have been processed).
canSinkOrHoistInst(I, AA, DT, CurLoop, MSSAU, true, Flags, ORE) &&
isSafeToExecuteUnconditionally(
I, DT, TLI, CurLoop, SafetyInfo, ORE,
- CurLoop->getLoopPreheader()->getTerminator(), AC,
- AllowSpeculation)) {
+ Preheader->getTerminator(), AC, AllowSpeculation)) {
hoist(I, DT, CurLoop, CFH.getOrCreateHoistedBlock(BB), SafetyInfo,
MSSAU, SE, ORE);
HoistedInstructions.push_back(&I);
static bool hoistMinMax(Instruction &I, Loop &L, ICFLoopSafetyInfo &SafetyInfo,
MemorySSAUpdater &MSSAU) {
bool Inverse = false;
- bool IsLogical = false;
using namespace PatternMatch;
Value *Cond1, *Cond2;
- if (match(&I, m_Or(m_Value(Cond1), m_Value(Cond2))))
- Inverse = true;
- else if (match(&I, m_LogicalOr(m_Value(Cond1), m_Value(Cond2)))) {
+ if (match(&I, m_LogicalOr(m_Value(Cond1), m_Value(Cond2)))) {
Inverse = true;
- IsLogical = true;
- } else if (match(&I, m_And(m_Value(Cond1), m_Value(Cond2)))) {
+ } else if (match(&I, m_LogicalAnd(m_Value(Cond1), m_Value(Cond2)))) {
// Do nothing
- } else if (match(&I, m_LogicalAnd(m_Value(Cond1), m_Value(Cond2))))
- IsLogical = true;
- else
+ } else
return false;
auto MatchICmpAgainstInvariant = [&](Value *C, ICmpInst::Predicate &P,
// before (if it was a non-taken input of logical and/or instruction). If it
// was poison, we need to freeze it. Note that no new use for LHS and RHS1 are
// introduced, so they don't need this.
- if (IsLogical)
+ if (isa<SelectInst>(I))
RHS2 = Builder.CreateFreeze(RHS2, RHS2->getName() + ".fr");
Value *NewRHS = Builder.CreateBinaryIntrinsic(
id, RHS1, RHS2, nullptr, StringRef("invariant.") +