1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2 ; RUN: opt %s -S -riscv-codegenprepare -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: define float @reduce_fadd(
9 ; CHECK-SAME: ptr [[F:%.*]]) #[[ATTR2:[0-9]+]] {
11 ; CHECK-NEXT: [[VSCALE:%.*]] = tail call i64 @llvm.vscale.i64()
12 ; CHECK-NEXT: [[VECSIZE:%.*]] = shl nuw nsw i64 [[VSCALE]], 2
13 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
15 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
16 ; CHECK-NEXT: [[TMP0:%.*]] = phi <vscale x 4 x float> [ insertelement (<vscale x 4 x float> poison, float 0.000000e+00, i64 0), [[ENTRY]] ], [ [[TMP2:%.*]], [[VECTOR_BODY]] ]
17 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds float, ptr [[F]], i64 [[INDEX]]
18 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 4 x float>, ptr [[GEP]], align 4
19 ; CHECK-NEXT: [[TMP1:%.*]] = extractelement <vscale x 4 x float> [[TMP0]], i64 0
20 ; CHECK-NEXT: [[ACC:%.*]] = tail call float @llvm.vector.reduce.fadd.nxv4f32(float [[TMP1]], <vscale x 4 x float> [[WIDE_LOAD]])
21 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[VECSIZE]]
22 ; CHECK-NEXT: [[DONE:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1024
23 ; CHECK-NEXT: [[TMP2]] = insertelement <vscale x 4 x float> poison, float [[ACC]], i64 0
24 ; CHECK-NEXT: br i1 [[DONE]], label [[EXIT:%.*]], label [[VECTOR_BODY]]
26 ; CHECK-NEXT: ret float [[ACC]]
30 %vscale = tail call i64 @llvm.vscale.i64()
31 %vecsize = shl nuw nsw i64 %vscale, 2
35 %index = phi i64 [ 0, %entry ], [ %index.next, %vector.body ]
36 %vec.phi = phi float [ 0.000000e+00, %entry ], [ %acc, %vector.body ]
37 %gep = getelementptr inbounds float, ptr %f, i64 %index
38 %wide.load = load <vscale x 4 x float>, ptr %gep, align 4
39 %acc = tail call float @llvm.vector.reduce.fadd.nxv4f32(float %vec.phi, <vscale x 4 x float> %wide.load)
40 %index.next = add nuw i64 %index, %vecsize
41 %done = icmp eq i64 %index.next, 1024
42 br i1 %done, label %exit, label %vector.body