Skip to content

Commit 0053b2a

Browse files
committed
[LV][EVL] Adrress the comments
rebase and update testcase
1 parent 0f1be97 commit 0053b2a

File tree

2 files changed

+32
-72
lines changed

2 files changed

+32
-72
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,10 +1167,7 @@ void VPWidenSelectRecipe::execute(VPTransformState &State) {
11671167

11681168
void VPWidenSelectEVLRecipe::execute(VPTransformState &State) {
11691169
State.setDebugLocFrom(getDebugLoc());
1170-
assert(State.UF == 1 && "Expected only UF == 1 when vectorizing with "
1171-
"explicit vector length.");
1172-
1173-
Value *EVLArg = State.get(getEVL(), 0, /*NeedsScalar=*/true);
1170+
Value *EVLArg = State.get(getEVL(), /*NeedsScalar=*/true);
11741171
IRBuilderBase &BuilderIR = State.Builder;
11751172
VectorBuilder Builder(BuilderIR);
11761173
Builder.setEVL(EVLArg);
@@ -1179,11 +1176,10 @@ void VPWidenSelectEVLRecipe::execute(VPTransformState &State) {
11791176
// We have to take the 'vectorized' value and pick the first lane.
11801177
// Instcombine will make this a no-op.
11811178
auto *InvarCond =
1182-
isInvariantCond() ? State.get(getCond(), VPIteration(0, 0)) : nullptr;
1179+
isInvariantCond() ? State.get(getCond(), VPLane(0)) : nullptr;
11831180

11841181
Value *Cond = InvarCond ? InvarCond : State.get(getCond(), 0);
1185-
if (!isa<VectorType>(Cond->getType()))
1186-
Cond = BuilderIR.CreateVectorSplat(State.VF, Cond, "splat.cond");
1182+
assert(isa<VectorType>(Cond->getType()) && "CondType must be vector Type.");
11871183

11881184
Value *Op0 = State.get(getOperand(1), 0);
11891185
Value *Op1 = State.get(getOperand(2), 0);

llvm/test/Transforms/LoopVectorize/RISCV/vplan-vp-select-intrinsics.ll

Lines changed: 29 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -5,83 +5,44 @@
55
; RUN: -prefer-predicate-over-epilogue=predicate-dont-vectorize \
66
; RUN: -mtriple=riscv64 -mattr=+v -riscv-v-vector-bits-max=128 -disable-output < %s 2>&1 | FileCheck --check-prefix=IF-EVL %s
77

8-
; RUN: opt -passes=loop-vectorize -debug-only=loop-vectorize \
9-
; RUN: -force-tail-folding-style=none \
10-
; RUN: -prefer-predicate-over-epilogue=predicate-else-scalar-epilogue \
11-
; RUN: -mtriple=riscv64 -mattr=+v -riscv-v-vector-bits-max=128 -disable-output < %s 2>&1 | FileCheck --check-prefix=NO-VP %s
12-
138
define void @vp_select(ptr noalias %a, ptr noalias %b, ptr noalias %c, i64 %N) {
149
; IF-EVL: VPlan 'Final VPlan for VF={vscale x 1,vscale x 2,vscale x 4},UF={1}' {
15-
; IF-EVL-NEXT: Live-in vp<%0> = VF * UF
16-
; IF-EVL-NEXT: Live-in vp<%1> = vector-trip-count
10+
; IF-EVL-NEXT: Live-in vp<[[VFUF:%[0-9]+]]> = VF * UF
11+
; IF-EVL-NEXT: Live-in vp<[[VTC:%[0-9]+]]> = vector-trip-count
1712
; IF-EVL-NEXT: Live-in ir<%N> = original trip-count
1813

1914
; IF-EVL: vector.ph:
2015
; IF-EVL-NEXT: Successor(s): vector loop
2116

2217
; IF-EVL: <x1> vector loop: {
2318
; IF-EVL-NEXT: vector.body:
24-
; IF-EVL-NEXT: EMIT vp<%3> = CANONICAL-INDUCTION ir<0>, vp<%12>
25-
; IF-EVL-NEXT: EXPLICIT-VECTOR-LENGTH-BASED-IV-PHI vp<%4> = phi ir<0>, vp<%11>
26-
; IF-EVL-NEXT: EMIT vp<%5> = EXPLICIT-VECTOR-LENGTH vp<%4>, ir<%N>
27-
; IF-EVL-NEXT: vp<%6> = SCALAR-STEPS vp<%4>, ir<1>
28-
; IF-EVL-NEXT: CLONE ir<%arrayidx> = getelementptr inbounds ir<%b>, vp<%6>
29-
; IF-EVL-NEXT: vp<%7> = vector-pointer ir<%arrayidx>
30-
; IF-EVL-NEXT: WIDEN ir<%0> = vp.load vp<%7>, vp<%5>
31-
; IF-EVL-NEXT: CLONE ir<%arrayidx3> = getelementptr inbounds ir<%c>, vp<%6>
32-
; IF-EVL-NEXT: vp<%8> = vector-pointer ir<%arrayidx3>
33-
; IF-EVL-NEXT: WIDEN ir<%1> = vp.load vp<%8>, vp<%5>
34-
; IF-EVL-NEXT: WIDEN ir<%cmp4> = icmp sgt ir<%0>, ir<%1>
35-
; IF-EVL-NEXT: WIDEN ir<%2> = vp.sub ir<0>, ir<%1>, vp<%5>
36-
; IF-EVL-NEXT: WIDEN-SELECT ir<%cond.p> = vp.select ir<%cmp4>, ir<%1>, ir<%2>, vp<%5>
37-
; IF-EVL-NEXT: WIDEN ir<%cond> = vp.add ir<%cond.p>, ir<%0>, vp<%5>
38-
; IF-EVL-NEXT: CLONE ir<%arrayidx15> = getelementptr inbounds ir<%a>, vp<%6>
39-
; IF-EVL-NEXT: vp<%9> = vector-pointer ir<%arrayidx15>
40-
; IF-EVL-NEXT: WIDEN vp.store vp<%9>, ir<%cond>, vp<%5>
41-
; IF-EVL-NEXT: SCALAR-CAST vp<%10> = zext vp<%5> to i64
42-
; IF-EVL-NEXT: EMIT vp<%11> = add vp<%10>, vp<%4>
43-
; IF-EVL-NEXT: EMIT vp<%12> = add vp<%3>, vp<%0>
44-
; IF-EVL-NEXT: EMIT branch-on-count vp<%12>, vp<%1>
19+
; IF-EVL-NEXT: EMIT vp<[[IV:%[0-9]+]]> = CANONICAL-INDUCTION
20+
; IF-EVL-NEXT: EXPLICIT-VECTOR-LENGTH-BASED-IV-PHI vp<[[EVL_PHI:%[0-9]+]]> = phi ir<0>, vp<[[IV_NEX:%[0-9]+]]>
21+
; IF-EVL-NEXT: EMIT vp<[[AVL:%.+]]> = sub ir<%N>, vp<[[EVL_PHI]]>
22+
; IF-EVL-NEXT: EMIT vp<[[EVL:%.+]]> = EXPLICIT-VECTOR-LENGTH vp<[[AVL]]>
23+
; IF-EVL-NEXT: vp<[[ST:%[0-9]+]]> = SCALAR-STEPS vp<[[EVL_PHI]]>, ir<1>
24+
; IF-EVL-NEXT: CLONE ir<[[GEP1:%.+]]> = getelementptr inbounds ir<%b>, vp<[[ST]]>
25+
; IF-EVL-NEXT: vp<[[PTR1:%[0-9]+]]> = vector-pointer ir<[[GEP1]]>
26+
; IF-EVL-NEXT: WIDEN ir<[[LD1:%.+]]> = vp.load vp<[[PTR1]]>, vp<[[EVL]]>
27+
; IF-EVL-NEXT: CLONE ir<[[GEP2:%.+]]> = getelementptr inbounds ir<%c>, vp<[[ST]]>
28+
; IF-EVL-NEXT: vp<[[PTR2:%[0-9]+]]> = vector-pointer ir<[[GEP2]]>
29+
; IF-EVL-NEXT: WIDEN ir<[[LD2:%.+]]> = vp.load vp<[[PTR2]]>, vp<[[EVL]]>
30+
; IF-EVL-NEXT: WIDEN ir<[[CMP:%.+]]> = icmp sgt ir<[[LD1]]>, ir<[[LD2]]>
31+
; IF-EVL-NEXT: WIDEN ir<[[SUB:%.+]]> = vp.sub ir<0>, ir<[[LD2]]>, vp<[[EVL]]>
32+
; IF-EVL-NEXT: WIDEN-SELECT ir<[[SELECT:%.+]]> = vp.select ir<[[CMP]]>, ir<%1>, ir<%2>, vp<[[EVL]]>
33+
; IF-EVL-NEXT: WIDEN ir<[[ADD:%.+]]> = vp.add ir<[[SELECT]]>, ir<[[LD1]]>, vp<[[EVL]]>
34+
; IF-EVL-NEXT: CLONE ir<[[GEP3:%.+]]> = getelementptr inbounds ir<%a>, vp<[[ST]]>
35+
; IF-EVL-NEXT: vp<[[PTR3:%.+]]> = vector-pointer ir<[[GEP3]]>
36+
; IF-EVL-NEXT: WIDEN vp.store vp<[[PTR3]]>, ir<[[ADD]]>, vp<[[EVL]]>
37+
; IF-EVL-NEXT: SCALAR-CAST vp<[[CAST:%[0-9]+]]> = zext vp<[[EVL]]> to i64
38+
; IF-EVL-NEXT: EMIT vp<[[IV_NEX]]> = add vp<[[CAST]]>, vp<[[EVL_PHI]]>
39+
; IF-EVL-NEXT: EMIT vp<[[IV_NEXT_EXIT:%[0-9]+]]> = add vp<[[IV]]>, vp<[[VFUF]]>
40+
; IF-EVL-NEXT: EMIT branch-on-count vp<[[IV_NEXT_EXIT]]>, vp<[[VTC]]>
4541
; IF-EVL-NEXT: No successors
4642
; IF-EVL-NEXT: }
4743

48-
; NO-VP: VPlan 'Final VPlan for VF={vscale x 1,vscale x 2,vscale x 4},UF>=1' {
49-
; NO-VP-NEXT: Live-in vp<%0> = VF * UF
50-
; NO-VP-NEXT: Live-in vp<%1> = vector-trip-count
51-
; NO-VP-NEXT: Live-in ir<%N> = original trip-count
52-
53-
; NO-VP: vector.ph:
54-
; NO-VP-NEXT: Successor(s): vector loop
55-
56-
; NO-VP: <x1> vector loop: {
57-
; NO-VP-NEXT: vector.body:
58-
; NO-VP-NEXT: EMIT vp<%2> = CANONICAL-INDUCTION ir<0>, vp<%7>
59-
; NO-VP-NEXT: vp<%3> = SCALAR-STEPS vp<%2>, ir<1>
60-
; NO-VP-NEXT: CLONE ir<%arrayidx> = getelementptr inbounds ir<%b>, vp<%3>
61-
; NO-VP-NEXT: vp<%4> = vector-pointer ir<%arrayidx>
62-
; NO-VP-NEXT: WIDEN ir<%0> = load vp<%4>
63-
; NO-VP-NEXT: CLONE ir<%arrayidx3> = getelementptr inbounds ir<%c>, vp<%3>
64-
; NO-VP-NEXT: vp<%5> = vector-pointer ir<%arrayidx3>
65-
; NO-VP-NEXT: WIDEN ir<%1> = load vp<%5>
66-
; NO-VP-NEXT: WIDEN ir<%cmp4> = icmp sgt ir<%0>, ir<%1>
67-
; NO-VP-NEXT: WIDEN ir<%2> = sub ir<0>, ir<%1>
68-
; NO-VP-NEXT: WIDEN-SELECT ir<%cond.p> = select ir<%cmp4>, ir<%1>, ir<%2>
69-
; NO-VP-NEXT: WIDEN ir<%cond> = add ir<%cond.p>, ir<%0>
70-
; NO-VP-NEXT: CLONE ir<%arrayidx15> = getelementptr inbounds ir<%a>, vp<%3>
71-
; NO-VP-NEXT: vp<%6> = vector-pointer ir<%arrayidx15>
72-
; NO-VP-NEXT: WIDEN store vp<%6>, ir<%cond>
73-
; NO-VP-NEXT: EMIT vp<%7> = add nuw vp<%2>, vp<%0>
74-
; NO-VP-NEXT: EMIT branch-on-count vp<%7>, vp<%1>
75-
; NO-VP-NEXT: No successors
76-
; NO-VP-NEXT: }
77-
78-
7944
entry:
80-
%cmp30 = icmp sgt i64 %N, 0
81-
br i1 %cmp30, label %for.body, label %for.cond.cleanup
82-
83-
for.cond.cleanup:
84-
ret void
45+
br label %for.body
8546

8647
for.body:
8748
%indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
@@ -97,5 +58,8 @@ for.body:
9758
store i32 %cond, ptr %arrayidx15, align 4
9859
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
9960
%exitcond.not = icmp eq i64 %indvars.iv.next, %N
100-
br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
61+
br i1 %exitcond.not, label %exit, label %for.body
62+
63+
exit:
64+
ret void
10165
}

0 commit comments

Comments
 (0)