LLVM
8.0.1
|
This pass handles simple speculating of instructions around PHIs when doing so is profitable for a particular target despite duplicated instructions. More...
#include "llvm/Transforms/Scalar/SpeculateAroundPHIs.h"
Public Member Functions | |
PreservedAnalyses | run (Function &F, FunctionAnalysisManager &AM) |
Run the pass over the function. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from llvm::PassInfoMixin< SpeculateAroundPHIsPass > | |
static StringRef | name () |
Gets the name of the pass we are mixed into. More... | |
This pass handles simple speculating of instructions around PHIs when doing so is profitable for a particular target despite duplicated instructions.
The motivating example are PHIs of constants which will require materializing the constants along each edge. If the PHI is used by an instruction where the target can materialize the constant as part of the instruction, it is profitable to speculate those instructions around the PHI node. This can reduce dynamic instruction count as well as decrease register pressure.
Consider this IR for example:
To materialize the inputs to this PHI node may require an explicit instruction. For example, on x86 this would turn into something like
When these constants can be folded directly into another instruction, it would be preferable to avoid the potential for register pressure (above we can easily avoid it, but that isn't always true) and simply duplicate the instruction using the PHI:
Which will generate something like the following on x86:
It is important to note that this pass is never intended to handle more complex cases where speculating around PHIs allows simplifications of the IR itself or other subsequent optimizations. Those can and should already be handled before this pass is ever run by a more powerful analysis that can reason about equivalences and common subexpressions. Classically, those cases would be handled by a GVN-powered PRE or similar transform. This pass, in contrast, is only interested in cases where despite no simplifications to the IR itself, speculation is faster to execute. The result of this is that the cost models which are appropriate to consider here are relatively simple ones around execution and codesize cost, without any need to consider simplifications or other transformations.
Definition at line 104 of file SpeculateAroundPHIs.h.
PreservedAnalyses SpeculateAroundPHIsPass::run | ( | Function & | F, |
FunctionAnalysisManager & | AM | ||
) |
Run the pass over the function.
Definition at line 795 of file SpeculateAroundPHIs.cpp.
References llvm::PreservedAnalyses::all(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::SmallVectorBase::empty(), F(), llvm::AnalysisManager< IRUnitT, ExtraArgTs >::getResult(), llvm::SmallVectorTemplateBase< T >::push_back(), and tryToSpeculatePHIs().