[llvm] [SLP] Normalize debug messages for newTreeEntry. (PR #119514)
Han-Kuan Chen via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 17 22:10:17 PST 2024
https://github.com/HanKuanChen updated https://github.com/llvm/llvm-project/pull/119514
>From b6ed2af869d23f0b9517143f114dfe75abe3b103 Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Mon, 9 Dec 2024 02:04:54 -0800
Subject: [PATCH 1/5] [SLP] Normalize debug messages for newTreeEntry.
A debug message should follow after newTreeEntry.
Make ExtractValueInst and ExtractElementInst use setOperand directly.
---
.../Transforms/Vectorize/SLPVectorizer.cpp | 54 ++++++++++++-------
1 file changed, 34 insertions(+), 20 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index a1d7515f031cfc..67d785016065ec 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -8388,7 +8388,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
TreeEntry *TE =
newTreeEntry(VL, Bundle, S, UserTreeIdx, ReuseShuffleIndices);
- LLVM_DEBUG(dbgs() << "SLP: added a vector of PHINodes.\n");
+ LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (PHINode).\n");
// Keeps the reordered operands to avoid code duplication.
PHIHandler Handler(*DT, PH, VL);
@@ -8417,13 +8417,13 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
}
// Insert new order with initial value 0, if it does not exist,
// otherwise return the iterator to the existing one.
- newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
- ReuseShuffleIndices, CurrentOrder);
+ TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
+ ReuseShuffleIndices, CurrentOrder);
+ LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry "
+ "(ExtractValueInst/ExtractElementInst).\n");
// This is a special case, as it does not gather, but at the same time
// we are not extending buildTree_rec() towards the operands.
- ValueList Op0;
- Op0.assign(VL.size(), VL0->getOperand(0));
- VectorizableTree.back()->setOperand(0, Op0);
+ TE->setOperand(*this);
return;
}
case Instruction::InsertElement: {
@@ -8451,7 +8451,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
CurrentOrder.clear();
TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
{}, CurrentOrder);
- LLVM_DEBUG(dbgs() << "SLP: added inserts bundle.\n");
+ LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (InsertElementInst).\n");
TE->setOperand(*this);
buildTree_rec(TE->getOperand(1), Depth + 1, {TE, 1});
@@ -8471,21 +8471,25 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
ReuseShuffleIndices, CurrentOrder, InterleaveFactor);
if (CurrentOrder.empty())
- LLVM_DEBUG(dbgs() << "SLP: added a vector of loads.\n");
+ LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (LoadInst).\n");
else
- LLVM_DEBUG(dbgs() << "SLP: added a vector of jumbled loads.\n");
+ LLVM_DEBUG(dbgs()
+ << "SLP: added a new TreeEntry (jumbled LoadInst).\n");
break;
case TreeEntry::StridedVectorize:
// Vectorizing non-consecutive loads with `llvm.masked.gather`.
TE = newTreeEntry(VL, TreeEntry::StridedVectorize, Bundle, S,
UserTreeIdx, ReuseShuffleIndices, CurrentOrder);
- LLVM_DEBUG(dbgs() << "SLP: added a vector of strided loads.\n");
+ LLVM_DEBUG(
+ dbgs() << "SLP: added a new TreeEntry (strided LoadInst).\n");
break;
case TreeEntry::ScatterVectorize:
// Vectorizing non-consecutive loads with `llvm.masked.gather`.
TE = newTreeEntry(VL, TreeEntry::ScatterVectorize, Bundle, S,
UserTreeIdx, ReuseShuffleIndices);
- LLVM_DEBUG(dbgs() << "SLP: added a vector of non-consecutive loads.\n");
+ LLVM_DEBUG(
+ dbgs()
+ << "SLP: added a new TreeEntry (non-consecutive LoadInst).\n");
break;
case TreeEntry::CombinedVectorize:
case TreeEntry::NeedToGather:
@@ -8529,7 +8533,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
}
TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
ReuseShuffleIndices);
- LLVM_DEBUG(dbgs() << "SLP: added a vector of casts.\n");
+ LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (CastInst).\n");
TE->setOperand(*this);
for (unsigned I : seq<unsigned>(VL0->getNumOperands()))
@@ -8556,7 +8560,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
CmpInst::Predicate P0 = cast<CmpInst>(VL0)->getPredicate();
TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
ReuseShuffleIndices);
- LLVM_DEBUG(dbgs() << "SLP: added a vector of compares.\n");
+ LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (CmpInst).\n");
ValueList Left, Right;
VLOperands Ops(VL, VL0, *this);
@@ -8626,7 +8630,9 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
case Instruction::Freeze: {
TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
ReuseShuffleIndices);
- LLVM_DEBUG(dbgs() << "SLP: added a vector of un/bin op.\n");
+ LLVM_DEBUG(
+ dbgs() << "SLP: added a new TreeEntry "
+ "(SelectInst/UnaryOperator/BinaryOperator/FreezeInst).\n");
TE->setOperand(*this, isa<BinaryOperator>(VL0) && isCommutative(VL0));
for (unsigned I : seq<unsigned>(VL0->getNumOperands()))
@@ -8636,7 +8642,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
case Instruction::GetElementPtr: {
TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
ReuseShuffleIndices);
- LLVM_DEBUG(dbgs() << "SLP: added a vector of GEPs.\n");
+ LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (GetElementPtrInst).\n");
SmallVector<ValueList, 2> Operands(2);
// Prepare the operand vector for pointer operands.
for (Value *V : VL) {
@@ -8694,12 +8700,13 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
fixupOrderingIndices(CurrentOrder);
TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
ReuseShuffleIndices, CurrentOrder);
- TE->setOperand(*this);
- buildTree_rec(TE->getOperand(0), Depth + 1, {TE, 0});
if (Consecutive)
- LLVM_DEBUG(dbgs() << "SLP: added a vector of stores.\n");
+ LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (StoreInst).\n");
else
- LLVM_DEBUG(dbgs() << "SLP: added a vector of jumbled stores.\n");
+ LLVM_DEBUG(
+ dbgs() << "SLP: added a new TreeEntry (jumbled StoreInst).\n");
+ TE->setOperand(*this);
+ buildTree_rec(TE->getOperand(0), Depth + 1, {TE, 0});
return;
}
case Instruction::Call: {
@@ -8710,6 +8717,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
ReuseShuffleIndices);
+ LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (CallInst).\n");
TE->setOperand(*this, isCommutative(VL0));
for (unsigned I : seq<unsigned>(CI->arg_size())) {
// For scalar operands no need to create an entry since no need to
@@ -8723,7 +8731,13 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
case Instruction::ShuffleVector: {
TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
ReuseShuffleIndices);
- LLVM_DEBUG(dbgs() << "SLP: added a ShuffleVector op.\n");
+ if (S.isAltShuffle()) {
+ LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (alternate op).\n");
+ } else {
+ assert(SLPReVec && "Only supported by REVEC.");
+ LLVM_DEBUG(
+ dbgs() << "SLP: added a new TreeEntry (ShuffleVectorInst).\n");
+ }
// Reorder operands if reordering would enable vectorization.
auto *CI = dyn_cast<CmpInst>(VL0);
>From bc6b05335f30f9764ee70d629ef8f0d5b578a75a Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Wed, 11 Dec 2024 02:10:28 -0800
Subject: [PATCH 2/5] alternate op->isAltShuffle
---
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 67d785016065ec..fd6765d8867242 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -8732,7 +8732,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
ReuseShuffleIndices);
if (S.isAltShuffle()) {
- LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (alternate op).\n");
+ LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (isAltShuffle).\n");
} else {
assert(SLPReVec && "Only supported by REVEC.");
LLVM_DEBUG(
>From 96862bd5711eb5057511ce44ff26fce2ed5c45f5 Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Wed, 11 Dec 2024 22:07:16 -0800
Subject: [PATCH 3/5] dump TreeEntry after newTreeEntry
---
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index fd6765d8867242..5b3bad0aba5a5f 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -3671,6 +3671,7 @@ class BoUpSLP {
if (UserTreeIdx.UserTE)
Last->UserTreeIndices.push_back(UserTreeIdx);
+ Last->dump();
return Last;
}
>From a7de688cdf4279ff207f547ec62a2effce650428 Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Sun, 15 Dec 2024 23:16:03 -0800
Subject: [PATCH 4/5] add LLVM_DEBUG
---
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 5b3bad0aba5a5f..02be2b462657e8 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -3671,7 +3671,7 @@ class BoUpSLP {
if (UserTreeIdx.UserTE)
Last->UserTreeIndices.push_back(UserTreeIdx);
- Last->dump();
+ LLVM_DEBUG(Last->dump());
return Last;
}
>From edccabdc318c6cb103db731b1460ecd83a7c653d Mon Sep 17 00:00:00 2001
From: Han-Kuan Chen <hankuan.chen at sifive.com>
Date: Tue, 17 Dec 2024 21:59:21 -0800
Subject: [PATCH 5/5] apply comment
---
.../Transforms/Vectorize/SLPVectorizer.cpp | 50 ++++++++++++-------
1 file changed, 32 insertions(+), 18 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 02be2b462657e8..23d07c5fd04dfa 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -3671,7 +3671,6 @@ class BoUpSLP {
if (UserTreeIdx.UserTE)
Last->UserTreeIndices.push_back(UserTreeIdx);
- LLVM_DEBUG(Last->dump());
return Last;
}
@@ -8389,7 +8388,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
TreeEntry *TE =
newTreeEntry(VL, Bundle, S, UserTreeIdx, ReuseShuffleIndices);
- LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (PHINode).\n");
+ LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (PHINode).\n";
+ TE->dump());
// Keeps the reordered operands to avoid code duplication.
PHIHandler Handler(*DT, PH, VL);
@@ -8421,7 +8421,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
ReuseShuffleIndices, CurrentOrder);
LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry "
- "(ExtractValueInst/ExtractElementInst).\n");
+ "(ExtractValueInst/ExtractElementInst).\n";
+ TE->dump());
// This is a special case, as it does not gather, but at the same time
// we are not extending buildTree_rec() towards the operands.
TE->setOperand(*this);
@@ -8452,7 +8453,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
CurrentOrder.clear();
TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
{}, CurrentOrder);
- LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (InsertElementInst).\n");
+ LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (InsertElementInst).\n";
+ TE->dump());
TE->setOperand(*this);
buildTree_rec(TE->getOperand(1), Depth + 1, {TE, 1});
@@ -8472,17 +8474,19 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
ReuseShuffleIndices, CurrentOrder, InterleaveFactor);
if (CurrentOrder.empty())
- LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (LoadInst).\n");
+ LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (LoadInst).\n";
+ TE->dump());
else
LLVM_DEBUG(dbgs()
- << "SLP: added a new TreeEntry (jumbled LoadInst).\n");
+ << "SLP: added a new TreeEntry (jumbled LoadInst).\n";
+ TE->dump());
break;
case TreeEntry::StridedVectorize:
// Vectorizing non-consecutive loads with `llvm.masked.gather`.
TE = newTreeEntry(VL, TreeEntry::StridedVectorize, Bundle, S,
UserTreeIdx, ReuseShuffleIndices, CurrentOrder);
- LLVM_DEBUG(
- dbgs() << "SLP: added a new TreeEntry (strided LoadInst).\n");
+ LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (strided LoadInst).\n";
+ TE->dump());
break;
case TreeEntry::ScatterVectorize:
// Vectorizing non-consecutive loads with `llvm.masked.gather`.
@@ -8490,7 +8494,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
UserTreeIdx, ReuseShuffleIndices);
LLVM_DEBUG(
dbgs()
- << "SLP: added a new TreeEntry (non-consecutive LoadInst).\n");
+ << "SLP: added a new TreeEntry (non-consecutive LoadInst).\n";
+ TE->dump());
break;
case TreeEntry::CombinedVectorize:
case TreeEntry::NeedToGather:
@@ -8534,7 +8539,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
}
TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
ReuseShuffleIndices);
- LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (CastInst).\n");
+ LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (CastInst).\n";
+ TE->dump());
TE->setOperand(*this);
for (unsigned I : seq<unsigned>(VL0->getNumOperands()))
@@ -8561,7 +8567,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
CmpInst::Predicate P0 = cast<CmpInst>(VL0)->getPredicate();
TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
ReuseShuffleIndices);
- LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (CmpInst).\n");
+ LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (CmpInst).\n";
+ TE->dump());
ValueList Left, Right;
VLOperands Ops(VL, VL0, *this);
@@ -8633,7 +8640,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
ReuseShuffleIndices);
LLVM_DEBUG(
dbgs() << "SLP: added a new TreeEntry "
- "(SelectInst/UnaryOperator/BinaryOperator/FreezeInst).\n");
+ "(SelectInst/UnaryOperator/BinaryOperator/FreezeInst).\n";
+ TE->dump());
TE->setOperand(*this, isa<BinaryOperator>(VL0) && isCommutative(VL0));
for (unsigned I : seq<unsigned>(VL0->getNumOperands()))
@@ -8643,7 +8651,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
case Instruction::GetElementPtr: {
TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
ReuseShuffleIndices);
- LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (GetElementPtrInst).\n");
+ LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (GetElementPtrInst).\n";
+ TE->dump());
SmallVector<ValueList, 2> Operands(2);
// Prepare the operand vector for pointer operands.
for (Value *V : VL) {
@@ -8702,10 +8711,12 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
ReuseShuffleIndices, CurrentOrder);
if (Consecutive)
- LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (StoreInst).\n");
+ LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (StoreInst).\n";
+ TE->dump());
else
LLVM_DEBUG(
- dbgs() << "SLP: added a new TreeEntry (jumbled StoreInst).\n");
+ dbgs() << "SLP: added a new TreeEntry (jumbled StoreInst).\n";
+ TE->dump());
TE->setOperand(*this);
buildTree_rec(TE->getOperand(0), Depth + 1, {TE, 0});
return;
@@ -8718,7 +8729,8 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
ReuseShuffleIndices);
- LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (CallInst).\n");
+ LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (CallInst).\n";
+ TE->dump());
TE->setOperand(*this, isCommutative(VL0));
for (unsigned I : seq<unsigned>(CI->arg_size())) {
// For scalar operands no need to create an entry since no need to
@@ -8733,11 +8745,13 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
ReuseShuffleIndices);
if (S.isAltShuffle()) {
- LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (isAltShuffle).\n");
+ LLVM_DEBUG(dbgs() << "SLP: added a new TreeEntry (isAltShuffle).\n";
+ TE->dump());
} else {
assert(SLPReVec && "Only supported by REVEC.");
LLVM_DEBUG(
- dbgs() << "SLP: added a new TreeEntry (ShuffleVectorInst).\n");
+ dbgs() << "SLP: added a new TreeEntry (ShuffleVectorInst).\n";
+ TE->dump());
}
// Reorder operands if reordering would enable vectorization.
More information about the llvm-commits
mailing list