[PATCH] D100101: [VPlan] Add VPBasicBlock::phis() helper (NFC).
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 27 02:25:23 PDT 2021
fhahn updated this revision to Diff 340763.
fhahn added a comment.
Updates:
1. add comment about PHI node order to VPBasicBlock
2. use existing getFirstNonPhi() in phis()
3. add VPrecipeBase::isPhi(), use it in getFirstNonPhi
In D100101#2718833 <https://reviews.llvm.org/D100101#2718833>, @Ayal wrote:
> Looks good to me!
>
> This is aligned with BasicBlock::phis(), with a simpler implementation based on finding FirstNonPHI. Number of phi's is expected to be limited, so running twice until FirstNonPHI instead of once should be tolerable.
>
> Would be good to document some place that all phi recipes appear before any non-phi recipe in VPBasicBlock, as in BasicBlock. (This assumption predates this patch.)
Thanks for taking a look! I added a sentence to the top-level comment for VPBasicBlock saying that all PHI-like recipes must come before non-phi recipes. I hope that's sufficient or were you thinking about a different place?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D100101/new/
https://reviews.llvm.org/D100101
Files:
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/lib/Transforms/Vectorize/VPlan.cpp
llvm/lib/Transforms/Vectorize/VPlan.h
Index: llvm/lib/Transforms/Vectorize/VPlan.h
===================================================================
--- llvm/lib/Transforms/Vectorize/VPlan.h
+++ llvm/lib/Transforms/Vectorize/VPlan.h
@@ -685,6 +685,12 @@
/// Returns true if the recipe may have side-effects.
bool mayHaveSideEffects() const;
+
+ /// Returns true for PHI-like recipes.
+ bool isPhi() const {
+ return getVPDefID() == VPWidenIntOrFpInductionSC || getVPDefID() == VPWidenPHISC ||
+ getVPDefID() == VPPredInstPHISC || getVPDefID() == VPWidenCanonicalIVSC;
+ }
};
inline bool VPUser::classof(const VPDef *Def) {
@@ -1433,7 +1439,7 @@
/// VPBasicBlock serves as the leaf of the Hierarchical Control-Flow Graph. It
/// holds a sequence of zero or more VPRecipe's each representing a sequence of
-/// output IR instructions.
+/// output IR instructions. All PHI-like recipes must come before any non-PHI recipes.
class VPBasicBlock : public VPBlockBase {
public:
using RecipeListTy = iplist<VPRecipeBase>;
@@ -1511,6 +1517,11 @@
/// Return the position of the first non-phi node recipe in the block.
iterator getFirstNonPhi();
+ /// Returns an iterator range over the PHI-like recipes in the block.
+ iterator_range<iterator> phis() {
+ return make_range(begin(), getFirstNonPhi());
+ }
+
void dropAllReferences(VPValue *NewValue) override;
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Index: llvm/lib/Transforms/Vectorize/VPlan.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/VPlan.cpp
+++ llvm/lib/Transforms/Vectorize/VPlan.cpp
@@ -249,10 +249,7 @@
VPBasicBlock::iterator VPBasicBlock::getFirstNonPhi() {
iterator It = begin();
- while (It != end() && (isa<VPWidenPHIRecipe>(&*It) ||
- isa<VPWidenIntOrFpInductionRecipe>(&*It) ||
- isa<VPPredInstPHIRecipe>(&*It) ||
- isa<VPWidenCanonicalIVRecipe>(&*It)))
+ while (It != end() && It->isPhi())
It++;
return It;
}
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -4066,13 +4066,10 @@
// original loop is widened to a vector form so we can use them to construct
// the incoming edges.
VPBasicBlock *Header = State.Plan->getEntry()->getEntryBasicBlock();
- for (VPRecipeBase &R : *Header) {
- if (isa<VPWidenIntOrFpInductionRecipe>(&R))
- continue;
+ for (VPRecipeBase &R : Header->phis()) {
VPWidenPHIRecipe *PhiR = dyn_cast<VPWidenPHIRecipe>(&R);
if (!PhiR)
- break;
-
+ continue;
auto *OrigPhi = cast<PHINode>(PhiR->getUnderlyingValue());
if (PhiR->getRecurrenceDescriptor()) {
fixReduction(PhiR, State);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100101.340763.patch
Type: text/x-patch
Size: 2870 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210427/09b00d24/attachment.bin>
More information about the llvm-commits
mailing list