Skip to content

Commit 727c02a

Browse files
committed
fixup! Setting the metadata outside the LoopVectorizeHints
And use the string value to represent tail-folding style (again).
1 parent 7349924 commit 727c02a

13 files changed

+30
-75
lines changed

llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ class LoopVectorizeHints {
6464
HK_FORCE,
6565
HK_ISVECTORIZED,
6666
HK_PREDICATE,
67-
HK_SCALABLE,
68-
HK_TAILFOLDING
67+
HK_SCALABLE
6968
};
7069

7170
/// Hint - associates name and validation with the hint value.
@@ -92,9 +91,6 @@ class LoopVectorizeHints {
9291
/// Already Vectorized
9392
Hint IsVectorized;
9493

95-
/// Tail folding style of a vectorized loop.
96-
Hint TailFoldingStyle;
97-
9894
/// Vector Predicate
9995
Hint Predicate;
10096

@@ -125,12 +121,6 @@ class LoopVectorizeHints {
125121
SK_PreferScalable = 1
126122
};
127123

128-
enum TailFoldingKind {
129-
TFK_Unspecified = -1,
130-
/// Tail folding with explicit vector length intrinsics.
131-
TFK_EVL = 0
132-
};
133-
134124
LoopVectorizeHints(const Loop *L, bool InterleaveOnlyWhenForced,
135125
OptimizationRemarkEmitter &ORE,
136126
const TargetTransformInfo *TTI = nullptr);
@@ -141,10 +131,6 @@ class LoopVectorizeHints {
141131
bool allowVectorization(Function *F, Loop *L,
142132
bool VectorizeOnlyWhenForced) const;
143133

144-
/// Mark the loop as being vectorized with a specific tail folding style.
145-
void setVectorizedTailFoldingStyle(TailFoldingKind Kind);
146-
void setEVLVectorized() { setVectorizedTailFoldingStyle(TFK_EVL); }
147-
148134
/// Dumps all the hint information.
149135
void emitRemarkWithHints() const;
150136

@@ -176,14 +162,6 @@ class LoopVectorizeHints {
176162
return (ScalableForceKind)Scalable.Value == SK_FixedWidthOnly;
177163
}
178164

179-
/// \return the tail folding style of a vectorized loop.
180-
TailFoldingKind getVectorizedTailFoldingStyle() const {
181-
return (TailFoldingKind)TailFoldingStyle.Value;
182-
}
183-
bool isEVLVectorized() const {
184-
return getVectorizedTailFoldingStyle() == TFK_EVL;
185-
}
186-
187165
/// If hints are provided that force vectorization, use the AlwaysPrint
188166
/// pass name to force the frontend to print the diagnostic.
189167
const char *vectorizeAnalysisPassName() const;

llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ bool LoopVectorizeHints::Hint::validate(unsigned Val) {
9494
return isPowerOf2_32(Val) && Val <= MaxInterleaveFactor;
9595
case HK_FORCE:
9696
return (Val <= 1);
97-
case HK_TAILFOLDING:
98-
return Val == 0;
9997
case HK_ISVECTORIZED:
10098
case HK_PREDICATE:
10199
case HK_SCALABLE:
@@ -112,8 +110,6 @@ LoopVectorizeHints::LoopVectorizeHints(const Loop *L,
112110
Interleave("interleave.count", InterleaveOnlyWhenForced, HK_INTERLEAVE),
113111
Force("vectorize.enable", FK_Undefined, HK_FORCE),
114112
IsVectorized("isvectorized", 0, HK_ISVECTORIZED),
115-
TailFoldingStyle("isvectorized.tailfoldingstyle", TFK_Unspecified,
116-
HK_TAILFOLDING),
117113
Predicate("vectorize.predicate.enable", FK_Undefined, HK_PREDICATE),
118114
Scalable("vectorize.scalable.enable", SK_Unspecified, HK_SCALABLE),
119115
TheLoop(L), ORE(ORE) {
@@ -158,14 +154,6 @@ LoopVectorizeHints::LoopVectorizeHints(const Loop *L,
158154
// nothing more that we can do.
159155
IsVectorized.Value =
160156
getWidth() == ElementCount::getFixed(1) && getInterleave() == 1;
161-
162-
if ((LoopVectorizeHints::TailFoldingKind)TailFoldingStyle.Value !=
163-
TFK_Unspecified &&
164-
!IsVectorized.Value)
165-
// If the loop is not vectorized, do not attach the tail folding style
166-
// metadata.
167-
TailFoldingStyle.Value = TFK_Unspecified;
168-
169157
LLVM_DEBUG(if (InterleaveOnlyWhenForced && getInterleave() == 1) dbgs()
170158
<< "LV: Interleaving disabled by the pass manager\n");
171159
}
@@ -189,24 +177,6 @@ void LoopVectorizeHints::setAlreadyVectorized() {
189177
IsVectorized.Value = 1;
190178
}
191179

192-
void LoopVectorizeHints::setVectorizedTailFoldingStyle(TailFoldingKind Kind) {
193-
if (Kind == TFK_Unspecified)
194-
return;
195-
196-
LLVMContext &Context = TheLoop->getHeader()->getContext();
197-
MDNode *TailFoldingMD = MDNode::get(
198-
Context,
199-
{MDString::get(Context, "llvm.loop.isvectorized.tailfoldingstyle"),
200-
ConstantAsMetadata::get(ConstantInt::get(Context, APInt(32, Kind)))});
201-
MDNode *LoopID = TheLoop->getLoopID();
202-
MDNode *NewLoopID =
203-
makePostTransformationMetadata(Context, LoopID, {}, {TailFoldingMD});
204-
TheLoop->setLoopID(NewLoopID);
205-
206-
// Update internal cache.
207-
TailFoldingStyle.Value = Kind;
208-
}
209-
210180
bool LoopVectorizeHints::allowVectorization(
211181
Function *F, Loop *L, bool VectorizeOnlyWhenForced) const {
212182
if (getForce() == LoopVectorizeHints::FK_Disabled) {
@@ -330,9 +300,8 @@ void LoopVectorizeHints::setHint(StringRef Name, Metadata *Arg) {
330300
return;
331301
unsigned Val = C->getZExtValue();
332302

333-
Hint *Hints[] = {&Width, &Interleave, &Force,
334-
&IsVectorized, &TailFoldingStyle, &Predicate,
335-
&Scalable};
303+
Hint *Hints[] = {&Width, &Interleave, &Force,
304+
&IsVectorized, &Predicate, &Scalable};
336305
for (auto *H : Hints) {
337306
if (Name == H->Name) {
338307
if (H->validate(Val))

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7830,16 +7830,24 @@ DenseMap<const SCEV *, Value *> LoopVectorizationPlanner::executePlan(
78307830
Hints.setAlreadyVectorized();
78317831

78327832
// Check if it's EVL-vectorized and mark the corresponding metadata.
7833-
// Note that we could have done this during the codegen of
7834-
// ExplictVectorLength, but the enclosing vector loop was not in a good
7835-
// shape for us to attach the metadata.
7836-
if (any_of(*HeaderVPBB, [](const VPRecipeBase &Recipe) {
7833+
bool IsEVLVectorized =
7834+
llvm::any_of(*HeaderVPBB, [](const VPRecipeBase &Recipe) {
78377835
// Looking for the ExplictVectorLength VPInstruction.
78387836
if (const auto *VI = dyn_cast<VPInstruction>(&Recipe))
78397837
return VI->getOpcode() == VPInstruction::ExplicitVectorLength;
78407838
return false;
7841-
}))
7842-
Hints.setEVLVectorized();
7839+
});
7840+
if (IsEVLVectorized) {
7841+
LLVMContext &Context = L->getHeader()->getContext();
7842+
MDNode *LoopID = L->getLoopID();
7843+
auto *IsEVLVectorizedMD = MDNode::get(
7844+
Context,
7845+
{MDString::get(Context, "llvm.loop.isvectorized.tailfoldingstyle"),
7846+
MDString::get(Context, "evl")});
7847+
MDNode *NewLoopID = makePostTransformationMetadata(Context, LoopID, {},
7848+
{IsEVLVectorizedMD});
7849+
L->setLoopID(NewLoopID);
7850+
}
78437851
}
78447852
TargetTransformInfo::UnrollingPreferences UP;
78457853
TTI.getUnrollingPreferences(L, *PSE.getSE(), UP, ORE);

llvm/test/Transforms/LoopVectorize/RISCV/truncate-to-minimal-bitwidth-evl-crash.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ define void @truncate_to_minimal_bitwidths_widen_cast_recipe(ptr %src) {
5454
; CHECK-NEXT: store i8 [[CONV36]], ptr null, align 1
5555
; CHECK-NEXT: [[IV_NEXT]] = add i64 [[IV1]], 1
5656
; CHECK-NEXT: [[EC:%.*]] = icmp eq i64 [[IV1]], 8
57-
; CHECK-NEXT: br i1 [[EC]], label %[[EXIT]], label %[[LOOP]], !llvm.loop [[LOOP3:![0-9]+]]
57+
; CHECK-NEXT: br i1 [[EC]], label %[[EXIT]], label %[[LOOP]], !llvm.loop [[LOOP4:![0-9]+]]
5858
; CHECK: [[EXIT]]:
5959
; CHECK-NEXT: ret void
6060
;
@@ -80,7 +80,7 @@ exit: ; preds = %loop
8080
;.
8181
; CHECK: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]], [[META2:![0-9]+]], [[META3:![0-9]+]]}
8282
; CHECK: [[META1]] = !{!"llvm.loop.isvectorized", i32 1}
83-
; CHECK: [[META2]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", i32 0}
83+
; CHECK: [[META2]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", !"evl"}
8484
; CHECK: [[META3]] = !{!"llvm.loop.unroll.runtime.disable"}
8585
; CHECK: [[LOOP4]] = distinct !{[[LOOP4]], [[META3]], [[META1]]}
8686
;.

llvm/test/Transforms/LoopVectorize/RISCV/type-info-cache-evl-crash.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ exit:
115115
; CHECK: [[META4]] = distinct !{[[META4]], [[META2]]}
116116
; CHECK: [[LOOP5]] = distinct !{[[LOOP5]], [[META6:![0-9]+]], [[META7:![0-9]+]], [[META8:![0-9]+]]}
117117
; CHECK: [[META6]] = !{!"llvm.loop.isvectorized", i32 1}
118-
; CHECK: [[META7]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", i32 0}
118+
; CHECK: [[META7]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", !"evl"}
119119
; CHECK: [[META8]] = !{!"llvm.loop.unroll.runtime.disable"}
120120
; CHECK: [[LOOP9]] = distinct !{[[LOOP9]], [[META6]]}
121121
;.

llvm/test/Transforms/LoopVectorize/RISCV/vectorize-force-tail-with-evl-bin-unary-ops-args.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1746,7 +1746,7 @@ finish.loopexit:
17461746
;.
17471747
; IF-EVL: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]], [[META2:![0-9]+]], [[META3:![0-9]+]]}
17481748
; IF-EVL: [[META1]] = !{!"llvm.loop.isvectorized", i32 1}
1749-
; IF-EVL: [[META2]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", i32 0}
1749+
; IF-EVL: [[META2]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", !"evl"}
17501750
; IF-EVL: [[META3]] = !{!"llvm.loop.unroll.runtime.disable"}
17511751
; IF-EVL: [[LOOP4]] = distinct !{[[LOOP4]], [[META1]]}
17521752
; IF-EVL: [[LOOP5]] = distinct !{[[LOOP5]], [[META1]], [[META2]], [[META3]]}

llvm/test/Transforms/LoopVectorize/RISCV/vectorize-force-tail-with-evl-call-intrinsics.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ declare i32 @llvm.abs.i32(i32, i1 immarg)
10481048
;.
10491049
; IF-EVL: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]], [[META2:![0-9]+]], [[META3:![0-9]+]]}
10501050
; IF-EVL: [[META1]] = !{!"llvm.loop.isvectorized", i32 1}
1051-
; IF-EVL: [[META2]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", i32 0}
1051+
; IF-EVL: [[META2]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", !"evl"}
10521052
; IF-EVL: [[META3]] = !{!"llvm.loop.unroll.runtime.disable"}
10531053
; IF-EVL: [[LOOP4]] = distinct !{[[LOOP4]], [[META1]]}
10541054
; IF-EVL: [[LOOP5]] = distinct !{[[LOOP5]], [[META1]], [[META2]], [[META3]]}

llvm/test/Transforms/LoopVectorize/RISCV/vectorize-force-tail-with-evl-cast-intrinsics.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ exit:
10561056
; IF-EVL: [[META4]] = distinct !{[[META4]], [[META2]]}
10571057
; IF-EVL: [[LOOP5]] = distinct !{[[LOOP5]], [[META6:![0-9]+]], [[META7:![0-9]+]], [[META8:![0-9]+]]}
10581058
; IF-EVL: [[META6]] = !{!"llvm.loop.isvectorized", i32 1}
1059-
; IF-EVL: [[META7]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", i32 0}
1059+
; IF-EVL: [[META7]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", !"evl"}
10601060
; IF-EVL: [[META8]] = !{!"llvm.loop.unroll.runtime.disable"}
10611061
; IF-EVL: [[LOOP9]] = distinct !{[[LOOP9]], [[META6]]}
10621062
; IF-EVL: [[META10]] = !{[[META11:![0-9]+]]}

llvm/test/Transforms/LoopVectorize/RISCV/vectorize-force-tail-with-evl-cond-reduction.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ for.end:
928928
;.
929929
; IF-EVL-OUTLOOP: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]], [[META2:![0-9]+]], [[META3:![0-9]+]]}
930930
; IF-EVL-OUTLOOP: [[META1]] = !{!"llvm.loop.isvectorized", i32 1}
931-
; IF-EVL-OUTLOOP: [[META2]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", i32 0}
931+
; IF-EVL-OUTLOOP: [[META2]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", !"evl"}
932932
; IF-EVL-OUTLOOP: [[META3]] = !{!"llvm.loop.unroll.runtime.disable"}
933933
; IF-EVL-OUTLOOP: [[LOOP4]] = distinct !{[[LOOP4]], [[META3]], [[META1]]}
934934
; IF-EVL-OUTLOOP: [[LOOP5]] = distinct !{[[LOOP5]], [[META1]], [[META2]], [[META3]]}
@@ -938,7 +938,7 @@ for.end:
938938
;.
939939
; IF-EVL-INLOOP: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]], [[META2:![0-9]+]], [[META3:![0-9]+]]}
940940
; IF-EVL-INLOOP: [[META1]] = !{!"llvm.loop.isvectorized", i32 1}
941-
; IF-EVL-INLOOP: [[META2]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", i32 0}
941+
; IF-EVL-INLOOP: [[META2]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", !"evl"}
942942
; IF-EVL-INLOOP: [[META3]] = !{!"llvm.loop.unroll.runtime.disable"}
943943
; IF-EVL-INLOOP: [[LOOP4]] = distinct !{[[LOOP4]], [[META3]], [[META1]]}
944944
; IF-EVL-INLOOP: [[LOOP5]] = distinct !{[[LOOP5]], [[META1]], [[META2]], [[META3]]}

llvm/test/Transforms/LoopVectorize/RISCV/vectorize-force-tail-with-evl-div.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ exit:
392392
;.
393393
; IF-EVL: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]], [[META2:![0-9]+]], [[META3:![0-9]+]]}
394394
; IF-EVL: [[META1]] = !{!"llvm.loop.isvectorized", i32 1}
395-
; IF-EVL: [[META2]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", i32 0}
395+
; IF-EVL: [[META2]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", !"evl"}
396396
; IF-EVL: [[META3]] = !{!"llvm.loop.unroll.runtime.disable"}
397397
; IF-EVL: [[LOOP4]] = distinct !{[[LOOP4]], [[META3]], [[META1]]}
398398
; IF-EVL: [[LOOP5]] = distinct !{[[LOOP5]], [[META1]], [[META2]], [[META3]]}

llvm/test/Transforms/LoopVectorize/RISCV/vectorize-force-tail-with-evl-fixed-order-recurrence.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ for.end:
633633
;.
634634
; IF-EVL: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]], [[META2:![0-9]+]], [[META3:![0-9]+]]}
635635
; IF-EVL: [[META1]] = !{!"llvm.loop.isvectorized", i32 1}
636-
; IF-EVL: [[META2]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", i32 0}
636+
; IF-EVL: [[META2]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", !"evl"}
637637
; IF-EVL: [[META3]] = !{!"llvm.loop.unroll.runtime.disable"}
638638
; IF-EVL: [[LOOP4]] = distinct !{[[LOOP4]], [[META3]], [[META1]]}
639639
; IF-EVL: [[LOOP5]] = distinct !{[[LOOP5]], [[META1]], [[META2]], [[META3]]}

llvm/test/Transforms/LoopVectorize/RISCV/vectorize-force-tail-with-evl-intermediate-store.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ for.end:
285285
; IF-EVL-OUTLOOP: [[META2]] = distinct !{[[META2]], !"LVerDomain"}
286286
; IF-EVL-OUTLOOP: [[LOOP3]] = distinct !{[[LOOP3]], [[META4:![0-9]+]], [[META5:![0-9]+]], [[META6:![0-9]+]]}
287287
; IF-EVL-OUTLOOP: [[META4]] = !{!"llvm.loop.isvectorized", i32 1}
288-
; IF-EVL-OUTLOOP: [[META5]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", i32 0}
288+
; IF-EVL-OUTLOOP: [[META5]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", !"evl"}
289289
; IF-EVL-OUTLOOP: [[META6]] = !{!"llvm.loop.unroll.runtime.disable"}
290290
; IF-EVL-OUTLOOP: [[META7]] = !{[[META8:![0-9]+]]}
291291
; IF-EVL-OUTLOOP: [[META8]] = distinct !{[[META8]], [[META2]]}
@@ -296,7 +296,7 @@ for.end:
296296
; IF-EVL-INLOOP: [[META2]] = distinct !{[[META2]], !"LVerDomain"}
297297
; IF-EVL-INLOOP: [[LOOP3]] = distinct !{[[LOOP3]], [[META4:![0-9]+]], [[META5:![0-9]+]], [[META6:![0-9]+]]}
298298
; IF-EVL-INLOOP: [[META4]] = !{!"llvm.loop.isvectorized", i32 1}
299-
; IF-EVL-INLOOP: [[META5]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", i32 0}
299+
; IF-EVL-INLOOP: [[META5]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", !"evl"}
300300
; IF-EVL-INLOOP: [[META6]] = !{!"llvm.loop.unroll.runtime.disable"}
301301
; IF-EVL-INLOOP: [[META7]] = !{[[META8:![0-9]+]]}
302302
; IF-EVL-INLOOP: [[META8]] = distinct !{[[META8]], [[META2]]}

llvm/test/Transforms/LoopVectorize/RISCV/vectorize-force-tail-with-evl-known-no-overflow.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ exit:
229229
;.
230230
; CHECK: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]], [[META2:![0-9]+]], [[META3:![0-9]+]]}
231231
; CHECK: [[META1]] = !{!"llvm.loop.isvectorized", i32 1}
232-
; CHECK: [[META2]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", i32 0}
232+
; CHECK: [[META2]] = !{!"llvm.loop.isvectorized.tailfoldingstyle", !"evl"}
233233
; CHECK: [[META3]] = !{!"llvm.loop.unroll.runtime.disable"}
234234
; CHECK: [[LOOP4]] = distinct !{[[LOOP4]], [[META3]], [[META1]]}
235235
; CHECK: [[LOOP5]] = distinct !{[[LOOP5]], [[META1]], [[META2]], [[META3]]}

0 commit comments

Comments
 (0)