Skip to content

Commit 700fa26

Browse files
igogo-x86tru
authored andcommitted
[CodeGen] Improve speed of ComplexDeinterleaving pass
Cache all results of running `identifyNode`, even those that do not identify potential complex operations. This patch prevents ComplexDeinterleaving pass from repeatedly trying to identify Nodes for the same pair of instructions. Fixes llvm#64379 Differential Revision: https://reviews.llvm.org/D156916 (cherry picked from commit 46b2ad0)
1 parent f8468c3 commit 700fa26

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

llvm/lib/CodeGen/ComplexDeinterleavingPass.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ class ComplexDeinterleavingGraph {
226226
const TargetLowering *TL = nullptr;
227227
const TargetLibraryInfo *TLI = nullptr;
228228
SmallVector<NodePtr> CompositeNodes;
229+
DenseMap<std::pair<Value *, Value *>, NodePtr> CachedResult;
229230

230231
SmallPtrSet<Instruction *, 16> FinalInstructions;
231232

@@ -292,17 +293,11 @@ class ComplexDeinterleavingGraph {
292293

293294
NodePtr submitCompositeNode(NodePtr Node) {
294295
CompositeNodes.push_back(Node);
296+
if (Node->Real && Node->Imag)
297+
CachedResult[{Node->Real, Node->Imag}] = Node;
295298
return Node;
296299
}
297300

298-
NodePtr getContainingComposite(Value *R, Value *I) {
299-
for (const auto &CN : CompositeNodes) {
300-
if (CN->Real == R && CN->Imag == I)
301-
return CN;
302-
}
303-
return nullptr;
304-
}
305-
306301
/// Identifies a complex partial multiply pattern and its rotation, based on
307302
/// the following patterns
308303
///
@@ -900,9 +895,11 @@ ComplexDeinterleavingGraph::identifyNode(Value *R, Value *I) {
900895
LLVM_DEBUG(dbgs() << "identifyNode on " << *R << " / " << *I << "\n");
901896
assert(R->getType() == I->getType() &&
902897
"Real and imaginary parts should not have different types");
903-
if (NodePtr CN = getContainingComposite(R, I)) {
898+
899+
auto It = CachedResult.find({R, I});
900+
if (It != CachedResult.end()) {
904901
LLVM_DEBUG(dbgs() << " - Folding to existing node\n");
905-
return CN;
902+
return It->second;
906903
}
907904

908905
if (NodePtr CN = identifySplat(R, I))
@@ -949,6 +946,7 @@ ComplexDeinterleavingGraph::identifyNode(Value *R, Value *I) {
949946
return CN;
950947

951948
LLVM_DEBUG(dbgs() << " - Not recognised as a valid pattern.\n");
949+
CachedResult[{R, I}] = nullptr;
952950
return nullptr;
953951
}
954952

0 commit comments

Comments
 (0)