diff options
author | Philip Reames <listmail@philipreames.com> | 2018-08-02 00:54:14 +0000 |
---|---|---|
committer | Philip Reames <listmail@philipreames.com> | 2018-08-02 00:54:14 +0000 |
commit | 09de470e9e925ce06381632636a8b5a125c6a4e1 (patch) | |
tree | aa2ef62de3cab52a830db3b70982bcda31a7d45e | |
parent | 566afa0ab2ce3fc753ce7490f7c1394c3f4699c0 (diff) | |
download | bcm5719-llvm-09de470e9e925ce06381632636a8b5a125c6a4e1.tar.gz bcm5719-llvm-09de470e9e925ce06381632636a8b5a125c6a4e1.zip |
[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
-rw-r--r-- | llvm/lib/Transforms/Scalar/LICM.cpp | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp index c4ea43a4324..02e5839ff5b 100644 --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -575,10 +575,29 @@ static bool isLoadInvariantInLoop(LoadInst *LI, DominatorTree *DT, 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, Loop *CurLoop, AliasSetTracker *CurAST, LoopSafetyInfo *SafetyInfo, 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 // loop body. const bool SinkingToLoopBody = !SafetyInfo; @@ -666,14 +685,6 @@ bool llvm::canSinkOrHoistInst(Instruction &I, AAResults *AA, DominatorTree *DT, 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 // always safe as there is no speculative execution. if (SinkingToLoopBody) |