Skip to content

Commit af2ed59

Browse files
committed
[NFC][LoopVectorize] Add zext/sext cost tests when there is type shrinkage
Differential Revision: https://reviews.llvm.org/D147151
1 parent f5dcab0 commit af2ed59

File tree

1 file changed

+175
-0
lines changed

1 file changed

+175
-0
lines changed
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2+
; REQUIRES: asserts
3+
; RUN: opt -S -passes=loop-vectorize,instsimplify -force-vector-interleave=1 \
4+
; RUN: -debug-only=loop-vectorize 2>%t < %s | FileCheck %s
5+
; RUN: cat %t | FileCheck %s --check-prefix=CHECK-COST
6+
7+
target triple = "aarch64-unknown-linux-gnu"
8+
9+
define void @zext_i8_i16(ptr noalias nocapture readonly %p, ptr noalias nocapture %q, i32 %len) #0 {
10+
; CHECK-COST-LABEL: LV: Checking a loop in 'zext_i8_i16'
11+
; CHECK-COST: LV: Found an estimated cost of 0 for VF 1 For instruction: %conv = zext i8 %0 to i32
12+
; CHECK-COST: LV: Found an estimated cost of 1 for VF 2 For instruction: %conv = zext i8 %0 to i32
13+
; CHECK-COST: LV: Found an estimated cost of 1 for VF 4 For instruction: %conv = zext i8 %0 to i32
14+
; CHECK-COST: LV: Found an estimated cost of 1 for VF 8 For instruction: %conv = zext i8 %0 to i32
15+
; CHECK-COST: LV: Found an estimated cost of 2 for VF 16 For instruction: %conv = zext i8 %0 to i32
16+
; CHECK-COST: LV: Found an estimated cost of 1 for VF vscale x 1 For instruction: %conv = zext i8 %0 to i32
17+
; CHECK-COST: LV: Found an estimated cost of 1 for VF vscale x 2 For instruction: %conv = zext i8 %0 to i32
18+
; CHECK-COST: LV: Found an estimated cost of 1 for VF vscale x 4 For instruction: %conv = zext i8 %0 to i32
19+
; CHECK-COST: LV: Found an estimated cost of 1 for VF vscale x 8 For instruction: %conv = zext i8 %0 to i32
20+
; CHECK-LABEL: define void @zext_i8_i16
21+
; CHECK-SAME: (ptr noalias nocapture readonly [[P:%.*]], ptr noalias nocapture [[Q:%.*]], i32 [[LEN:%.*]]) #[[ATTR0:[0-9]+]] {
22+
; CHECK-NEXT: entry:
23+
; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[LEN]], -1
24+
; CHECK-NEXT: [[TMP1:%.*]] = zext i32 [[TMP0]] to i64
25+
; CHECK-NEXT: [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
26+
; CHECK-NEXT: [[TMP3:%.*]] = call i64 @llvm.vscale.i64()
27+
; CHECK-NEXT: [[TMP4:%.*]] = mul i64 [[TMP3]], 8
28+
; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[TMP2]], [[TMP4]]
29+
; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
30+
; CHECK: vector.ph:
31+
; CHECK-NEXT: [[TMP5:%.*]] = call i64 @llvm.vscale.i64()
32+
; CHECK-NEXT: [[TMP6:%.*]] = mul i64 [[TMP5]], 8
33+
; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[TMP2]], [[TMP6]]
34+
; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[TMP2]], [[N_MOD_VF]]
35+
; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
36+
; CHECK: vector.body:
37+
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
38+
; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 [[INDEX]]
39+
; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 8 x i8>, ptr [[TMP7]], align 1
40+
; CHECK-NEXT: [[TMP8:%.*]] = zext <vscale x 8 x i8> [[WIDE_LOAD]] to <vscale x 8 x i16>
41+
; CHECK-NEXT: [[TMP9:%.*]] = add <vscale x 8 x i16> [[TMP8]], trunc (<vscale x 8 x i32> shufflevector (<vscale x 8 x i32> insertelement (<vscale x 8 x i32> poison, i32 2, i64 0), <vscale x 8 x i32> poison, <vscale x 8 x i32> zeroinitializer) to <vscale x 8 x i16>)
42+
; CHECK-NEXT: [[TMP10:%.*]] = getelementptr inbounds i16, ptr [[Q]], i64 [[INDEX]]
43+
; CHECK-NEXT: store <vscale x 8 x i16> [[TMP9]], ptr [[TMP10]], align 2
44+
; CHECK-NEXT: [[TMP11:%.*]] = call i64 @llvm.vscale.i64()
45+
; CHECK-NEXT: [[TMP12:%.*]] = mul i64 [[TMP11]], 8
46+
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP12]]
47+
; CHECK-NEXT: [[TMP13:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
48+
; CHECK-NEXT: br i1 [[TMP13]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
49+
; CHECK: middle.block:
50+
; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
51+
; CHECK-NEXT: br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
52+
; CHECK: scalar.ph:
53+
; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
54+
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
55+
; CHECK: for.body:
56+
; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
57+
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 [[INDVARS_IV]]
58+
; CHECK-NEXT: [[TMP14:%.*]] = load i8, ptr [[ARRAYIDX]], align 1
59+
; CHECK-NEXT: [[CONV:%.*]] = zext i8 [[TMP14]] to i32
60+
; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i32 [[CONV]], 2
61+
; CHECK-NEXT: [[CONV1:%.*]] = trunc i32 [[ADD]] to i16
62+
; CHECK-NEXT: [[ARRAYIDX3:%.*]] = getelementptr inbounds i16, ptr [[Q]], i64 [[INDVARS_IV]]
63+
; CHECK-NEXT: store i16 [[CONV1]], ptr [[ARRAYIDX3]], align 2
64+
; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
65+
; CHECK-NEXT: [[LFTR_WIDEIV:%.*]] = trunc i64 [[INDVARS_IV_NEXT]] to i32
66+
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[LFTR_WIDEIV]], [[LEN]]
67+
; CHECK-NEXT: br i1 [[EXITCOND]], label [[EXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
68+
; CHECK: exit:
69+
; CHECK-NEXT: ret void
70+
;
71+
entry:
72+
br label %for.body
73+
74+
for.body: ; preds = %entry, %for.body
75+
%indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
76+
%arrayidx = getelementptr inbounds i8, ptr %p, i64 %indvars.iv
77+
%0 = load i8, ptr %arrayidx
78+
%conv = zext i8 %0 to i32
79+
%add = add nuw nsw i32 %conv, 2
80+
%conv1 = trunc i32 %add to i16
81+
%arrayidx3 = getelementptr inbounds i16, ptr %q, i64 %indvars.iv
82+
store i16 %conv1, ptr %arrayidx3
83+
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
84+
%lftr.wideiv = trunc i64 %indvars.iv.next to i32
85+
%exitcond = icmp eq i32 %lftr.wideiv, %len
86+
br i1 %exitcond, label %exit, label %for.body
87+
88+
exit: ; preds = %for.body
89+
ret void
90+
}
91+
92+
define void @sext_i8_i16(ptr noalias nocapture readonly %p, ptr noalias nocapture %q, i32 %len) #0 {
93+
; CHECK-COST-LABEL: LV: Checking a loop in 'sext_i8_i16'
94+
; CHECK-COST: LV: Found an estimated cost of 0 for VF 1 For instruction: %conv = sext i8 %0 to i32
95+
; CHECK-COST: LV: Found an estimated cost of 1 for VF 2 For instruction: %conv = sext i8 %0 to i32
96+
; CHECK-COST: LV: Found an estimated cost of 1 for VF 4 For instruction: %conv = sext i8 %0 to i32
97+
; CHECK-COST: LV: Found an estimated cost of 1 for VF 8 For instruction: %conv = sext i8 %0 to i32
98+
; CHECK-COST: LV: Found an estimated cost of 2 for VF 16 For instruction: %conv = sext i8 %0 to i32
99+
; CHECK-COST: LV: Found an estimated cost of 1 for VF vscale x 1 For instruction: %conv = sext i8 %0 to i32
100+
; CHECK-COST: LV: Found an estimated cost of 1 for VF vscale x 2 For instruction: %conv = sext i8 %0 to i32
101+
; CHECK-COST: LV: Found an estimated cost of 1 for VF vscale x 4 For instruction: %conv = sext i8 %0 to i32
102+
; CHECK-COST: LV: Found an estimated cost of 1 for VF vscale x 8 For instruction: %conv = sext i8 %0 to i32
103+
; CHECK-LABEL: define void @sext_i8_i16
104+
; CHECK-SAME: (ptr noalias nocapture readonly [[P:%.*]], ptr noalias nocapture [[Q:%.*]], i32 [[LEN:%.*]]) #[[ATTR0]] {
105+
; CHECK-NEXT: entry:
106+
; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[LEN]], -1
107+
; CHECK-NEXT: [[TMP1:%.*]] = zext i32 [[TMP0]] to i64
108+
; CHECK-NEXT: [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
109+
; CHECK-NEXT: [[TMP3:%.*]] = call i64 @llvm.vscale.i64()
110+
; CHECK-NEXT: [[TMP4:%.*]] = mul i64 [[TMP3]], 8
111+
; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[TMP2]], [[TMP4]]
112+
; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
113+
; CHECK: vector.ph:
114+
; CHECK-NEXT: [[TMP5:%.*]] = call i64 @llvm.vscale.i64()
115+
; CHECK-NEXT: [[TMP6:%.*]] = mul i64 [[TMP5]], 8
116+
; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[TMP2]], [[TMP6]]
117+
; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[TMP2]], [[N_MOD_VF]]
118+
; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
119+
; CHECK: vector.body:
120+
; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
121+
; CHECK-NEXT: [[TMP7:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 [[INDEX]]
122+
; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 8 x i8>, ptr [[TMP7]], align 1
123+
; CHECK-NEXT: [[TMP8:%.*]] = sext <vscale x 8 x i8> [[WIDE_LOAD]] to <vscale x 8 x i16>
124+
; CHECK-NEXT: [[TMP9:%.*]] = add <vscale x 8 x i16> [[TMP8]], trunc (<vscale x 8 x i32> shufflevector (<vscale x 8 x i32> insertelement (<vscale x 8 x i32> poison, i32 2, i64 0), <vscale x 8 x i32> poison, <vscale x 8 x i32> zeroinitializer) to <vscale x 8 x i16>)
125+
; CHECK-NEXT: [[TMP10:%.*]] = getelementptr inbounds i16, ptr [[Q]], i64 [[INDEX]]
126+
; CHECK-NEXT: store <vscale x 8 x i16> [[TMP9]], ptr [[TMP10]], align 2
127+
; CHECK-NEXT: [[TMP11:%.*]] = call i64 @llvm.vscale.i64()
128+
; CHECK-NEXT: [[TMP12:%.*]] = mul i64 [[TMP11]], 8
129+
; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP12]]
130+
; CHECK-NEXT: [[TMP13:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
131+
; CHECK-NEXT: br i1 [[TMP13]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
132+
; CHECK: middle.block:
133+
; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
134+
; CHECK-NEXT: br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
135+
; CHECK: scalar.ph:
136+
; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
137+
; CHECK-NEXT: br label [[FOR_BODY:%.*]]
138+
; CHECK: for.body:
139+
; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
140+
; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i8, ptr [[P]], i64 [[INDVARS_IV]]
141+
; CHECK-NEXT: [[TMP14:%.*]] = load i8, ptr [[ARRAYIDX]], align 1
142+
; CHECK-NEXT: [[CONV:%.*]] = sext i8 [[TMP14]] to i32
143+
; CHECK-NEXT: [[ADD:%.*]] = add nuw nsw i32 [[CONV]], 2
144+
; CHECK-NEXT: [[CONV1:%.*]] = trunc i32 [[ADD]] to i16
145+
; CHECK-NEXT: [[ARRAYIDX3:%.*]] = getelementptr inbounds i16, ptr [[Q]], i64 [[INDVARS_IV]]
146+
; CHECK-NEXT: store i16 [[CONV1]], ptr [[ARRAYIDX3]], align 2
147+
; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
148+
; CHECK-NEXT: [[LFTR_WIDEIV:%.*]] = trunc i64 [[INDVARS_IV_NEXT]] to i32
149+
; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[LFTR_WIDEIV]], [[LEN]]
150+
; CHECK-NEXT: br i1 [[EXITCOND]], label [[EXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP5:![0-9]+]]
151+
; CHECK: exit:
152+
; CHECK-NEXT: ret void
153+
;
154+
entry:
155+
br label %for.body
156+
157+
for.body: ; preds = %entry, %for.body
158+
%indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
159+
%arrayidx = getelementptr inbounds i8, ptr %p, i64 %indvars.iv
160+
%0 = load i8, ptr %arrayidx
161+
%conv = sext i8 %0 to i32
162+
%add = add nuw nsw i32 %conv, 2
163+
%conv1 = trunc i32 %add to i16
164+
%arrayidx3 = getelementptr inbounds i16, ptr %q, i64 %indvars.iv
165+
store i16 %conv1, ptr %arrayidx3
166+
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
167+
%lftr.wideiv = trunc i64 %indvars.iv.next to i32
168+
%exitcond = icmp eq i32 %lftr.wideiv, %len
169+
br i1 %exitcond, label %exit, label %for.body
170+
171+
exit: ; preds = %for.body
172+
ret void
173+
}
174+
175+
attributes #0 = { "target-features"="+sve" vscale_range(1,16) }

0 commit comments

Comments
 (0)