Home

Add Constant Hoisting Pass

Press ? to show keyboard shortcuts.
Committed
ributzkaJan 24 2014, 10:23 AM
Parents
rL200021: Add final and owerride keywords to TargetTransformInfo's subclasses.
Branches
Unknown
Tags
Unknown
Subscribers
None
Projects
None
Description

Add Constant Hoisting Pass

This pass identifies expensive constants to hoist and coalesces them to
better prepare it for SelectionDAG-based code generation. This works around the
limitations of the basic-block-at-a-time approach.

First it scans all instructions for integer constants and calculates its
cost. If the constant can be folded into the instruction (the cost is
TCC_Free) or the cost is just a simple operation (TCC_BASIC), then we don't
consider it expensive and leave it alone. This is the default behavior and
the default implementation of getIntImmCost will always return TCC_Free.

If the cost is more than TCC_BASIC, then the integer constant can't be folded
into the instruction and it might be beneficial to hoist the constant.
Similar constants are coalesced to reduce register pressure and
materialization code.

When a constant is hoisted, it is also hidden behind a bitcast to force it to
be live-out of the basic block. Otherwise the constant would be just
duplicated and each basic block would have its own copy in the SelectionDAG.
The SelectionDAG recognizes such constants as opaque and doesn't perform
certain transformations on them, which would create a new expensive constant.

This optimization is only applied to integer constants in instructions and
simple (this means not nested) constant cast experessions. For example:
%0 = load i64* inttoptr (i64 big_constant to i64*)

Reviewed by Eric

rL200022

llvm/trunk/include/llvm/Analysis/TargetTransformInfo.h

Loading...

llvm/trunk/include/llvm/CodeGen/SelectionDAG.h

Loading...

llvm/trunk/include/llvm/CodeGen/SelectionDAGNodes.h

Loading...

llvm/trunk/include/llvm/InitializePasses.h

Loading...

llvm/trunk/include/llvm/LinkAllPasses.h

Loading...

llvm/trunk/include/llvm/Transforms/Scalar.h

Loading...

llvm/trunk/lib/Analysis/TargetTransformInfo.cpp

Loading...

llvm/trunk/lib/CodeGen/Passes.cpp

Loading...

llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Loading...

llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Loading...

llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Loading...

llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp

Loading...

llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Loading...

llvm/trunk/lib/Target/X86/X86TargetTransformInfo.cpp

Loading...

llvm/trunk/lib/Transforms/Scalar/CMakeLists.txt

Loading...

llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp

Loading...

llvm/trunk/lib/Transforms/Scalar/ConstantHoisting.cpp

Loading...

llvm/trunk/lib/Transforms/Scalar/Scalar.cpp

Loading...

llvm/trunk/test/CodeGen/ARM/memcpy-inline.ll

Loading...

llvm/trunk/test/CodeGen/X86/large-constants.ll

Loading...

Add Comment