summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorFiona Glaser <escha@apple.com>2017-12-12 19:18:02 +0000
committerFiona Glaser <escha@apple.com>2017-12-12 19:18:02 +0000
commit1feb97a12bbc090ce0130f2f8fad4de4aa3f6c46 (patch)
tree35bfae04fa8c4f59e6c0b6d7b1cd59c174028312 /include
parent960dcea840cb497bc0ff4b5112dc181ecdef566d (diff)
Reassociate: add global reassociation algorithm
This algorithm (explained more in the source code) takes into account global redundancies by building a "pair map" to find common subexprs. The primary motivation of this is to handle situations like foo = (a * b) * c bar = (a * d) * c where we currently don't identify that "a * c" is redundant. Accordingly, it prioritizes the emission of a * c so that CSE can remove the redundant calculation later. Does not change the actual reassociation algorithm -- only the order in which the reassociated operand chain is reconstructed. Gives ~1.5% floating point math instruction count reduction on a large offline suite of graphics shaders. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320515 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/Transforms/Scalar/Reassociate.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/include/llvm/Transforms/Scalar/Reassociate.h b/include/llvm/Transforms/Scalar/Reassociate.h
index fa87673e3e4..9997dfa5b6f 100644
--- a/include/llvm/Transforms/Scalar/Reassociate.h
+++ b/include/llvm/Transforms/Scalar/Reassociate.h
@@ -72,6 +72,13 @@ class ReassociatePass : public PassInfoMixin<ReassociatePass> {
DenseMap<BasicBlock *, unsigned> RankMap;
DenseMap<AssertingVH<Value>, unsigned> ValueRankMap;
SetVector<AssertingVH<Instruction>> RedoInsts;
+
+ // Arbitrary, but prevents quadratic behavior.
+ static const unsigned GlobalReassociateLimit = 10;
+ static const unsigned NumBinaryOps =
+ Instruction::BinaryOpsEnd - Instruction::BinaryOpsBegin;
+ DenseMap<std::pair<Value *, Value *>, unsigned> PairMap[NumBinaryOps];
+
bool MadeChange;
public:
@@ -105,6 +112,7 @@ private:
SetVector<AssertingVH<Instruction>> &Insts);
void OptimizeInst(Instruction *I);
Instruction *canonicalizeNegConstExpr(Instruction *I);
+ void BuildPairMap(ReversePostOrderTraversal<Function *> &RPOT);
};
} // end namespace llvm