1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
2 ; RUN: llc < %s -mtriple=riscv64 -mattr=+v | FileCheck %s
4 declare i64 @llvm.vscale.i64()
5 declare float @llvm.vector.reduce.fadd.nxv4f32(float, <vscale x 4 x float>)
7 define float @reduce_fadd(ptr %f) {
8 ; CHECK-LABEL: reduce_fadd:
9 ; CHECK: # %bb.0: # %entry
10 ; CHECK-NEXT: csrr a2, vlenb
11 ; CHECK-NEXT: srli a1, a2, 1
12 ; CHECK-NEXT: vsetvli a3, zero, e32, m1, ta, ma
13 ; CHECK-NEXT: vmv.s.x v8, zero
14 ; CHECK-NEXT: slli a2, a2, 1
15 ; CHECK-NEXT: li a3, 1024
16 ; CHECK-NEXT: .LBB0_1: # %vector.body
17 ; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
18 ; CHECK-NEXT: vl2re32.v v10, (a0)
19 ; CHECK-NEXT: vsetvli a4, zero, e32, m2, ta, ma
20 ; CHECK-NEXT: vfredosum.vs v8, v10, v8
21 ; CHECK-NEXT: sub a3, a3, a1
22 ; CHECK-NEXT: add a0, a0, a2
23 ; CHECK-NEXT: bnez a3, .LBB0_1
24 ; CHECK-NEXT: # %bb.2: # %exit
25 ; CHECK-NEXT: vfmv.f.s fa0, v8
28 %vscale = tail call i64 @llvm.vscale.i64()
29 %vecsize = shl nuw nsw i64 %vscale, 2
33 %index = phi i64 [ 0, %entry ], [ %index.next, %vector.body ]
34 %vec.phi = phi float [ 0.000000e+00, %entry ], [ %acc, %vector.body ]
35 %gep = getelementptr inbounds float, ptr %f, i64 %index
36 %wide.load = load <vscale x 4 x float>, ptr %gep, align 4
37 %acc = tail call float @llvm.vector.reduce.fadd.nxv4f32(float %vec.phi, <vscale x 4 x float> %wide.load)
38 %index.next = add nuw i64 %index, %vecsize
39 %done = icmp eq i64 %index.next, 1024
40 br i1 %done, label %exit, label %vector.body