Skip to content

Commit 415d657

Browse files
committed
Use VPDom
1 parent 8af36bc commit 415d657

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "VPlan.h"
2020
#include "LoopVectorizationPlanner.h"
2121
#include "VPlanCFG.h"
22+
#include "VPlanDominatorTree.h"
2223
#include "VPlanPatternMatch.h"
2324
#include "VPlanTransforms.h"
2425
#include "VPlanUtils.h"
@@ -262,7 +263,12 @@ Value *VPTransformState::get(VPValue *Def, bool NeedsScalar) {
262263
return Data.VPV2Vector[Def];
263264

264265
auto GetBroadcastInstrs = [this, Def](Value *V) {
265-
bool SafeToHoist = !Def->hasDefiningRecipe();
266+
VPDominatorTree VPDT(*Plan);
267+
bool SafeToHoist =
268+
!Def->hasDefiningRecipe() ||
269+
VPDT.properlyDominates(Def->getDefiningRecipe()->getParent(),
270+
Plan->getVectorPreheader());
271+
266272
if (VF.isScalar())
267273
return V;
268274
// Place the code for broadcasting invariant variables in the new preheader.

llvm/lib/Transforms/Vectorize/VPlanDominatorTree.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ class VPDominatorTree : public DominatorTreeBase<VPBlockBase, false> {
3939

4040
public:
4141
VPDominatorTree() = default;
42+
explicit VPDominatorTree(VPlan &Plan) { recalculate(Plan); }
4243

4344
/// Returns true if \p A properly dominates \p B.
45+
using Base::properlyDominates;
4446
bool properlyDominates(const VPRecipeBase *A, const VPRecipeBase *B);
4547
};
4648

0 commit comments

Comments
 (0)