| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals none --filter "(:|reduce\.fadd)" --version 6 | |
| ; RUN: opt -passes='loop-vectorize' -force-vector-width=4 -S < %s 2>&1 | FileCheck %s | |
| ; Tests for llvm.loop.vectorize.fp_unsafe metadata. | |
| ; Test 1: no fp_unsafe hint - default, FP reordering allowed. | |
| define float @fp_reduction_no_hint(ptr %A, i64 %n) { | |
| ; CHECK-LABEL: define float @fp_reduction_no_hint( | |
| ; CHECK-SAME: ptr [[A:%.*]], i64 [[N:%.*]]) { | |
| ; CHECK: [[ENTRY:.*:]] | |
| ; CHECK: [[VECTOR_PH:.*:]] | |
| ; CHECK: [[VECTOR_BODY:.*:]] | |
| ; CHECK: [[MIDDLE_BLOCK:.*:]] | |
| ; CHECK: [[TMP4:%.*]] = call float @llvm.vector.reduce.fadd.v4f32(float -0.000000e+00, <4 x float> [[TMP2:%.*]]) | |
| ; CHECK: [[SCALAR_PH:.*:]] | |
| ; CHECK: [[LOOP:.*:]] | |
| ; CHECK: [[EXIT:.*:]] | |
| ; | |
| entry: | |
| br label %loop | |
| loop: | |
| %i = phi i64 [ 0, %entry ], [ %i.next, %loop ] | |
| %sum = phi float [ 0.0, %entry ], [ %sum.next, %loop ] | |
| %ptr = getelementptr inbounds float, ptr %A, i64 %i | |
| %val = load float, ptr %ptr, align 4 | |
| %sum.next = fadd float %sum, %val | |
| %i.next = add nuw nsw i64 %i, 1 | |
| %cond = icmp eq i64 %i.next, %n | |
| br i1 %cond, label %exit, label %loop | |
| exit: | |
| ret float %sum.next | |
| } | |
| ; Test 2: fp_unsafe.enable - relaxation explicitly allowed. | |
| define float @fp_reduction_fp_unsafe_enable(ptr %A, i64 %n) { | |
| ; CHECK-LABEL: define float @fp_reduction_fp_unsafe_enable( | |
| ; CHECK-SAME: ptr [[A:%.*]], i64 [[N:%.*]]) { | |
| ; CHECK: [[ENTRY:.*:]] | |
| ; CHECK: [[VECTOR_PH:.*:]] | |
| ; CHECK: [[VECTOR_BODY:.*:]] | |
| ; CHECK: [[MIDDLE_BLOCK:.*:]] | |
| ; CHECK: [[TMP4:%.*]] = call float @llvm.vector.reduce.fadd.v4f32(float -0.000000e+00, <4 x float> [[TMP2:%.*]]) | |
| ; CHECK: [[SCALAR_PH:.*:]] | |
| ; CHECK: [[LOOP:.*:]] | |
| ; CHECK: [[EXIT:.*:]] | |
| ; | |
| entry: | |
| br label %loop | |
| loop: | |
| %i = phi i64 [ 0, %entry ], [ %i.next, %loop ] | |
| %sum = phi float [ 0.0, %entry ], [ %sum.next, %loop ] | |
| %ptr = getelementptr inbounds float, ptr %A, i64 %i | |
| %val = load float, ptr %ptr, align 4 | |
| %sum.next = fadd float %sum, %val | |
| %i.next = add nuw nsw i64 %i, 1 | |
| %cond = icmp eq i64 %i.next, %n | |
| br i1 %cond, label %exit, label %loop, !llvm.loop !0 | |
| exit: | |
| ret float %sum.next | |
| } | |
| ; UTC_ARGS: --disable | |
| ; Test 3: fp_unsafe.disable - relaxation suppressed, loop not vectorized. | |
| define float @fp_reduction_fp_unsafe_disable(ptr %A, i64 %n) { | |
| ; CHECK-LABEL: define float @fp_reduction_fp_unsafe_disable( | |
| ; CHECK-NOT: vector.body | |
| entry: | |
| br label %loop | |
| loop: | |
| %i = phi i64 [ 0, %entry ], [ %i.next, %loop ] | |
| %sum = phi float [ 0.0, %entry ], [ %sum.next, %loop ] | |
| %ptr = getelementptr inbounds float, ptr %A, i64 %i | |
| %val = load float, ptr %ptr, align 4 | |
| %sum.next = fadd float %sum, %val | |
| %i.next = add nuw nsw i64 %i, 1 | |
| %cond = icmp eq i64 %i.next, %n | |
| br i1 %cond, label %exit, label %loop, !llvm.loop !2 | |
| exit: | |
| ret float %sum.next | |
| } | |
| !0 = distinct !{!0, !1} | |
| !1 = !{!"llvm.loop.vectorize.fp_unsafe.enable"} | |
| !2 = distinct !{!2, !3} | |
| !3 = !{!"llvm.loop.vectorize.fp_unsafe.disable"} |