1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[LICM] hoisting/sinking legality - bail early for unsupported instructions

Originally, this was part of a larger refactoring I'd planned, but had to abandoned.  I figured the minor improvement in readability was worthwhile.

llvm-svn: 338663
This commit is contained in:
Philip Reames 2018-08-02 00:54:14 +00:00
parent 4b8c550e74
commit 68eaba6f0a

View File

@ -575,10 +575,29 @@ static bool isLoadInvariantInLoop(LoadInst *LI, DominatorTree *DT,
return false; return false;
} }
namespace {
/// Return true if-and-only-if we know how to (mechanically) both hoist and
/// sink a given instruction out of a loop. Does not address legality
/// concerns such as aliasing or speculation safety.
bool isHoistableAndSinkableInst(Instruction &I) {
// Only these instructions are hoistable/sinkable.
return (isa<LoadInst>(I) || isa<CallInst>(I) ||
isa<BinaryOperator>(I) || isa<CastInst>(I) ||
isa<SelectInst>(I) || isa<GetElementPtrInst>(I) ||
isa<CmpInst>(I) || isa<InsertElementInst>(I) ||
isa<ExtractElementInst>(I) || isa<ShuffleVectorInst>(I) ||
isa<ExtractValueInst>(I) || isa<InsertValueInst>(I));
}
}
bool llvm::canSinkOrHoistInst(Instruction &I, AAResults *AA, DominatorTree *DT, bool llvm::canSinkOrHoistInst(Instruction &I, AAResults *AA, DominatorTree *DT,
Loop *CurLoop, AliasSetTracker *CurAST, Loop *CurLoop, AliasSetTracker *CurAST,
LoopSafetyInfo *SafetyInfo, LoopSafetyInfo *SafetyInfo,
OptimizationRemarkEmitter *ORE) { OptimizationRemarkEmitter *ORE) {
// If we don't understand the instruction, bail early.
if (!isHoistableAndSinkableInst(I))
return false;
// SafetyInfo is nullptr if we are checking for sinking from preheader to // SafetyInfo is nullptr if we are checking for sinking from preheader to
// loop body. // loop body.
const bool SinkingToLoopBody = !SafetyInfo; const bool SinkingToLoopBody = !SafetyInfo;
@ -666,14 +685,6 @@ bool llvm::canSinkOrHoistInst(Instruction &I, AAResults *AA, DominatorTree *DT,
return false; return false;
} }
// Only these instructions are hoistable/sinkable.
if (!isa<BinaryOperator>(I) && !isa<CastInst>(I) && !isa<SelectInst>(I) &&
!isa<GetElementPtrInst>(I) && !isa<CmpInst>(I) &&
!isa<InsertElementInst>(I) && !isa<ExtractElementInst>(I) &&
!isa<ShuffleVectorInst>(I) && !isa<ExtractValueInst>(I) &&
!isa<InsertValueInst>(I))
return false;
// If we are checking for sinking from preheader to loop body it will be // If we are checking for sinking from preheader to loop body it will be
// always safe as there is no speculative execution. // always safe as there is no speculative execution.
if (SinkingToLoopBody) if (SinkingToLoopBody)