Skip to content

Commit 437f0bb

Browse files
committed
Revert "[LV] Allow tryToCreateWidenRecipe to return a VPValue, use for blends."
This reverts commit 4efa097, because some the compilers used for some bots do not support automatic conversions to PointerUnion.
1 parent 4efa097 commit 437f0bb

File tree

3 files changed

+21
-96
lines changed

3 files changed

+21
-96
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8249,24 +8249,15 @@ VPRecipeBuilder::tryToOptimizeInductionTruncate(TruncInst *I, VFRange &Range,
82498249
return nullptr;
82508250
}
82518251

8252-
VPRecipeOrVPValueTy VPRecipeBuilder::tryToBlend(PHINode *Phi, VPlanPtr &Plan) {
8253-
// If all incoming values are equal, the incoming VPValue can be used directly
8254-
// instead of creating a new VPBlendRecipe.
8255-
Value *FirstIncoming = Phi->getIncomingValue(0);
8256-
if (all_of(Phi->incoming_values(), [FirstIncoming](const Value *Inc) {
8257-
return FirstIncoming == Inc;
8258-
})) {
8259-
return Plan->getOrAddVPValue(Phi->getIncomingValue(0));
8260-
}
8261-
8252+
VPBlendRecipe *VPRecipeBuilder::tryToBlend(PHINode *Phi, VPlanPtr &Plan) {
82628253
// We know that all PHIs in non-header blocks are converted into selects, so
82638254
// we don't have to worry about the insertion order and we can just use the
82648255
// builder. At this point we generate the predication tree. There may be
82658256
// duplications since this is a simple recursive scan, but future
82668257
// optimizations will clean it up.
8258+
82678259
SmallVector<VPValue *, 2> Operands;
82688260
unsigned NumIncoming = Phi->getNumIncomingValues();
8269-
82708261
for (unsigned In = 0; In < NumIncoming; In++) {
82718262
VPValue *EdgeMask =
82728263
createEdgeMask(Phi->getIncomingBlock(In), Phi->getParent(), Plan);
@@ -8458,9 +8449,9 @@ VPRegionBlock *VPRecipeBuilder::createReplicateRegion(Instruction *Instr,
84588449
return Region;
84598450
}
84608451

8461-
VPRecipeOrVPValueTy VPRecipeBuilder::tryToCreateWidenRecipe(Instruction *Instr,
8462-
VFRange &Range,
8463-
VPlanPtr &Plan) {
8452+
VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(Instruction *Instr,
8453+
VFRange &Range,
8454+
VPlanPtr &Plan) {
84648455
// First, check for specific widening recipes that deal with calls, memory
84658456
// operations, inductions and Phi nodes.
84668457
if (auto *CI = dyn_cast<CallInst>(Instr))
@@ -8632,15 +8623,17 @@ VPlanPtr LoopVectorizationPlanner::buildVPlanWithVPRecipes(
86328623
if (isa<BranchInst>(Instr) || DeadInstructions.count(Instr))
86338624
continue;
86348625

8635-
if (auto RecipeOrValue =
8626+
if (auto Recipe =
86368627
RecipeBuilder.tryToCreateWidenRecipe(Instr, Range, Plan)) {
8637-
// If Instr can be simplified to an existing VPValue, use it.
8638-
if (RecipeOrValue.is<VPValue *>()) {
8639-
Plan->addVPValue(Instr, RecipeOrValue.get<VPValue *>());
8628+
8629+
// VPBlendRecipes with a single incoming (value, mask) pair are no-ops.
8630+
// Use the incoming value directly.
8631+
if (isa<VPBlendRecipe>(Recipe) && Recipe->getNumOperands() <= 2) {
8632+
Plan->removeVPValueFor(Instr);
8633+
Plan->addVPValue(Instr, Recipe->getOperand(0));
8634+
delete Recipe;
86408635
continue;
86418636
}
8642-
// Otherwise, add the new recipe.
8643-
VPRecipeBase *Recipe = RecipeOrValue.get<VPRecipeBase *>();
86448637
for (auto *Def : Recipe->definedValues()) {
86458638
auto *UV = Def->getUnderlyingValue();
86468639
Plan->addVPValue(UV, Def);

llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "LoopVectorizationPlanner.h"
1313
#include "VPlan.h"
1414
#include "llvm/ADT/DenseMap.h"
15-
#include "llvm/ADT/PointerUnion.h"
1615
#include "llvm/IR/IRBuilder.h"
1716

1817
namespace llvm {
@@ -21,8 +20,6 @@ class LoopVectorizationLegality;
2120
class LoopVectorizationCostModel;
2221
class TargetLibraryInfo;
2322

24-
using VPRecipeOrVPValueTy = PointerUnion<VPRecipeBase *, VPValue *>;
25-
2623
/// Helper class to create VPRecipies from IR instructions.
2724
class VPRecipeBuilder {
2825
/// The loop that we evaluate.
@@ -78,11 +75,10 @@ class VPRecipeBuilder {
7875
tryToOptimizeInductionTruncate(TruncInst *I, VFRange &Range,
7976
VPlan &Plan) const;
8077

81-
/// Handle non-loop phi nodes. Return a VPValue, if all incoming values match
82-
/// or a new VPBlendRecipe otherwise. Currently all such phi nodes are turned
83-
/// into a sequence of select instructions as the vectorizer currently
84-
/// performs full if-conversion.
85-
VPRecipeOrVPValueTy tryToBlend(PHINode *Phi, VPlanPtr &Plan);
78+
/// Handle non-loop phi nodes. Currently all such phi nodes are turned into
79+
/// a sequence of select instructions as the vectorizer currently performs
80+
/// full if-conversion.
81+
VPBlendRecipe *tryToBlend(PHINode *Phi, VPlanPtr &Plan);
8682

8783
/// Handle call instructions. If \p CI can be widened for \p Range.Start,
8884
/// return a new VPWidenCallRecipe. Range.End may be decreased to ensure same
@@ -103,12 +99,10 @@ class VPRecipeBuilder {
10399
: OrigLoop(OrigLoop), TLI(TLI), Legal(Legal), CM(CM), PSE(PSE),
104100
Builder(Builder) {}
105101

106-
/// Check if an existing VPValue can be used for \p Instr or a recipe can be
107-
/// create for \p I withing the given VF \p Range. If an existing VPValue can
108-
/// be used or if a recipe can be created, return it. Otherwise return a
109-
/// VPRecipeOrVPValueTy with nullptr.
110-
VPRecipeOrVPValueTy tryToCreateWidenRecipe(Instruction *Instr, VFRange &Range,
111-
VPlanPtr &Plan);
102+
/// Check if a recipe can be create for \p I withing the given VF \p Range.
103+
/// If a recipe can be created, return it. Otherwise return nullptr.
104+
VPRecipeBase *tryToCreateWidenRecipe(Instruction *Instr, VFRange &Range,
105+
VPlanPtr &Plan);
112106

113107
/// Set the recipe created for given ingredient. This operation is a no-op for
114108
/// ingredients that were not marked using a nullptr entry in the map.

llvm/test/Transforms/LoopVectorize/single-value-blend-phis.ll

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -382,65 +382,3 @@ loop.latch:
382382
exit:
383383
ret void
384384
}
385-
386-
; Test case for PR44800.
387-
define void @duplicated_incoming_blocks_blend(i32 %x, i32* %ptr) {
388-
; CHECK-LABEL: @duplicated_incoming_blocks_blend(
389-
; CHECK-NEXT: entry:
390-
; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
391-
; CHECK: vector.ph:
392-
; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <2 x i32> poison, i32 [[X:%.*]], i32 0
393-
; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <2 x i32> [[BROADCAST_SPLATINSERT]], <2 x i32> poison, <2 x i32> zeroinitializer
394-
; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
395-
; CHECK: vector.body:
396-
; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
397-
; CHECK-NEXT: [[VEC_IND:%.*]] = phi <2 x i32> [ <i32 0, i32 1>, [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
398-
; CHECK-NEXT: [[TMP0:%.*]] = icmp ugt <2 x i32> [[VEC_IND]], [[BROADCAST_SPLAT]]
399-
; CHECK-NEXT: [[TMP1:%.*]] = extractelement <2 x i32> [[VEC_IND]], i32 0
400-
; CHECK-NEXT: [[TMP2:%.*]] = getelementptr i32, i32* [[PTR:%.*]], i32 [[TMP1]]
401-
; CHECK-NEXT: [[TMP3:%.*]] = getelementptr i32, i32* [[TMP2]], i32 0
402-
; CHECK-NEXT: [[TMP4:%.*]] = bitcast i32* [[TMP3]] to <2 x i32>*
403-
; CHECK-NEXT: store <2 x i32> [[VEC_IND]], <2 x i32>* [[TMP4]], align 4
404-
; CHECK-NEXT: [[INDEX_NEXT]] = add i32 [[INDEX]], 2
405-
; CHECK-NEXT: [[VEC_IND_NEXT]] = add <2 x i32> [[VEC_IND]], <i32 2, i32 2>
406-
; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i32 [[INDEX_NEXT]], 1000
407-
; CHECK-NEXT: br i1 [[TMP5]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], [[LOOP10:!llvm.loop !.*]]
408-
; CHECK: middle.block:
409-
; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i32 1000, 1000
410-
; CHECK-NEXT: br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
411-
; CHECK: scalar.ph:
412-
; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ 1000, [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
413-
; CHECK-NEXT: br label [[LOOP_HEADER:%.*]]
414-
; CHECK: loop.header:
415-
; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[ADD_I:%.*]], [[LOOP_LATCH:%.*]] ]
416-
; CHECK-NEXT: [[C_0:%.*]] = icmp ugt i32 [[IV]], [[X]]
417-
; CHECK-NEXT: br i1 [[C_0]], label [[LOOP_LATCH]], label [[LOOP_LATCH]]
418-
; CHECK: loop.latch:
419-
; CHECK-NEXT: [[P:%.*]] = phi i32 [ [[IV]], [[LOOP_HEADER]] ], [ [[IV]], [[LOOP_HEADER]] ]
420-
; CHECK-NEXT: [[GEP_PTR:%.*]] = getelementptr i32, i32* [[PTR]], i32 [[P]]
421-
; CHECK-NEXT: store i32 [[P]], i32* [[GEP_PTR]], align 4
422-
; CHECK-NEXT: [[ADD_I]] = add nsw i32 [[P]], 1
423-
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[ADD_I]], 1000
424-
; CHECK-NEXT: br i1 [[CMP]], label [[LOOP_HEADER]], label [[EXIT]], [[LOOP11:!llvm.loop !.*]]
425-
; CHECK: exit:
426-
; CHECK-NEXT: ret void
427-
;
428-
entry:
429-
br label %loop.header
430-
431-
loop.header:
432-
%iv = phi i32 [ 0 , %entry ], [ %add.i, %loop.latch ]
433-
%c.0 = icmp ugt i32 %iv, %x
434-
br i1 %c.0, label %loop.latch, label %loop.latch
435-
436-
loop.latch:
437-
%p = phi i32 [ %iv, %loop.header ], [ %iv, %loop.header ]
438-
%gep.ptr = getelementptr i32, i32* %ptr, i32 %p
439-
store i32 %p, i32* %gep.ptr
440-
%add.i = add nsw i32 %p, 1
441-
%cmp = icmp slt i32 %add.i, 1000
442-
br i1 %cmp, label %loop.header, label %exit
443-
444-
exit:
445-
ret void
446-
}

0 commit comments

Comments
 (0)