Skip to content

Commit

Permalink
Fixed generation of unnecessary phi-node in gvn pre for getelementptr…
Browse files Browse the repository at this point in the history
… (cherry-pick from upstream with stripPointerCasts added)
  • Loading branch information
azhogin authored and akiramenai committed Nov 18, 2020
1 parent 3a02f37 commit e48c04b
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions llvm/lib/Transforms/Scalar/GVN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2188,7 +2188,7 @@ bool GVN::performScalarPREInsertion(Instruction *Instr, BasicBlock *Pred,
}

bool GVN::performScalarPRE(Instruction *CurInst) {
if (isa<AllocaInst>(CurInst) || isa<TerminatorInst>(CurInst) ||
if (isa<AllocaInst>(CurInst) || CurInst->isTerminator() ||
isa<PHINode>(CurInst) || CurInst->getType()->isVoidTy() ||
CurInst->mayReadFromMemory() || CurInst->mayHaveSideEffects() ||
isa<DbgInfoIntrinsic>(CurInst))
Expand All @@ -2201,10 +2201,24 @@ bool GVN::performScalarPRE(Instruction *CurInst) {
if (isa<CmpInst>(CurInst))
return false;

// We don't currently value number ANY inline asm calls.
if (CallInst *CallI = dyn_cast<CallInst>(CurInst))
if (CallI->isInlineAsm())
// Don't do PRE on GEPs. The inserted PHI would prevent CodeGenPrepare from
// sinking the addressing mode computation back to its uses. Extending the
// GEP's live range increases the register pressure, and therefore it can
// introduce unnecessary spills.
//
// This doesn't prevent Load PRE. PHI translation will make the GEP available
// to the load by moving it to the predecessor block if necessary.
if (isa<GetElementPtrInst>(CurInst->stripPointerCasts()))
return false;

if (auto *CallB = dyn_cast<CallInst>(CurInst)) {
// We don't currently value number ANY inline asm calls.
if (CallB->isInlineAsm())
return false;
// Don't do PRE on convergent calls.
if (CallB->isConvergent())
return false;
}

uint32_t ValNo = VN.lookup(CurInst);

Expand Down

0 comments on commit e48c04b

Please sign in to comment.