Skip to content

Commit 9ad81e1

Browse files
committed
[Test] add test for setting fastmath flags of select intrinsic
1 parent 5e4b41c commit 9ad81e1

File tree

2 files changed

+146
-0
lines changed

2 files changed

+146
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; REQUIRES: asserts
3+
4+
; RUN: opt < %s -passes=loop-vectorize -mtriple=riscv64 -mattr=+v -riscv-v-vector-bits-max=128 \
5+
; RUN: -riscv-v-vector-bits-min=128 -S | FileCheck --check-prefix=FAST %s
6+
7+
define void @select_with_fastmath_flags(ptr noalias %a, ptr noalias %b, ptr noalias %c, i64 %N) {
8+
; FAST-LABEL: define void @select_with_fastmath_flags(
9+
; FAST-SAME: ptr noalias [[A:%.*]], ptr noalias [[B:%.*]], ptr noalias [[C:%.*]], i64 [[N:%.*]]) #[[ATTR0:[0-9]+]] {
10+
; FAST-NEXT: [[ENTRY:.*]]:
11+
; FAST-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
12+
; FAST-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 4
13+
; FAST-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N]], [[TMP1]]
14+
; FAST-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
15+
; FAST: [[VECTOR_PH]]:
16+
; FAST-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
17+
; FAST-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 4
18+
; FAST-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N]], [[TMP3]]
19+
; FAST-NEXT: [[N_VEC:%.*]] = sub i64 [[N]], [[N_MOD_VF]]
20+
; FAST-NEXT: [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
21+
; FAST-NEXT: [[TMP5:%.*]] = mul i64 [[TMP4]], 4
22+
; FAST-NEXT: br label %[[VECTOR_BODY:.*]]
23+
; FAST: [[VECTOR_BODY]]:
24+
; FAST-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
25+
; FAST-NEXT: [[TMP6:%.*]] = add i64 [[INDEX]], 0
26+
; FAST-NEXT: [[TMP7:%.*]] = getelementptr inbounds nuw float, ptr [[B]], i64 [[TMP6]]
27+
; FAST-NEXT: [[TMP8:%.*]] = getelementptr inbounds nuw float, ptr [[TMP7]], i32 0
28+
; FAST-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 4 x float>, ptr [[TMP8]], align 4
29+
; FAST-NEXT: [[TMP9:%.*]] = getelementptr inbounds nuw float, ptr [[C]], i64 [[TMP6]]
30+
; FAST-NEXT: [[TMP10:%.*]] = getelementptr inbounds nuw float, ptr [[TMP9]], i32 0
31+
; FAST-NEXT: [[WIDE_LOAD1:%.*]] = load <vscale x 4 x float>, ptr [[TMP10]], align 4
32+
; FAST-NEXT: [[TMP11:%.*]] = fcmp fast ogt <vscale x 4 x float> [[WIDE_LOAD]], [[WIDE_LOAD1]]
33+
; FAST-NEXT: [[TMP12:%.*]] = fadd fast <vscale x 4 x float> [[WIDE_LOAD]], splat (float 1.000000e+01)
34+
; FAST-NEXT: [[TMP13:%.*]] = select <vscale x 4 x i1> [[TMP11]], <vscale x 4 x float> [[TMP12]], <vscale x 4 x float> [[WIDE_LOAD1]]
35+
; FAST-NEXT: [[TMP14:%.*]] = getelementptr inbounds nuw float, ptr [[A]], i64 [[TMP6]]
36+
; FAST-NEXT: [[TMP15:%.*]] = getelementptr inbounds nuw float, ptr [[TMP14]], i32 0
37+
; FAST-NEXT: store <vscale x 4 x float> [[TMP13]], ptr [[TMP15]], align 4
38+
; FAST-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
39+
; FAST-NEXT: [[TMP16:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
40+
; FAST-NEXT: br i1 [[TMP16]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
41+
; FAST: [[MIDDLE_BLOCK]]:
42+
; FAST-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]]
43+
; FAST-NEXT: br i1 [[CMP_N]], label %[[EXIT:.*]], label %[[SCALAR_PH]]
44+
; FAST: [[SCALAR_PH]]:
45+
; FAST-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
46+
; FAST-NEXT: br label %[[FOR_BODY:.*]]
47+
; FAST: [[FOR_BODY]]:
48+
; FAST-NEXT: [[IV:%.*]] = phi i64 [ [[IV_NEXT:%.*]], %[[FOR_BODY]] ], [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ]
49+
; FAST-NEXT: [[GEP:%.*]] = getelementptr inbounds nuw float, ptr [[B]], i64 [[IV]]
50+
; FAST-NEXT: [[TMP17:%.*]] = load float, ptr [[GEP]], align 4
51+
; FAST-NEXT: [[GEP3:%.*]] = getelementptr inbounds nuw float, ptr [[C]], i64 [[IV]]
52+
; FAST-NEXT: [[TMP18:%.*]] = load float, ptr [[GEP3]], align 4
53+
; FAST-NEXT: [[CMP4:%.*]] = fcmp fast ogt float [[TMP17]], [[TMP18]]
54+
; FAST-NEXT: [[ADD:%.*]] = fadd fast float [[TMP17]], 1.000000e+01
55+
; FAST-NEXT: [[COND:%.*]] = select fast i1 [[CMP4]], float [[ADD]], float [[TMP18]]
56+
; FAST-NEXT: [[GEP11:%.*]] = getelementptr inbounds nuw float, ptr [[A]], i64 [[IV]]
57+
; FAST-NEXT: store float [[COND]], ptr [[GEP11]], align 4
58+
; FAST-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
59+
; FAST-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
60+
; FAST-NEXT: br i1 [[EXITCOND_NOT]], label %[[EXIT]], label %[[FOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]]
61+
; FAST: [[EXIT]]:
62+
; FAST-NEXT: ret void
63+
;
64+
65+
66+
entry:
67+
br label %for.body
68+
69+
for.body:
70+
%iv = phi i64 [ %iv.next, %for.body ], [ 0, %entry ]
71+
%gep = getelementptr inbounds nuw float, ptr %b, i64 %iv
72+
%0 = load float, ptr %gep, align 4
73+
%gep3 = getelementptr inbounds nuw float, ptr %c, i64 %iv
74+
%1 = load float, ptr %gep3, align 4
75+
%cmp4 = fcmp fast ogt float %0, %1
76+
%add = fadd fast float %0, 1.000000e+01
77+
%cond = select fast i1 %cmp4, float %add, float %1
78+
%gep11 = getelementptr inbounds nuw float, ptr %a, i64 %iv
79+
store float %cond, ptr %gep11, align 4
80+
%iv.next = add nuw nsw i64 %iv, 1
81+
%exitcond.not = icmp eq i64 %iv.next, %N
82+
br i1 %exitcond.not, label %exit, label %for.body
83+
84+
exit:
85+
ret void
86+
}
87+
;.
88+
; FAST: [[LOOP0]] = distinct !{[[LOOP0]], [[META1:![0-9]+]], [[META2:![0-9]+]]}
89+
; FAST: [[META1]] = !{!"llvm.loop.isvectorized", i32 1}
90+
; FAST: [[META2]] = !{!"llvm.loop.unroll.runtime.disable"}
91+
; FAST: [[LOOP3]] = distinct !{[[LOOP3]], [[META2]], [[META1]]}
92+
;.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
; REQUIRES: asserts
2+
3+
; RUN: opt -passes=loop-vectorize -debug-only=loop-vectorize \
4+
; RUN: -mtriple=riscv64 -mattr=+v -riscv-v-vector-bits-max=128 \
5+
; RUN: -riscv-v-vector-bits-min=128 -disable-output < %s 2>&1 | FileCheck --check-prefix=FAST %s
6+
7+
define void @select_with_fastmath_flags(ptr noalias %a, ptr noalias %b, ptr noalias %c, i64 %N) {
8+
; FAST: VPlan 'Final VPlan for VF={vscale x 1,vscale x 2,vscale x 4},UF={1}' {
9+
; FAST-NEXT: ir<[[VFUF:%.+]]> = VF * UF
10+
; FAST-NEXT: Live-in ir<[[VTC:%.+]]> = vector-trip-count
11+
; FAST-NEXT: Live-in ir<%N> = original trip-count
12+
13+
; FAST: <x1> vector loop: {
14+
; FAST-NEXT: vector.body:
15+
; FAST-NEXT: SCALAR-PHI vp<[[IV:%.+]]> = phi ir<0>, vp<[[IV_NEXT_EXIT:%.+]]>
16+
; FAST-NEXT: vp<[[ST:%.+]]> = SCALAR-STEPS vp<[[IV]]>, ir<1>
17+
; FAST-NEXT: CLONE ir<[[GEP1:%.+]]> = getelementptr inbounds nuw ir<%b>, vp<[[ST]]>
18+
; FAST-NEXT: vp<[[PTR1:%.+]]> = vector-pointer ir<[[GEP1]]>
19+
; FAST-NEXT: WIDEN ir<[[LD1:%.+]]> = load vp<[[PTR1]]>
20+
; FAST-NEXT: CLONE ir<[[GEP2:%.+]]> = getelementptr inbounds nuw ir<%c>, vp<[[ST]]>
21+
; FAST-NEXT: vp<[[PTR2:%.+]]> = vector-pointer ir<[[GEP2]]>
22+
; FAST-NEXT: WIDEN ir<[[LD2:%.+]]> = load vp<[[PTR2]]>
23+
; FAST-NEXT: WIDEN ir<[[FCMP:%.+]]> = fcmp ogt ir<[[LD1]]>, ir<[[LD2]]>
24+
; FAST-NEXT: WIDEN ir<[[FADD:%.+]]> = fadd reassoc nnan ninf nsz arcp contract afn ir<[[LD1]]>, ir<1.000000e+01>
25+
; FAST-NEXT: WIDEN-SELECT ir<[[SELECT:%.+]]> = select ir<[[FCMP]]>, ir<[[FADD]]>, ir<[[LD2]]>
26+
; FAST-NEXT: CLONE ir<[[GEP3:%.+]]> = getelementptr inbounds nuw ir<%a>, vp<[[ST]]>
27+
; FAST-NEXT: vp<[[PTR3:%.+]]> = vector-pointer ir<[[GEP3]]>
28+
; FAST-NEXT: WIDEN store vp<[[PTR3]]>, ir<[[SELECT]]>
29+
; FAST-NEXT: EMIT vp<[[IV_NEXT_EXIT]]> = add nuw vp<[[IV]]>, ir<[[VFUF]]>
30+
; FAST-NEXT: EMIT branch-on-count vp<[[IV_NEXT_EXIT]]>, ir<%n.vec>
31+
; FAST-NEXT: No successors
32+
; FAST-NEXT: }
33+
34+
entry:
35+
br label %for.body
36+
37+
for.body:
38+
%iv = phi i64 [ %iv.next, %for.body ], [ 0, %entry ]
39+
%gep = getelementptr inbounds nuw float, ptr %b, i64 %iv
40+
%0 = load float, ptr %gep, align 4
41+
%gep3 = getelementptr inbounds nuw float, ptr %c, i64 %iv
42+
%1 = load float, ptr %gep3, align 4
43+
%cmp4 = fcmp fast ogt float %0, %1
44+
%add = fadd fast float %0, 1.000000e+01
45+
%cond = select fast i1 %cmp4, float %add, float %1
46+
%gep11 = getelementptr inbounds nuw float, ptr %a, i64 %iv
47+
store float %cond, ptr %gep11, align 4
48+
%iv.next = add nuw nsw i64 %iv, 1
49+
%exitcond.not = icmp eq i64 %iv.next, %N
50+
br i1 %exitcond.not, label %exit, label %for.body
51+
52+
exit:
53+
ret void
54+
}

0 commit comments

Comments
 (0)