[llvm] r338663 - [LICM] hoisting/sinking legality - bail early for unsupported instructions
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 1 17:54:14 PDT 2018
Author: reames
Date: Wed Aug 1 17:54:14 2018
New Revision: 338663
URL: http://llvm.org/viewvc/llvm-project?rev=338663&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/Transforms/Scalar/LICM.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/LICM.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LICM.cpp?rev=338663&r1=338662&r2=338663&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LICM.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LICM.cpp Wed Aug 1 17:54:14 2018
@@ -575,10 +575,29 @@ static bool isLoadInvariantInLoop(LoadIn
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(Instructio
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)
More information about the llvm-commits
mailing list