[llvm] Deduplication of cyclic PHI nodes (PR #86662)
Marek Sedláček via llvm-commits
llvm-commits at lists.llvm.org
Fri May 17 01:18:11 PDT 2024
https://github.com/mark-sed updated https://github.com/llvm/llvm-project/pull/86662
>From 167f6301e6477af8a0c0db1ecd5bd3e655949f00 Mon Sep 17 00:00:00 2001
From: Marek Sedlacek <msedlacek at azul.com>
Date: Mon, 11 Mar 2024 13:46:41 +0100
Subject: [PATCH 1/4] Added cyclic phis deduplication
---
llvm/lib/Transforms/Utils/Local.cpp | 78 ++++++++++++++-----
llvm/unittests/Transforms/Utils/LocalTest.cpp | 72 +++++++++++++++++
2 files changed, 132 insertions(+), 18 deletions(-)
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index c4a8843f2840b..bd3ae5b39da71 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -111,6 +111,9 @@ static cl::opt<unsigned> PHICSENumPHISmallSize(
"When the basic block contains not more than this number of PHI nodes, "
"perform a (faster!) exhaustive search instead of set-driven one."));
+static cl::opt<unsigned> DeduplicatePhisMaxDepth("deduplicate-phi-max-depth",
+ cl::Hidden, cl::init(8));
+
// Max recursion depth for collectBitParts used when detecting bswap and
// bitreverse idioms.
static const unsigned BitPartRecursionMaxDepth = 48;
@@ -1344,6 +1347,41 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB,
return true;
}
+static bool
+matchPhiStructures(PHINode *P1, PHINode *P2,
+ SmallSet<std::pair<PHINode *, PHINode *>, 8> &MatchingPhis) {
+ assert(P1->getParent() == P2->getParent() && "Must have the same parent!");
+ if (P1->getType() != P2->getType())
+ return false;
+ // Don't analyze too complex phi structures
+ if (MatchingPhis.size() > DeduplicatePhisMaxDepth)
+ return false;
+
+ if (P2 > P1)
+ std::swap(P1, P2);
+ if (!MatchingPhis.insert(std::make_pair(P1, P2)).second)
+ return true;
+
+ SmallDenseMap<BasicBlock *, Value *, 8> IncomingValues;
+ for (int i = 0, e = P1->getNumIncomingValues(); i != e; ++i)
+ IncomingValues[P1->getIncomingBlock(i)] = P1->getIncomingValue(i);
+
+ for (int i = 0, e = P2->getNumIncomingValues(); i != e; ++i) {
+ Value *I1 = IncomingValues[P2->getIncomingBlock(i)];
+ Value *I2 = P2->getIncomingValue(i);
+ if (I1 == I2)
+ continue;
+ if (auto *I1Phi = dyn_cast<PHINode>(I1))
+ if (auto *I2Phi = dyn_cast<PHINode>(I2))
+ if (I1Phi->getParent() == I2Phi->getParent())
+ if (matchPhiStructures(I1Phi, I2Phi, MatchingPhis))
+ continue;
+ return false;
+ }
+
+ return true;
+}
+
static bool
EliminateDuplicatePHINodesNaiveImpl(BasicBlock *BB,
SmallPtrSetImpl<PHINode *> &ToRemove) {
@@ -1364,7 +1402,9 @@ EliminateDuplicatePHINodesNaiveImpl(BasicBlock *BB,
for (auto J = I; PHINode *DuplicatePN = dyn_cast<PHINode>(J); ++J) {
if (ToRemove.contains(DuplicatePN))
continue;
- if (!DuplicatePN->isIdenticalToWhenDefined(PN))
+ SmallSet<std::pair<PHINode *, PHINode *>, 8> MatchingPhis;
+ if (!DuplicatePN->isIdenticalToWhenDefined(PN) &&
+ !matchPhiStructures(PN, DuplicatePN, MatchingPhis))
continue;
// A duplicate. Replace this PHI with the base PHI.
++NumPHICSEs;
@@ -1400,15 +1440,16 @@ EliminateDuplicatePHINodesSetBasedImpl(BasicBlock *BB,
return PN == getEmptyKey() || PN == getTombstoneKey();
}
- // WARNING: this logic must be kept in sync with
- // Instruction::isIdenticalToWhenDefined()!
static unsigned getHashValueImpl(PHINode *PN) {
- // Compute a hash value on the operands. Instcombine will likely have
- // sorted them, which helps expose duplicates, but we have to check all
- // the operands to be safe in case instcombine hasn't run.
- return static_cast<unsigned>(hash_combine(
- hash_combine_range(PN->value_op_begin(), PN->value_op_end()),
- hash_combine_range(PN->block_begin(), PN->block_end())));
+ unsigned Result = 0;
+ for (int i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
+ auto *Incoming = PN->getIncomingValue(i);
+ if (!isa<PHINode>(Incoming))
+ Result +=
+ 1 +
+ ((intptr_t(PN->getIncomingBlock(i)) ^ intptr_t(Incoming)) >> 3);
+ }
+ return Result;
}
static unsigned getHashValue(PHINode *PN) {
@@ -1423,18 +1464,19 @@ EliminateDuplicatePHINodesSetBasedImpl(BasicBlock *BB,
return getHashValueImpl(PN);
}
- static bool isEqualImpl(PHINode *LHS, PHINode *RHS) {
- if (isSentinel(LHS) || isSentinel(RHS))
- return LHS == RHS;
- return LHS->isIdenticalTo(RHS);
- }
-
static bool isEqual(PHINode *LHS, PHINode *RHS) {
// These comparisons are nontrivial, so assert that equality implies
// hash equality (DenseMap demands this as an invariant).
- bool Result = isEqualImpl(LHS, RHS);
- assert(!Result || (isSentinel(LHS) && LHS == RHS) ||
- getHashValueImpl(LHS) == getHashValueImpl(RHS));
+ if (LHS == getEmptyKey() || LHS == getTombstoneKey() ||
+ RHS == getEmptyKey() || RHS == getTombstoneKey())
+ return LHS == RHS;
+ SmallSet<std::pair<PHINode *, PHINode *>, 8> MatchingPhis;
+ bool Result = matchPhiStructures(LHS, RHS, MatchingPhis);
+#ifndef NDEBUG
+ SmallSet<std::pair<PHINode *, PHINode *>, 8> MatchingPhis2;
+ bool Result2 = matchPhiStructures(RHS, LHS, MatchingPhis2);
+ assert(Result2 == Result && "Must be symmetric");
+#endif
return Result;
}
};
diff --git a/llvm/unittests/Transforms/Utils/LocalTest.cpp b/llvm/unittests/Transforms/Utils/LocalTest.cpp
index 8225774104575..6ab6742a6d641 100644
--- a/llvm/unittests/Transforms/Utils/LocalTest.cpp
+++ b/llvm/unittests/Transforms/Utils/LocalTest.cpp
@@ -114,6 +114,78 @@ static std::unique_ptr<Module> parseIR(LLVMContext &C, const char *IR) {
return Mod;
}
+TEST(Local, RemoveDuplicateCyclicPHINodes) {
+ LLVMContext C;
+
+ std::unique_ptr<Module> M = parseIR(C,
+ R"(
+ declare i64 @f() #0
+ declare void @f.2()
+
+ define void @f.3(i1 %flag1, i1 %flag2, i1 %flag3, i1 %flag4) {
+ bb:
+ %0 = call i64 @f()
+ br label %bb1
+
+ bb1:
+ %1 = phi i64 [ %7, %bb7 ], [ 5, %bb ]
+ %2 = phi i64 [ %8, %bb7 ], [ 5, %bb ]
+ br i1 %flag1, label %bb2, label %bb3
+
+ bb2:
+ br label %bb3
+
+ bb3:
+ %3 = phi i64 [ 1, %bb2 ], [ %1, %bb1 ]
+ %4 = phi i64 [ 1, %bb2 ], [ %2, %bb1 ]
+ br i1 %flag2, label %bb4, label %bb5
+
+ bb4:
+ br label %bb5
+
+ bb5:
+ %5 = phi i64 [ 2, %bb4 ], [ %3, %bb3 ]
+ %6 = phi i64 [ 2, %bb4 ], [ %4, %bb3 ]
+ br i1 %flag3, label %bb6, label %bb7
+
+ bb6:
+ br label %bb7
+
+ bb7:
+ %7 = phi i64 [ 3, %bb6 ], [ %5, %bb5 ]
+ %8 = phi i64 [ 3, %bb6 ], [ %6, %bb5 ]
+ br i1 %flag4, label %bb1, label %bb8
+
+ bb8:
+ call void @f.2()
+ ret void
+ }
+ )");
+
+ auto *GV = M->getNamedValue("f.3");
+ ASSERT_TRUE(GV);
+ auto *F = dyn_cast<Function>(GV);
+ ASSERT_TRUE(F);
+
+ for (Function::iterator I = F->begin(), E = F->end(); I != E;) {
+ BasicBlock *BB = &*I++;
+ EliminateDuplicatePHINodes(BB);
+ }
+
+ // No block should have more than 2 PHIs
+ for (Function::iterator I = F->begin(), E = F->end(); I != E;) {
+ BasicBlock *BB = &*I++;
+ int PHICount = 0;
+ for (BasicBlock::iterator J = BB->begin(), JE = BB->end(); J != JE; ++J) {
+ Instruction *Inst = &*J;
+ if (isa<PHINode>(Inst)) {
+ PHICount++;
+ EXPECT_TRUE(PHICount < 2);
+ }
+ }
+ }
+}
+
TEST(Local, ReplaceDbgDeclare) {
LLVMContext C;
>From f23d861dd0c681ae51179fc68a43b95594cf24e5 Mon Sep 17 00:00:00 2001
From: Marek Sedlacek <msedlacek at azul.com>
Date: Wed, 3 Apr 2024 12:07:18 +0200
Subject: [PATCH 2/4] Removed cyclic phis from a test, which will be removed by
this change
---
llvm/test/Transforms/GVN/pr64598.ll | 12 ------------
1 file changed, 12 deletions(-)
diff --git a/llvm/test/Transforms/GVN/pr64598.ll b/llvm/test/Transforms/GVN/pr64598.ll
index 902af984bce2b..ed6e567bc1510 100644
--- a/llvm/test/Transforms/GVN/pr64598.ll
+++ b/llvm/test/Transforms/GVN/pr64598.ll
@@ -17,18 +17,11 @@ define i32 @main(i64 %x, ptr %d, ptr noalias %p) {
; CHECK-NEXT: [[T2_PRE_PRE25:%.*]] = phi ptr [ [[T2_PRE_PRE23]], [[LOOP2_LATCH_LOOP2_CRIT_EDGE:%.*]] ], [ [[T2_PRE_PRE]], [[LOOP]] ]
; CHECK-NEXT: [[T1_PRE_PRE21:%.*]] = phi ptr [ [[T1_PRE_PRE19]], [[LOOP2_LATCH_LOOP2_CRIT_EDGE]] ], [ [[T1_PRE_PRE]], [[LOOP]] ]
; CHECK-NEXT: [[T3_PRE:%.*]] = phi ptr [ [[T3_PRE16:%.*]], [[LOOP2_LATCH_LOOP2_CRIT_EDGE]] ], [ [[T3_PRE_PRE_PRE]], [[LOOP]] ]
-; CHECK-NEXT: [[T2_PRE:%.*]] = phi ptr [ [[T2_PRE13:%.*]], [[LOOP2_LATCH_LOOP2_CRIT_EDGE]] ], [ [[T2_PRE_PRE]], [[LOOP]] ]
-; CHECK-NEXT: [[T1_PRE:%.*]] = phi ptr [ [[T1_PRE10:%.*]], [[LOOP2_LATCH_LOOP2_CRIT_EDGE]] ], [ [[T1_PRE_PRE]], [[LOOP]] ]
; CHECK-NEXT: br label [[LOOP3:%.*]]
; CHECK: loop3:
; CHECK-NEXT: [[T2_PRE_PRE24:%.*]] = phi ptr [ [[T2_PRE_PRE23]], [[LOOP3_LATCH:%.*]] ], [ [[T2_PRE_PRE25]], [[LOOP2]] ]
; CHECK-NEXT: [[T1_PRE_PRE20:%.*]] = phi ptr [ [[T1_PRE_PRE19]], [[LOOP3_LATCH]] ], [ [[T1_PRE_PRE21]], [[LOOP2]] ]
; CHECK-NEXT: [[T3_PRE17:%.*]] = phi ptr [ [[T3_PRE16]], [[LOOP3_LATCH]] ], [ [[T3_PRE]], [[LOOP2]] ]
-; CHECK-NEXT: [[T2_PRE14:%.*]] = phi ptr [ [[T2_PRE13]], [[LOOP3_LATCH]] ], [ [[T2_PRE]], [[LOOP2]] ]
-; CHECK-NEXT: [[T1_PRE11:%.*]] = phi ptr [ [[T1_PRE10]], [[LOOP3_LATCH]] ], [ [[T1_PRE]], [[LOOP2]] ]
-; CHECK-NEXT: [[T78:%.*]] = phi ptr [ [[T7:%.*]], [[LOOP3_LATCH]] ], [ [[T3_PRE]], [[LOOP2]] ]
-; CHECK-NEXT: [[T66:%.*]] = phi ptr [ [[T6:%.*]], [[LOOP3_LATCH]] ], [ [[T2_PRE]], [[LOOP2]] ]
-; CHECK-NEXT: [[T54:%.*]] = phi ptr [ [[T5:%.*]], [[LOOP3_LATCH]] ], [ [[T1_PRE]], [[LOOP2]] ]
; CHECK-NEXT: [[TOBOOL_NOT2_I:%.*]] = icmp eq i64 [[X]], 0
; CHECK-NEXT: br i1 false, label [[LOOP3_LOOP3_LATCH_CRIT_EDGE:%.*]], label [[FOR_BODY_LR_PH_I:%.*]]
; CHECK: loop3.loop3.latch_crit_edge:
@@ -43,11 +36,6 @@ define i32 @main(i64 %x, ptr %d, ptr noalias %p) {
; CHECK-NEXT: [[T2_PRE_PRE23]] = phi ptr [ [[T2_PRE_PRE24]], [[LOOP3_LOOP3_LATCH_CRIT_EDGE]] ], [ [[T6_PRE]], [[FOR_BODY_LR_PH_I]] ]
; CHECK-NEXT: [[T1_PRE_PRE19]] = phi ptr [ [[T1_PRE_PRE20]], [[LOOP3_LOOP3_LATCH_CRIT_EDGE]] ], [ [[T5_PRE]], [[FOR_BODY_LR_PH_I]] ]
; CHECK-NEXT: [[T3_PRE16]] = phi ptr [ [[T3_PRE17]], [[LOOP3_LOOP3_LATCH_CRIT_EDGE]] ], [ [[T7_PRE]], [[FOR_BODY_LR_PH_I]] ]
-; CHECK-NEXT: [[T2_PRE13]] = phi ptr [ [[T2_PRE14]], [[LOOP3_LOOP3_LATCH_CRIT_EDGE]] ], [ [[T6_PRE]], [[FOR_BODY_LR_PH_I]] ]
-; CHECK-NEXT: [[T1_PRE10]] = phi ptr [ [[T1_PRE11]], [[LOOP3_LOOP3_LATCH_CRIT_EDGE]] ], [ [[T5_PRE]], [[FOR_BODY_LR_PH_I]] ]
-; CHECK-NEXT: [[T7]] = phi ptr [ [[T78]], [[LOOP3_LOOP3_LATCH_CRIT_EDGE]] ], [ [[T7_PRE]], [[FOR_BODY_LR_PH_I]] ]
-; CHECK-NEXT: [[T6]] = phi ptr [ [[T66]], [[LOOP3_LOOP3_LATCH_CRIT_EDGE]] ], [ [[T6_PRE]], [[FOR_BODY_LR_PH_I]] ]
-; CHECK-NEXT: [[T5]] = phi ptr [ [[T54]], [[LOOP3_LOOP3_LATCH_CRIT_EDGE]] ], [ [[T5_PRE]], [[FOR_BODY_LR_PH_I]] ]
; CHECK-NEXT: br i1 false, label [[LOOP2_LATCH:%.*]], label [[LOOP3]]
; CHECK: loop2.latch:
; CHECK-NEXT: br i1 false, label [[LOOP2_LATCH_LOOP2_CRIT_EDGE]], label [[LOOP_LATCH]]
>From 6a0f2c61a4a28b86dd0cebfd73daf2cf0408d65e Mon Sep 17 00:00:00 2001
From: Marek Sedlacek <msedlacek at azul.com>
Date: Tue, 9 Apr 2024 11:46:42 +0200
Subject: [PATCH 3/4] Modified .ll test for when deduplication is turned off
and added a comment why we need custom hash
---
llvm/lib/Transforms/Utils/Local.cpp | 2 ++
llvm/test/Transforms/GVN/pr64598.ll | 56 +++++++++++++++++++++++++++++
2 files changed, 58 insertions(+)
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index bd3ae5b39da71..d832e762d5931 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -1441,6 +1441,8 @@ EliminateDuplicatePHINodesSetBasedImpl(BasicBlock *BB,
}
static unsigned getHashValueImpl(PHINode *PN) {
+ // Must be indifferent to the order of incoming blocks and values as
+ // matchPhiStructures() is.
unsigned Result = 0;
for (int i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
auto *Incoming = PN->getIncomingValue(i);
diff --git a/llvm/test/Transforms/GVN/pr64598.ll b/llvm/test/Transforms/GVN/pr64598.ll
index ed6e567bc1510..46314f881f4c5 100644
--- a/llvm/test/Transforms/GVN/pr64598.ll
+++ b/llvm/test/Transforms/GVN/pr64598.ll
@@ -1,5 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
; RUN: opt -S -passes=gvn < %s | FileCheck %s
+; RUN: opt -S -passes=gvn -deduplicate-phi-max-depth=1 < %s | FileCheck -check-prefix=CHECK-2 %s
define i32 @main(i64 %x, ptr %d, ptr noalias %p) {
; CHECK-LABEL: define i32 @main
@@ -45,6 +46,61 @@ define i32 @main(i64 %x, ptr %d, ptr noalias %p) {
; CHECK-NEXT: store i32 0, ptr [[D]], align 4, !tbaa [[TBAA4:![0-9]+]]
; CHECK-NEXT: br label [[LOOP]]
;
+; CHECK-2-LABEL: define i32 @main
+; CHECK-2-SAME: (i64 [[X:%.*]], ptr [[D:%.*]], ptr noalias [[P:%.*]]) {
+; CHECK-2-NEXT: entry:
+; CHECK-2-NEXT: [[T1_PRE_PRE_PRE:%.*]] = load ptr, ptr [[P]], align 8
+; CHECK-2-NEXT: [[T2_PRE_PRE_PRE:%.*]] = load ptr, ptr [[T1_PRE_PRE_PRE]], align 8, !tbaa [[TBAA0:![0-9]+]]
+; CHECK-2-NEXT: [[T3_PRE_PRE_PRE:%.*]] = load ptr, ptr [[T2_PRE_PRE_PRE]], align 8
+; CHECK-2-NEXT: br label [[LOOP:%.*]]
+; CHECK-2: loop:
+; CHECK-2-NEXT: [[T2_PRE_PRE:%.*]] = phi ptr [ [[T2_PRE_PRE23:%.*]], [[LOOP_LATCH:%.*]] ], [ [[T2_PRE_PRE_PRE]], [[ENTRY:%.*]] ]
+; CHECK-2-NEXT: [[T1_PRE_PRE:%.*]] = phi ptr [ [[T1_PRE_PRE19:%.*]], [[LOOP_LATCH]] ], [ [[T1_PRE_PRE_PRE]], [[ENTRY]] ]
+; CHECK-2-NEXT: br label [[LOOP2:%.*]]
+; CHECK-2: loop2:
+; CHECK-2-NEXT: [[T2_PRE_PRE25:%.*]] = phi ptr [ [[T2_PRE_PRE23]], [[LOOP2_LATCH_LOOP2_CRIT_EDGE:%.*]] ], [ [[T2_PRE_PRE]], [[LOOP]] ]
+; CHECK-2-NEXT: [[T1_PRE_PRE21:%.*]] = phi ptr [ [[T1_PRE_PRE19]], [[LOOP2_LATCH_LOOP2_CRIT_EDGE]] ], [ [[T1_PRE_PRE]], [[LOOP]] ]
+; CHECK-2-NEXT: [[T3_PRE:%.*]] = phi ptr [ [[T3_PRE16:%.*]], [[LOOP2_LATCH_LOOP2_CRIT_EDGE]] ], [ [[T3_PRE_PRE_PRE]], [[LOOP]] ]
+; CHECK-2-NEXT: [[T2_PRE:%.*]] = phi ptr [ [[T2_PRE13:%.*]], [[LOOP2_LATCH_LOOP2_CRIT_EDGE]] ], [ [[T2_PRE_PRE]], [[LOOP]] ]
+; CHECK-2-NEXT: [[T1_PRE:%.*]] = phi ptr [ [[T1_PRE10:%.*]], [[LOOP2_LATCH_LOOP2_CRIT_EDGE]] ], [ [[T1_PRE_PRE]], [[LOOP]] ]
+; CHECK-2-NEXT: br label [[LOOP3:%.*]]
+; CHECK-2: loop3:
+; CHECK-2-NEXT: [[T2_PRE_PRE24:%.*]] = phi ptr [ [[T2_PRE_PRE23]], [[LOOP3_LATCH:%.*]] ], [ [[T2_PRE_PRE25]], [[LOOP2]] ]
+; CHECK-2-NEXT: [[T1_PRE_PRE20:%.*]] = phi ptr [ [[T1_PRE_PRE19]], [[LOOP3_LATCH]] ], [ [[T1_PRE_PRE21]], [[LOOP2]] ]
+; CHECK-2-NEXT: [[T3_PRE17:%.*]] = phi ptr [ [[T3_PRE16]], [[LOOP3_LATCH]] ], [ [[T3_PRE]], [[LOOP2]] ]
+; CHECK-2-NEXT: [[T2_PRE14:%.*]] = phi ptr [ [[T2_PRE13]], [[LOOP3_LATCH]] ], [ [[T2_PRE]], [[LOOP2]] ]
+; CHECK-2-NEXT: [[T1_PRE11:%.*]] = phi ptr [ [[T1_PRE10]], [[LOOP3_LATCH]] ], [ [[T1_PRE]], [[LOOP2]] ]
+; CHECK-2-NEXT: [[T78:%.*]] = phi ptr [ [[T7:%.*]], [[LOOP3_LATCH]] ], [ [[T3_PRE]], [[LOOP2]] ]
+; CHECK-2-NEXT: [[T66:%.*]] = phi ptr [ [[T6:%.*]], [[LOOP3_LATCH]] ], [ [[T2_PRE]], [[LOOP2]] ]
+; CHECK-2-NEXT: [[T54:%.*]] = phi ptr [ [[T5:%.*]], [[LOOP3_LATCH]] ], [ [[T1_PRE]], [[LOOP2]] ]
+; CHECK-2-NEXT: [[TOBOOL_NOT2_I:%.*]] = icmp eq i64 [[X]], 0
+; CHECK-2-NEXT: br i1 false, label [[LOOP3_LOOP3_LATCH_CRIT_EDGE:%.*]], label [[FOR_BODY_LR_PH_I:%.*]]
+; CHECK-2: loop3.loop3.latch_crit_edge:
+; CHECK-2-NEXT: br label [[LOOP3_LATCH]]
+; CHECK-2: for.body.lr.ph.i:
+; CHECK-2-NEXT: store i32 0, ptr [[P]], align 4
+; CHECK-2-NEXT: [[T5_PRE:%.*]] = load ptr, ptr [[P]], align 8
+; CHECK-2-NEXT: [[T6_PRE:%.*]] = load ptr, ptr [[T5_PRE]], align 8, !tbaa [[TBAA0]]
+; CHECK-2-NEXT: [[T7_PRE:%.*]] = load ptr, ptr [[T6_PRE]], align 8
+; CHECK-2-NEXT: br label [[LOOP3_LATCH]]
+; CHECK-2: loop3.latch:
+; CHECK-2-NEXT: [[T2_PRE_PRE23]] = phi ptr [ [[T2_PRE_PRE24]], [[LOOP3_LOOP3_LATCH_CRIT_EDGE]] ], [ [[T6_PRE]], [[FOR_BODY_LR_PH_I]] ]
+; CHECK-2-NEXT: [[T1_PRE_PRE19]] = phi ptr [ [[T1_PRE_PRE20]], [[LOOP3_LOOP3_LATCH_CRIT_EDGE]] ], [ [[T5_PRE]], [[FOR_BODY_LR_PH_I]] ]
+; CHECK-2-NEXT: [[T3_PRE16]] = phi ptr [ [[T3_PRE17]], [[LOOP3_LOOP3_LATCH_CRIT_EDGE]] ], [ [[T7_PRE]], [[FOR_BODY_LR_PH_I]] ]
+; CHECK-2-NEXT: [[T2_PRE13]] = phi ptr [ [[T2_PRE14]], [[LOOP3_LOOP3_LATCH_CRIT_EDGE]] ], [ [[T6_PRE]], [[FOR_BODY_LR_PH_I]] ]
+; CHECK-2-NEXT: [[T1_PRE10]] = phi ptr [ [[T1_PRE11]], [[LOOP3_LOOP3_LATCH_CRIT_EDGE]] ], [ [[T5_PRE]], [[FOR_BODY_LR_PH_I]] ]
+; CHECK-2-NEXT: [[T7]] = phi ptr [ [[T78]], [[LOOP3_LOOP3_LATCH_CRIT_EDGE]] ], [ [[T7_PRE]], [[FOR_BODY_LR_PH_I]] ]
+; CHECK-2-NEXT: [[T6]] = phi ptr [ [[T66]], [[LOOP3_LOOP3_LATCH_CRIT_EDGE]] ], [ [[T6_PRE]], [[FOR_BODY_LR_PH_I]] ]
+; CHECK-2-NEXT: [[T5]] = phi ptr [ [[T54]], [[LOOP3_LOOP3_LATCH_CRIT_EDGE]] ], [ [[T5_PRE]], [[FOR_BODY_LR_PH_I]] ]
+; CHECK-2-NEXT: br i1 false, label [[LOOP2_LATCH:%.*]], label [[LOOP3]]
+; CHECK-2: loop2.latch:
+; CHECK-2-NEXT: br i1 false, label [[LOOP2_LATCH_LOOP2_CRIT_EDGE]], label [[LOOP_LATCH]]
+; CHECK-2: loop2.latch.loop2_crit_edge:
+; CHECK-2-NEXT: br label [[LOOP2]]
+; CHECK-2: loop.latch:
+; CHECK-2-NEXT: store i32 0, ptr [[D]], align 4, !tbaa [[TBAA4:![0-9]+]]
+; CHECK-2-NEXT: br label [[LOOP]]
+;
entry:
br label %loop
>From 7fcfe5e03c30834c28d1da9c0e8414b4ee66e265 Mon Sep 17 00:00:00 2001
From: Marek Sedlacek <msedlacek at azul.com>
Date: Fri, 17 May 2024 10:17:53 +0200
Subject: [PATCH 4/4] Lowered the default max depth for deduplication
---
llvm/lib/Transforms/Utils/Local.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index d832e762d5931..f6e686aadda7d 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -112,7 +112,7 @@ static cl::opt<unsigned> PHICSENumPHISmallSize(
"perform a (faster!) exhaustive search instead of set-driven one."));
static cl::opt<unsigned> DeduplicatePhisMaxDepth("deduplicate-phi-max-depth",
- cl::Hidden, cl::init(8));
+ cl::Hidden, cl::init(4));
// Max recursion depth for collectBitParts used when detecting bswap and
// bitreverse idioms.
More information about the llvm-commits
mailing list