Skip to content

Commit 7ad19f7

Browse files
committed
!fixup address latest comments, thanks
1 parent 980a939 commit 7ad19f7

File tree

5 files changed

+52
-60
lines changed

5 files changed

+52
-60
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8599,13 +8599,11 @@ VPRecipeBuilder::tryToWidenMemory(Instruction *I, ArrayRef<VPValue *> Operands,
85998599
}
86008600
if (LoadInst *Load = dyn_cast<LoadInst>(I))
86018601
return new VPWidenLoadRecipe(*Load, Ptr, Mask, Consecutive, Reverse,
8602-
getMetadataToPropagate(Load),
86038602
I->getDebugLoc());
86048603

86058604
StoreInst *Store = cast<StoreInst>(I);
86068605
return new VPWidenStoreRecipe(*Store, Ptr, Operands[0], Mask, Consecutive,
8607-
Reverse, getMetadataToPropagate(Store),
8608-
I->getDebugLoc());
8606+
Reverse, I->getDebugLoc());
86098607
}
86108608

86118609
/// Creates a VPWidenIntOrFpInductionRecpipe for \p Phi. If needed, it will also

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,10 +1199,11 @@ class VPIRMetadata {
11991199

12001200
protected:
12011201
VPIRMetadata(MDArrayRef Metadata) : Metadata(Metadata) {}
1202+
VPIRMetadata(Instruction &I) { getMetadataToPropagate(&I, Metadata); }
12021203

12031204
public:
1204-
/// Add all metadata to \p V if it is an instruction.
1205-
void applyMetadata(Value *V) const;
1205+
/// Add all metadata to \p I.
1206+
void applyMetadata(Instruction &I) const;
12061207

12071208
/// Return the IR metadata.
12081209
MDArrayRef getMetadata() const { return Metadata; }
@@ -1337,10 +1338,9 @@ class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
13371338

13381339
VPWidenIntrinsicRecipe(Intrinsic::ID VectorIntrinsicID,
13391340
ArrayRef<VPValue *> CallArguments, Type *Ty,
1340-
MDArrayRef Metadata, DebugLoc DL = {})
1341+
DebugLoc DL = {})
13411342
: VPRecipeWithIRFlags(VPDef::VPWidenIntrinsicSC, CallArguments, DL),
1342-
VPIRMetadata(Metadata), VectorIntrinsicID(VectorIntrinsicID),
1343-
ResultTy(Ty) {
1343+
VPIRMetadata({}), VectorIntrinsicID(VectorIntrinsicID), ResultTy(Ty) {
13441344
LLVMContext &Ctx = Ty->getContext();
13451345
AttributeSet Attrs = Intrinsic::getFnAttributes(Ctx, VectorIntrinsicID);
13461346
MemoryEffects ME = Attrs.getMemoryEffects();
@@ -2651,9 +2651,8 @@ class VPWidenMemoryRecipe : public VPRecipeBase, public VPIRMetadata {
26512651

26522652
VPWidenMemoryRecipe(const char unsigned SC, Instruction &I,
26532653
std::initializer_list<VPValue *> Operands,
2654-
bool Consecutive, bool Reverse, MDArrayRef Metadata,
2655-
DebugLoc DL)
2656-
: VPRecipeBase(SC, Operands, DL), VPIRMetadata(Metadata), Ingredient(I),
2654+
bool Consecutive, bool Reverse, DebugLoc DL)
2655+
: VPRecipeBase(SC, Operands, DL), VPIRMetadata(I), Ingredient(I),
26572656
Consecutive(Consecutive), Reverse(Reverse) {
26582657
assert((Consecutive || !Reverse) && "Reverse implies consecutive");
26592658
}
@@ -2711,18 +2710,17 @@ class VPWidenMemoryRecipe : public VPRecipeBase, public VPIRMetadata {
27112710
/// optional mask.
27122711
struct VPWidenLoadRecipe final : public VPWidenMemoryRecipe, public VPValue {
27132712
VPWidenLoadRecipe(LoadInst &Load, VPValue *Addr, VPValue *Mask,
2714-
bool Consecutive, bool Reverse, MDArrayRef Metadata,
2715-
DebugLoc DL)
2713+
bool Consecutive, bool Reverse, DebugLoc DL)
27162714
: VPWidenMemoryRecipe(VPDef::VPWidenLoadSC, Load, {Addr}, Consecutive,
2717-
Reverse, Metadata, DL),
2715+
Reverse, DL),
27182716
VPValue(this, &Load) {
27192717
setMask(Mask);
27202718
}
27212719

27222720
VPWidenLoadRecipe *clone() override {
2723-
auto *Copy = new VPWidenLoadRecipe(cast<LoadInst>(Ingredient), getAddr(),
2724-
getMask(), Consecutive, Reverse,
2725-
getMetadata(), getDebugLoc());
2721+
auto *Copy =
2722+
new VPWidenLoadRecipe(cast<LoadInst>(Ingredient), getAddr(), getMask(),
2723+
Consecutive, Reverse, getDebugLoc());
27262724
return Copy;
27272725
}
27282726

@@ -2754,7 +2752,7 @@ struct VPWidenLoadEVLRecipe final : public VPWidenMemoryRecipe, public VPValue {
27542752
VPWidenLoadEVLRecipe(VPWidenLoadRecipe &L, VPValue &EVL, VPValue *Mask)
27552753
: VPWidenMemoryRecipe(VPDef::VPWidenLoadEVLSC, L.getIngredient(),
27562754
{L.getAddr(), &EVL}, L.isConsecutive(),
2757-
L.isReverse(), L.getMetadata(), L.getDebugLoc()),
2755+
L.isReverse(), L.getDebugLoc()),
27582756
VPValue(this, &getIngredient()) {
27592757
setMask(Mask);
27602758
}
@@ -2791,17 +2789,16 @@ struct VPWidenLoadEVLRecipe final : public VPWidenMemoryRecipe, public VPValue {
27912789
/// to store to and an optional mask.
27922790
struct VPWidenStoreRecipe final : public VPWidenMemoryRecipe {
27932791
VPWidenStoreRecipe(StoreInst &Store, VPValue *Addr, VPValue *StoredVal,
2794-
VPValue *Mask, bool Consecutive, bool Reverse,
2795-
MDArrayRef Metadata, DebugLoc DL)
2792+
VPValue *Mask, bool Consecutive, bool Reverse, DebugLoc DL)
27962793
: VPWidenMemoryRecipe(VPDef::VPWidenStoreSC, Store, {Addr, StoredVal},
2797-
Consecutive, Reverse, Metadata, DL) {
2794+
Consecutive, Reverse, DL) {
27982795
setMask(Mask);
27992796
}
28002797

28012798
VPWidenStoreRecipe *clone() override {
2802-
auto *Copy = new VPWidenStoreRecipe(
2803-
cast<StoreInst>(Ingredient), getAddr(), getStoredValue(), getMask(),
2804-
Consecutive, Reverse, getMetadata(), getDebugLoc());
2799+
auto *Copy = new VPWidenStoreRecipe(cast<StoreInst>(Ingredient), getAddr(),
2800+
getStoredValue(), getMask(),
2801+
Consecutive, Reverse, getDebugLoc());
28052802
return Copy;
28062803
}
28072804

@@ -2836,8 +2833,7 @@ struct VPWidenStoreEVLRecipe final : public VPWidenMemoryRecipe {
28362833
VPWidenStoreEVLRecipe(VPWidenStoreRecipe &S, VPValue &EVL, VPValue *Mask)
28372834
: VPWidenMemoryRecipe(VPDef::VPWidenStoreEVLSC, S.getIngredient(),
28382835
{S.getAddr(), S.getStoredValue(), &EVL},
2839-
S.isConsecutive(), S.isReverse(), S.getMetadata(),
2840-
S.getDebugLoc()) {
2836+
S.isConsecutive(), S.isReverse(), S.getDebugLoc()) {
28412837
setMask(Mask);
28422838
}
28432839

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,12 +1204,9 @@ void VPIRPhi::print(raw_ostream &O, const Twine &Indent,
12041204
}
12051205
#endif
12061206

1207-
void VPIRMetadata::applyMetadata(Value *V) const {
1208-
auto *I = dyn_cast<Instruction>(V);
1209-
if (!I)
1210-
return;
1207+
void VPIRMetadata::applyMetadata(Instruction &I) const {
12111208
for (const auto &[Kind, Node] : Metadata)
1212-
I->setMetadata(Kind, Node);
1209+
I.setMetadata(Kind, Node);
12131210
}
12141211

12151212
void VPWidenCallRecipe::execute(VPTransformState &State) {
@@ -1239,7 +1236,7 @@ void VPWidenCallRecipe::execute(VPTransformState &State) {
12391236

12401237
CallInst *V = State.Builder.CreateCall(Variant, Args, OpBundles);
12411238
setFlags(V);
1242-
applyMetadata(V);
1239+
applyMetadata(*V);
12431240

12441241
if (!V->getType()->isVoidTy())
12451242
State.set(this, V);
@@ -1318,7 +1315,7 @@ void VPWidenIntrinsicRecipe::execute(VPTransformState &State) {
13181315
CallInst *V = State.Builder.CreateCall(VectorF, Args, OpBundles);
13191316

13201317
setFlags(V);
1321-
applyMetadata(V);
1318+
applyMetadata(*V);
13221319

13231320
if (!V->getType()->isVoidTy())
13241321
State.set(this, V);
@@ -1516,9 +1513,11 @@ void VPWidenSelectRecipe::execute(VPTransformState &State) {
15161513
Value *Op1 = State.get(getOperand(2));
15171514
Value *Sel = State.Builder.CreateSelect(Cond, Op0, Op1);
15181515
State.set(this, Sel);
1519-
if (isa<FPMathOperator>(Sel))
1520-
setFlags(cast<Instruction>(Sel));
1521-
applyMetadata(Sel);
1516+
if (auto *I = dyn_cast<Instruction>(Sel)) {
1517+
if (isa<FPMathOperator>(I))
1518+
setFlags(I);
1519+
applyMetadata(*I);
1520+
}
15221521
}
15231522

15241523
InstructionCost VPWidenSelectRecipe::computeCost(ElementCount VF,
@@ -1651,7 +1650,7 @@ void VPWidenRecipe::execute(VPTransformState &State) {
16511650

16521651
if (auto *VecOp = dyn_cast<Instruction>(V)) {
16531652
setFlags(VecOp);
1654-
applyMetadata(V);
1653+
applyMetadata(*VecOp);
16551654
}
16561655

16571656
// Use this vector value for all users of the original instruction.
@@ -1687,7 +1686,8 @@ void VPWidenRecipe::execute(VPTransformState &State) {
16871686
} else {
16881687
C = Builder.CreateICmp(getPredicate(), A, B);
16891688
}
1690-
applyMetadata(C);
1689+
if (auto *I = dyn_cast<Instruction>(C))
1690+
applyMetadata(*I);
16911691
State.set(this, C);
16921692
break;
16931693
}
@@ -1806,7 +1806,7 @@ void VPWidenCastRecipe::execute(VPTransformState &State) {
18061806
State.set(this, Cast);
18071807
if (auto *CastOp = dyn_cast<Instruction>(Cast)) {
18081808
setFlags(CastOp);
1809-
applyMetadata(CastOp);
1809+
applyMetadata(*CastOp);
18101810
}
18111811
}
18121812

@@ -2749,7 +2749,7 @@ void VPWidenLoadRecipe::execute(VPTransformState &State) {
27492749
}
27502750

27512751
Value *Addr = State.get(getAddr(), /*IsScalar*/ !CreateGather);
2752-
Value *NewLI;
2752+
Instruction *NewLI;
27532753
if (CreateGather) {
27542754
NewLI = Builder.CreateMaskedGather(DataTy, Addr, Alignment, Mask, nullptr,
27552755
"wide.masked.gather");
@@ -2762,10 +2762,9 @@ void VPWidenLoadRecipe::execute(VPTransformState &State) {
27622762
}
27632763
// Add metadata to the load, but setVectorValue to the reverse shuffle.
27642764
State.addNewMetadata(NewLI, LI);
2765-
applyMetadata(NewLI);
2766-
if (Reverse)
2767-
NewLI = Builder.CreateVectorReverse(NewLI, "reverse");
2768-
State.set(this, NewLI);
2765+
applyMetadata(*NewLI);
2766+
State.set(this,
2767+
Reverse ? Builder.CreateVectorReverse(NewLI, "reverse") : NewLI);
27692768
}
27702769

27712770
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
@@ -2823,7 +2822,7 @@ void VPWidenLoadEVLRecipe::execute(VPTransformState &State) {
28232822
NewLI->addParamAttr(
28242823
0, Attribute::getWithAlignment(NewLI->getContext(), Alignment));
28252824
State.addNewMetadata(NewLI, LI);
2826-
applyMetadata(NewLI);
2825+
applyMetadata(*NewLI);
28272826
Instruction *Res = NewLI;
28282827
if (isReverse())
28292828
Res = createReverseEVL(Builder, Res, EVL, "vp.reverse");
@@ -2900,7 +2899,7 @@ void VPWidenStoreRecipe::execute(VPTransformState &State) {
29002899
else
29012900
NewSI = Builder.CreateAlignedStore(StoredVal, Addr, Alignment);
29022901
State.addNewMetadata(NewSI, SI);
2903-
applyMetadata(NewSI);
2902+
applyMetadata(*NewSI);
29042903
}
29052904

29062905
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
@@ -2948,7 +2947,7 @@ void VPWidenStoreEVLRecipe::execute(VPTransformState &State) {
29482947
NewSI->addParamAttr(
29492948
1, Attribute::getWithAlignment(NewSI->getContext(), Alignment));
29502949
State.addNewMetadata(NewSI, SI);
2951-
applyMetadata(NewSI);
2950+
applyMetadata(*NewSI);
29522951
}
29532952

29542953
InstructionCost VPWidenStoreEVLRecipe::computeCost(ElementCount VF,

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ bool VPlanTransforms::tryToConvertVPInstructionsToVPRecipes(
7878
if (LoadInst *Load = dyn_cast<LoadInst>(Inst)) {
7979
NewRecipe = new VPWidenLoadRecipe(
8080
*Load, Ingredient.getOperand(0), nullptr /*Mask*/,
81-
false /*Consecutive*/, false /*Reverse*/, Metadata,
81+
false /*Consecutive*/, false /*Reverse*/,
8282
Ingredient.getDebugLoc());
8383
} else if (StoreInst *Store = dyn_cast<StoreInst>(Inst)) {
8484
NewRecipe = new VPWidenStoreRecipe(
8585
*Store, Ingredient.getOperand(1), Ingredient.getOperand(0),
8686
nullptr /*Mask*/, false /*Consecutive*/, false /*Reverse*/,
87-
Metadata, Ingredient.getDebugLoc());
87+
Ingredient.getDebugLoc());
8888
} else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Inst)) {
8989
NewRecipe = new VPWidenGEPRecipe(GEP, Ingredient.operands());
9090
} else if (CallInst *CI = dyn_cast<CallInst>(Inst)) {
@@ -2012,9 +2012,9 @@ static VPRecipeBase *createEVLRecipe(VPValue *HeaderMask,
20122012
.Case<VPWidenSelectRecipe>([&](VPWidenSelectRecipe *Sel) {
20132013
SmallVector<VPValue *> Ops(Sel->operands());
20142014
Ops.push_back(&EVL);
2015-
return new VPWidenIntrinsicRecipe(
2016-
Intrinsic::vp_select, Ops, TypeInfo.inferScalarType(Sel),
2017-
Sel->getMetadata(), Sel->getDebugLoc());
2015+
return new VPWidenIntrinsicRecipe(Intrinsic::vp_select, Ops,
2016+
TypeInfo.inferScalarType(Sel),
2017+
Sel->getDebugLoc());
20182018
})
20192019
.Case<VPInstruction>([&](VPInstruction *VPI) -> VPRecipeBase * {
20202020
if (VPI->getOpcode() == VPInstruction::FirstOrderRecurrenceSplice) {
@@ -2026,7 +2026,7 @@ static VPRecipeBase *createEVLRecipe(VPValue *HeaderMask,
20262026
Ops.append({MinusOneVPV, &AllOneMask, PrevEVL, &EVL});
20272027
return new VPWidenIntrinsicRecipe(Intrinsic::experimental_vp_splice,
20282028
Ops, TypeInfo.inferScalarType(VPI),
2029-
{}, VPI->getDebugLoc());
2029+
VPI->getDebugLoc());
20302030
}
20312031

20322032
VPValue *LHS, *RHS;
@@ -2041,7 +2041,7 @@ static VPRecipeBase *createEVLRecipe(VPValue *HeaderMask,
20412041
// limited to selects whose condition is a header mask.
20422042
return new VPWidenIntrinsicRecipe(
20432043
Intrinsic::vp_merge, {&AllOneMask, LHS, RHS, &EVL},
2044-
TypeInfo.inferScalarType(LHS), {}, VPI->getDebugLoc());
2044+
TypeInfo.inferScalarType(LHS), VPI->getDebugLoc());
20452045
})
20462046
.Default([&](VPRecipeBase *R) { return nullptr; });
20472047
}
@@ -2758,7 +2758,7 @@ void VPlanTransforms::narrowInterleaveGroups(VPlan &Plan, ElementCount VF,
27582758
auto *L = new VPWidenLoadRecipe(
27592759
*cast<LoadInst>(LoadGroup->getInterleaveGroup()->getInsertPos()),
27602760
LoadGroup->getAddr(), LoadGroup->getMask(), /*Consecutive=*/true,
2761-
/*Reverse=*/false, {}, LoadGroup->getDebugLoc());
2761+
/*Reverse=*/false, LoadGroup->getDebugLoc());
27622762
L->insertBefore(LoadGroup);
27632763
return L;
27642764
}
@@ -2789,7 +2789,7 @@ void VPlanTransforms::narrowInterleaveGroups(VPlan &Plan, ElementCount VF,
27892789
auto *S = new VPWidenStoreRecipe(
27902790
*cast<StoreInst>(StoreGroup->getInterleaveGroup()->getInsertPos()),
27912791
StoreGroup->getAddr(), Res, nullptr, /*Consecutive=*/true,
2792-
/*Reverse=*/false, {}, StoreGroup->getDebugLoc());
2792+
/*Reverse=*/false, StoreGroup->getDebugLoc());
27932793
S->insertBefore(StoreGroup);
27942794
StoreGroup->eraseFromParent();
27952795
}

llvm/unittests/Transforms/Vectorize/VPlanTest.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ TEST_F(VPRecipeTest, CastVPWidenMemoryRecipeToVPUserAndVPDef) {
10841084
new LoadInst(Int32, PoisonValue::get(Int32Ptr), "", false, Align(1));
10851085
VPValue *Addr = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
10861086
VPValue *Mask = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
1087-
VPWidenLoadRecipe Recipe(*Load, Addr, Mask, true, false, {}, {});
1087+
VPWidenLoadRecipe Recipe(*Load, Addr, Mask, true, false, {});
10881088
EXPECT_TRUE(isa<VPUser>(&Recipe));
10891089
VPRecipeBase *BaseR = &Recipe;
10901090
EXPECT_TRUE(isa<VPUser>(BaseR));
@@ -1202,7 +1202,7 @@ TEST_F(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
12021202
new LoadInst(Int32, PoisonValue::get(Int32Ptr), "", false, Align(1));
12031203
VPValue *Mask = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
12041204
VPValue *Addr = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
1205-
VPWidenLoadRecipe Recipe(*Load, Addr, Mask, true, false, {}, {});
1205+
VPWidenLoadRecipe Recipe(*Load, Addr, Mask, true, false, {});
12061206
EXPECT_FALSE(Recipe.mayHaveSideEffects());
12071207
EXPECT_TRUE(Recipe.mayReadFromMemory());
12081208
EXPECT_FALSE(Recipe.mayWriteToMemory());
@@ -1216,8 +1216,7 @@ TEST_F(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
12161216
VPValue *Mask = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
12171217
VPValue *Addr = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
12181218
VPValue *StoredV = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 3));
1219-
VPWidenStoreRecipe Recipe(*Store, Addr, StoredV, Mask, false, false, {},
1220-
{});
1219+
VPWidenStoreRecipe Recipe(*Store, Addr, StoredV, Mask, false, false, {});
12211220
EXPECT_TRUE(Recipe.mayHaveSideEffects());
12221221
EXPECT_FALSE(Recipe.mayReadFromMemory());
12231222
EXPECT_TRUE(Recipe.mayWriteToMemory());

0 commit comments

Comments
 (0)