Skip to content

Commit 140de9d

Browse files
committed
Use VPDom
1 parent 069c762 commit 140de9d

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"
@@ -267,7 +268,12 @@ Value *VPTransformState::get(VPValue *Def, bool NeedsScalar) {
267268
return Data.VPV2Vector[Def];
268269

269270
auto GetBroadcastInstrs = [this, Def](Value *V) {
270-
bool SafeToHoist = !Def->hasDefiningRecipe();
271+
VPDominatorTree VPDT(*Plan);
272+
bool SafeToHoist =
273+
!Def->hasDefiningRecipe() ||
274+
VPDT.properlyDominates(Def->getDefiningRecipe()->getParent(),
275+
Plan->getVectorPreheader());
276+
271277
if (VF.isScalar())
272278
return V;
273279
// 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)