| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals none --filter-out-after "scalar.ph:" --version 6 | |
| ; RUN: opt -p loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -S %s | FileCheck %s | |
| ; RUN: opt -p loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -prefer-inloop-reductions -S %s | FileCheck --check-prefix=INLOOP %s | |
| ; Conditional fadd reduction with -0.0 start; the merge phi does not have nsz. | |
| ; If the condition is false for all iterations, the result must be -0.0. | |
| define float @cond_fadd(ptr %src, i64 %n) { | |
| ; CHECK-LABEL: define float @cond_fadd( | |
| ; CHECK-SAME: ptr [[SRC:%.*]], i64 [[N:%.*]]) { | |
| ; CHECK-NEXT: [[ENTRY:.*:]] | |
| ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N]], 4 | |
| ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]] | |
| ; CHECK: [[VECTOR_PH]]: | |
| ; CHECK-NEXT: [[TMP0:%.*]] = and i64 [[N]], 3 | |
| ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N]], [[TMP0]] | |
| ; CHECK-NEXT: br label %[[VECTOR_BODY:.*]] | |
| ; CHECK: [[VECTOR_BODY]]: | |
| ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ] | |
| ; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x float> [ <float -0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00>, %[[VECTOR_PH]] ], [ [[PREDPHI:%.*]], %[[VECTOR_BODY]] ] | |
| ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds float, ptr [[SRC]], i64 [[INDEX]] | |
| ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x float>, ptr [[TMP1]], align 4 | |
| ; CHECK-NEXT: [[TMP2:%.*]] = fcmp ogt <4 x float> [[WIDE_LOAD]], splat (float 2.000000e+00) | |
| ; CHECK-NEXT: [[TMP3:%.*]] = fadd fast <4 x float> [[VEC_PHI]], [[WIDE_LOAD]] | |
| ; CHECK-NEXT: [[PREDPHI]] = select <4 x i1> [[TMP2]], <4 x float> [[TMP3]], <4 x float> [[VEC_PHI]] | |
| ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4 | |
| ; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]] | |
| ; CHECK-NEXT: br i1 [[TMP4]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]] | |
| ; CHECK: [[MIDDLE_BLOCK]]: | |
| ; CHECK-NEXT: [[TMP5:%.*]] = call fast float @llvm.vector.reduce.fadd.v4f32(float 0.000000e+00, <4 x float> [[PREDPHI]]) | |
| ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]] | |
| ; CHECK-NEXT: br i1 [[CMP_N]], [[EXIT:label %.*]], label %[[SCALAR_PH]] | |
| ; CHECK: [[SCALAR_PH]]: | |
| ; | |
| ; INLOOP-LABEL: define float @cond_fadd( | |
| ; INLOOP-SAME: ptr [[SRC:%.*]], i64 [[N:%.*]]) { | |
| ; INLOOP-NEXT: [[ENTRY:.*:]] | |
| ; INLOOP-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N]], 4 | |
| ; INLOOP-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]] | |
| ; INLOOP: [[VECTOR_PH]]: | |
| ; INLOOP-NEXT: [[TMP0:%.*]] = and i64 [[N]], 3 | |
| ; INLOOP-NEXT: [[N_VEC:%.*]] = sub i64 [[N]], [[TMP0]] | |
| ; INLOOP-NEXT: br label %[[VECTOR_BODY:.*]] | |
| ; INLOOP: [[VECTOR_BODY]]: | |
| ; INLOOP-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ] | |
| ; INLOOP-NEXT: [[VEC_PHI:%.*]] = phi float [ -0.000000e+00, %[[VECTOR_PH]] ], [ [[TMP5:%.*]], %[[VECTOR_BODY]] ] | |
| ; INLOOP-NEXT: [[TMP1:%.*]] = getelementptr inbounds float, ptr [[SRC]], i64 [[INDEX]] | |
| ; INLOOP-NEXT: [[WIDE_LOAD:%.*]] = load <4 x float>, ptr [[TMP1]], align 4 | |
| ; INLOOP-NEXT: [[TMP2:%.*]] = fcmp ogt <4 x float> [[WIDE_LOAD]], splat (float 2.000000e+00) | |
| ; INLOOP-NEXT: [[TMP3:%.*]] = select fast <4 x i1> [[TMP2]], <4 x float> [[WIDE_LOAD]], <4 x float> zeroinitializer | |
| ; INLOOP-NEXT: [[TMP4:%.*]] = call fast float @llvm.vector.reduce.fadd.v4f32(float 0.000000e+00, <4 x float> [[TMP3]]) | |
| ; INLOOP-NEXT: [[TMP5]] = fadd fast float [[VEC_PHI]], [[TMP4]] | |
| ; INLOOP-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4 | |
| ; INLOOP-NEXT: [[TMP6:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]] | |
| ; INLOOP-NEXT: br i1 [[TMP6]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]] | |
| ; INLOOP: [[MIDDLE_BLOCK]]: | |
| ; INLOOP-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]] | |
| ; INLOOP-NEXT: br i1 [[CMP_N]], [[EXIT:label %.*]], label %[[SCALAR_PH]] | |
| ; INLOOP: [[SCALAR_PH]]: | |
| ; | |
| entry: | |
| br label %loop.header | |
| loop.header: | |
| %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ] | |
| %red = phi float [ -0.0, %entry ], [ %red.next, %loop.latch ] | |
| %gep.src = getelementptr inbounds float, ptr %src, i64 %iv | |
| %l = load float, ptr %gep.src, align 4 | |
| %c = fcmp ogt float %l, 2.0 | |
| br i1 %c, label %then, label %loop.latch | |
| then: | |
| %add = fadd fast float %red, %l | |
| br label %loop.latch | |
| loop.latch: | |
| %red.next = phi float [ %add, %then ], [ %red, %loop.header ] | |
| %iv.next = add nuw nsw i64 %iv, 1 | |
| %ec = icmp eq i64 %iv.next, %n | |
| br i1 %ec, label %exit, label %loop.header | |
| exit: | |
| ret float %red.next | |
| } | |
| ; Same as above, but the merge phi has nsz. | |
| define float @cond_fadd_merge_phi_nsz(ptr %src, i64 %n) { | |
| ; CHECK-LABEL: define float @cond_fadd_merge_phi_nsz( | |
| ; CHECK-SAME: ptr [[SRC:%.*]], i64 [[N:%.*]]) { | |
| ; CHECK-NEXT: [[ENTRY:.*:]] | |
| ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N]], 4 | |
| ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]] | |
| ; CHECK: [[VECTOR_PH]]: | |
| ; CHECK-NEXT: [[TMP0:%.*]] = and i64 [[N]], 3 | |
| ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N]], [[TMP0]] | |
| ; CHECK-NEXT: br label %[[VECTOR_BODY:.*]] | |
| ; CHECK: [[VECTOR_BODY]]: | |
| ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ] | |
| ; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x float> [ <float -0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00>, %[[VECTOR_PH]] ], [ [[PREDPHI:%.*]], %[[VECTOR_BODY]] ] | |
| ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds float, ptr [[SRC]], i64 [[INDEX]] | |
| ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x float>, ptr [[TMP1]], align 4 | |
| ; CHECK-NEXT: [[TMP2:%.*]] = fcmp ogt <4 x float> [[WIDE_LOAD]], splat (float 2.000000e+00) | |
| ; CHECK-NEXT: [[TMP3:%.*]] = fadd fast <4 x float> [[VEC_PHI]], [[WIDE_LOAD]] | |
| ; CHECK-NEXT: [[PREDPHI]] = select nsz <4 x i1> [[TMP2]], <4 x float> [[TMP3]], <4 x float> [[VEC_PHI]] | |
| ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4 | |
| ; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]] | |
| ; CHECK-NEXT: br i1 [[TMP4]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]] | |
| ; CHECK: [[MIDDLE_BLOCK]]: | |
| ; CHECK-NEXT: [[TMP5:%.*]] = call fast float @llvm.vector.reduce.fadd.v4f32(float 0.000000e+00, <4 x float> [[PREDPHI]]) | |
| ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]] | |
| ; CHECK-NEXT: br i1 [[CMP_N]], [[EXIT:label %.*]], label %[[SCALAR_PH]] | |
| ; CHECK: [[SCALAR_PH]]: | |
| ; | |
| ; INLOOP-LABEL: define float @cond_fadd_merge_phi_nsz( | |
| ; INLOOP-SAME: ptr [[SRC:%.*]], i64 [[N:%.*]]) { | |
| ; INLOOP-NEXT: [[ENTRY:.*:]] | |
| ; INLOOP-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N]], 4 | |
| ; INLOOP-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]] | |
| ; INLOOP: [[VECTOR_PH]]: | |
| ; INLOOP-NEXT: [[TMP0:%.*]] = and i64 [[N]], 3 | |
| ; INLOOP-NEXT: [[N_VEC:%.*]] = sub i64 [[N]], [[TMP0]] | |
| ; INLOOP-NEXT: br label %[[VECTOR_BODY:.*]] | |
| ; INLOOP: [[VECTOR_BODY]]: | |
| ; INLOOP-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ] | |
| ; INLOOP-NEXT: [[VEC_PHI:%.*]] = phi float [ -0.000000e+00, %[[VECTOR_PH]] ], [ [[TMP5:%.*]], %[[VECTOR_BODY]] ] | |
| ; INLOOP-NEXT: [[TMP1:%.*]] = getelementptr inbounds float, ptr [[SRC]], i64 [[INDEX]] | |
| ; INLOOP-NEXT: [[WIDE_LOAD:%.*]] = load <4 x float>, ptr [[TMP1]], align 4 | |
| ; INLOOP-NEXT: [[TMP2:%.*]] = fcmp ogt <4 x float> [[WIDE_LOAD]], splat (float 2.000000e+00) | |
| ; INLOOP-NEXT: [[TMP3:%.*]] = select fast <4 x i1> [[TMP2]], <4 x float> [[WIDE_LOAD]], <4 x float> zeroinitializer | |
| ; INLOOP-NEXT: [[TMP4:%.*]] = call fast float @llvm.vector.reduce.fadd.v4f32(float 0.000000e+00, <4 x float> [[TMP3]]) | |
| ; INLOOP-NEXT: [[TMP5]] = fadd fast float [[VEC_PHI]], [[TMP4]] | |
| ; INLOOP-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4 | |
| ; INLOOP-NEXT: [[TMP6:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]] | |
| ; INLOOP-NEXT: br i1 [[TMP6]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]] | |
| ; INLOOP: [[MIDDLE_BLOCK]]: | |
| ; INLOOP-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]] | |
| ; INLOOP-NEXT: br i1 [[CMP_N]], [[EXIT:label %.*]], label %[[SCALAR_PH]] | |
| ; INLOOP: [[SCALAR_PH]]: | |
| ; | |
| entry: | |
| br label %loop.header | |
| loop.header: | |
| %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ] | |
| %red = phi float [ -0.0, %entry ], [ %red.next, %loop.latch ] | |
| %gep.src = getelementptr inbounds float, ptr %src, i64 %iv | |
| %l = load float, ptr %gep.src, align 4 | |
| %c = fcmp ogt float %l, 2.0 | |
| br i1 %c, label %then, label %loop.latch | |
| then: | |
| %add = fadd fast float %red, %l | |
| br label %loop.latch | |
| loop.latch: | |
| %red.next = phi nsz float [ %add, %then ], [ %red, %loop.header ] | |
| %iv.next = add nuw nsw i64 %iv, 1 | |
| %ec = icmp eq i64 %iv.next, %n | |
| br i1 %ec, label %exit, label %loop.header | |
| exit: | |
| ret float %red.next | |
| } | |
| ; Same as @cond_fadd, but with fsub. | |
| define float @cond_fsub(ptr %src, i64 %n) { | |
| ; CHECK-LABEL: define float @cond_fsub( | |
| ; CHECK-SAME: ptr [[SRC:%.*]], i64 [[N:%.*]]) { | |
| ; CHECK-NEXT: [[ENTRY:.*:]] | |
| ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N]], 4 | |
| ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]] | |
| ; CHECK: [[VECTOR_PH]]: | |
| ; CHECK-NEXT: [[TMP0:%.*]] = and i64 [[N]], 3 | |
| ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N]], [[TMP0]] | |
| ; CHECK-NEXT: br label %[[VECTOR_BODY:.*]] | |
| ; CHECK: [[VECTOR_BODY]]: | |
| ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ] | |
| ; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x float> [ <float -0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00>, %[[VECTOR_PH]] ], [ [[PREDPHI:%.*]], %[[VECTOR_BODY]] ] | |
| ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds float, ptr [[SRC]], i64 [[INDEX]] | |
| ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x float>, ptr [[TMP1]], align 4 | |
| ; CHECK-NEXT: [[TMP2:%.*]] = fcmp ogt <4 x float> [[WIDE_LOAD]], splat (float 2.000000e+00) | |
| ; CHECK-NEXT: [[TMP3:%.*]] = fsub fast <4 x float> [[VEC_PHI]], [[WIDE_LOAD]] | |
| ; CHECK-NEXT: [[PREDPHI]] = select <4 x i1> [[TMP2]], <4 x float> [[TMP3]], <4 x float> [[VEC_PHI]] | |
| ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4 | |
| ; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]] | |
| ; CHECK-NEXT: br i1 [[TMP4]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP6:![0-9]+]] | |
| ; CHECK: [[MIDDLE_BLOCK]]: | |
| ; CHECK-NEXT: [[TMP5:%.*]] = call fast float @llvm.vector.reduce.fadd.v4f32(float 0.000000e+00, <4 x float> [[PREDPHI]]) | |
| ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]] | |
| ; CHECK-NEXT: br i1 [[CMP_N]], [[EXIT:label %.*]], label %[[SCALAR_PH]] | |
| ; CHECK: [[SCALAR_PH]]: | |
| ; | |
| ; INLOOP-LABEL: define float @cond_fsub( | |
| ; INLOOP-SAME: ptr [[SRC:%.*]], i64 [[N:%.*]]) { | |
| ; INLOOP-NEXT: [[ENTRY:.*:]] | |
| ; INLOOP-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N]], 4 | |
| ; INLOOP-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]] | |
| ; INLOOP: [[VECTOR_PH]]: | |
| ; INLOOP-NEXT: [[TMP0:%.*]] = and i64 [[N]], 3 | |
| ; INLOOP-NEXT: [[N_VEC:%.*]] = sub i64 [[N]], [[TMP0]] | |
| ; INLOOP-NEXT: br label %[[VECTOR_BODY:.*]] | |
| ; INLOOP: [[VECTOR_BODY]]: | |
| ; INLOOP-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ] | |
| ; INLOOP-NEXT: [[VEC_PHI:%.*]] = phi float [ -0.000000e+00, %[[VECTOR_PH]] ], [ [[TMP5:%.*]], %[[VECTOR_BODY]] ] | |
| ; INLOOP-NEXT: [[TMP1:%.*]] = getelementptr inbounds float, ptr [[SRC]], i64 [[INDEX]] | |
| ; INLOOP-NEXT: [[WIDE_LOAD:%.*]] = load <4 x float>, ptr [[TMP1]], align 4 | |
| ; INLOOP-NEXT: [[TMP2:%.*]] = fcmp ogt <4 x float> [[WIDE_LOAD]], splat (float 2.000000e+00) | |
| ; INLOOP-NEXT: [[TMP3:%.*]] = select fast <4 x i1> [[TMP2]], <4 x float> [[WIDE_LOAD]], <4 x float> zeroinitializer | |
| ; INLOOP-NEXT: [[TMP4:%.*]] = call fast float @llvm.vector.reduce.fadd.v4f32(float 0.000000e+00, <4 x float> [[TMP3]]) | |
| ; INLOOP-NEXT: [[TMP5]] = fsub fast float [[VEC_PHI]], [[TMP4]] | |
| ; INLOOP-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4 | |
| ; INLOOP-NEXT: [[TMP6:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]] | |
| ; INLOOP-NEXT: br i1 [[TMP6]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP6:![0-9]+]] | |
| ; INLOOP: [[MIDDLE_BLOCK]]: | |
| ; INLOOP-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]] | |
| ; INLOOP-NEXT: br i1 [[CMP_N]], [[EXIT:label %.*]], label %[[SCALAR_PH]] | |
| ; INLOOP: [[SCALAR_PH]]: | |
| ; | |
| entry: | |
| br label %loop.header | |
| loop.header: | |
| %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ] | |
| %red = phi float [ -0.0, %entry ], [ %red.next, %loop.latch ] | |
| %gep.src = getelementptr inbounds float, ptr %src, i64 %iv | |
| %l = load float, ptr %gep.src, align 4 | |
| %c = fcmp ogt float %l, 2.0 | |
| br i1 %c, label %then, label %loop.latch | |
| then: | |
| %sub = fsub fast float %red, %l | |
| br label %loop.latch | |
| loop.latch: | |
| %red.next = phi float [ %sub, %then ], [ %red, %loop.header ] | |
| %iv.next = add nuw nsw i64 %iv, 1 | |
| %ec = icmp eq i64 %iv.next, %n | |
| br i1 %ec, label %exit, label %loop.header | |
| exit: | |
| ret float %red.next | |
| } | |
| ; Same as @cond_fadd, but with fmuladd. | |
| define float @cond_fmuladd(ptr %src, i64 %n) { | |
| ; CHECK-LABEL: define float @cond_fmuladd( | |
| ; CHECK-SAME: ptr [[SRC:%.*]], i64 [[N:%.*]]) { | |
| ; CHECK-NEXT: [[ENTRY:.*:]] | |
| ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N]], 4 | |
| ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]] | |
| ; CHECK: [[VECTOR_PH]]: | |
| ; CHECK-NEXT: [[TMP0:%.*]] = and i64 [[N]], 3 | |
| ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N]], [[TMP0]] | |
| ; CHECK-NEXT: br label %[[VECTOR_BODY:.*]] | |
| ; CHECK: [[VECTOR_BODY]]: | |
| ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ] | |
| ; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x float> [ <float -0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00>, %[[VECTOR_PH]] ], [ [[PREDPHI:%.*]], %[[VECTOR_BODY]] ] | |
| ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds float, ptr [[SRC]], i64 [[INDEX]] | |
| ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x float>, ptr [[TMP1]], align 4 | |
| ; CHECK-NEXT: [[TMP2:%.*]] = fcmp ogt <4 x float> [[WIDE_LOAD]], splat (float 2.000000e+00) | |
| ; CHECK-NEXT: [[TMP3:%.*]] = call fast <4 x float> @llvm.fmuladd.v4f32(<4 x float> [[WIDE_LOAD]], <4 x float> [[WIDE_LOAD]], <4 x float> [[VEC_PHI]]) | |
| ; CHECK-NEXT: [[PREDPHI]] = select <4 x i1> [[TMP2]], <4 x float> [[TMP3]], <4 x float> [[VEC_PHI]] | |
| ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4 | |
| ; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]] | |
| ; CHECK-NEXT: br i1 [[TMP4]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP8:![0-9]+]] | |
| ; CHECK: [[MIDDLE_BLOCK]]: | |
| ; CHECK-NEXT: [[TMP5:%.*]] = call fast float @llvm.vector.reduce.fadd.v4f32(float 0.000000e+00, <4 x float> [[PREDPHI]]) | |
| ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]] | |
| ; CHECK-NEXT: br i1 [[CMP_N]], [[EXIT:label %.*]], label %[[SCALAR_PH]] | |
| ; CHECK: [[SCALAR_PH]]: | |
| ; | |
| ; INLOOP-LABEL: define float @cond_fmuladd( | |
| ; INLOOP-SAME: ptr [[SRC:%.*]], i64 [[N:%.*]]) { | |
| ; INLOOP-NEXT: [[ENTRY:.*:]] | |
| ; INLOOP-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N]], 4 | |
| ; INLOOP-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]] | |
| ; INLOOP: [[VECTOR_PH]]: | |
| ; INLOOP-NEXT: [[TMP0:%.*]] = and i64 [[N]], 3 | |
| ; INLOOP-NEXT: [[N_VEC:%.*]] = sub i64 [[N]], [[TMP0]] | |
| ; INLOOP-NEXT: br label %[[VECTOR_BODY:.*]] | |
| ; INLOOP: [[VECTOR_BODY]]: | |
| ; INLOOP-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ] | |
| ; INLOOP-NEXT: [[VEC_PHI:%.*]] = phi float [ -0.000000e+00, %[[VECTOR_PH]] ], [ [[TMP6:%.*]], %[[VECTOR_BODY]] ] | |
| ; INLOOP-NEXT: [[TMP1:%.*]] = getelementptr inbounds float, ptr [[SRC]], i64 [[INDEX]] | |
| ; INLOOP-NEXT: [[WIDE_LOAD:%.*]] = load <4 x float>, ptr [[TMP1]], align 4 | |
| ; INLOOP-NEXT: [[TMP2:%.*]] = fcmp ogt <4 x float> [[WIDE_LOAD]], splat (float 2.000000e+00) | |
| ; INLOOP-NEXT: [[TMP3:%.*]] = fmul fast <4 x float> [[WIDE_LOAD]], [[WIDE_LOAD]] | |
| ; INLOOP-NEXT: [[TMP4:%.*]] = select fast <4 x i1> [[TMP2]], <4 x float> [[TMP3]], <4 x float> zeroinitializer | |
| ; INLOOP-NEXT: [[TMP5:%.*]] = call fast float @llvm.vector.reduce.fadd.v4f32(float 0.000000e+00, <4 x float> [[TMP4]]) | |
| ; INLOOP-NEXT: [[TMP6]] = fadd fast float [[VEC_PHI]], [[TMP5]] | |
| ; INLOOP-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4 | |
| ; INLOOP-NEXT: [[TMP7:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]] | |
| ; INLOOP-NEXT: br i1 [[TMP7]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP8:![0-9]+]] | |
| ; INLOOP: [[MIDDLE_BLOCK]]: | |
| ; INLOOP-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]] | |
| ; INLOOP-NEXT: br i1 [[CMP_N]], [[EXIT:label %.*]], label %[[SCALAR_PH]] | |
| ; INLOOP: [[SCALAR_PH]]: | |
| ; | |
| entry: | |
| br label %loop.header | |
| loop.header: | |
| %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ] | |
| %red = phi float [ -0.0, %entry ], [ %red.next, %loop.latch ] | |
| %gep.src = getelementptr inbounds float, ptr %src, i64 %iv | |
| %l = load float, ptr %gep.src, align 4 | |
| %c = fcmp ogt float %l, 2.0 | |
| br i1 %c, label %then, label %loop.latch | |
| then: | |
| %fma = call fast float @llvm.fmuladd.f32(float %l, float %l, float %red) | |
| br label %loop.latch | |
| loop.latch: | |
| %red.next = phi float [ %fma, %then ], [ %red, %loop.header ] | |
| %iv.next = add nuw nsw i64 %iv, 1 | |
| %ec = icmp eq i64 %iv.next, %n | |
| br i1 %ec, label %exit, label %loop.header | |
| exit: | |
| ret float %red.next | |
| } | |
| ; Same as @cond_fadd, but with fmul. | |
| define float @cond_fmul(ptr %src, i64 %n) { | |
| ; CHECK-LABEL: define float @cond_fmul( | |
| ; CHECK-SAME: ptr [[SRC:%.*]], i64 [[N:%.*]]) { | |
| ; CHECK-NEXT: [[ENTRY:.*:]] | |
| ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N]], 4 | |
| ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]] | |
| ; CHECK: [[VECTOR_PH]]: | |
| ; CHECK-NEXT: [[TMP0:%.*]] = and i64 [[N]], 3 | |
| ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N]], [[TMP0]] | |
| ; CHECK-NEXT: br label %[[VECTOR_BODY:.*]] | |
| ; CHECK: [[VECTOR_BODY]]: | |
| ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ] | |
| ; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x float> [ <float -0.000000e+00, float 1.000000e+00, float 1.000000e+00, float 1.000000e+00>, %[[VECTOR_PH]] ], [ [[PREDPHI:%.*]], %[[VECTOR_BODY]] ] | |
| ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds float, ptr [[SRC]], i64 [[INDEX]] | |
| ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x float>, ptr [[TMP1]], align 4 | |
| ; CHECK-NEXT: [[TMP2:%.*]] = fcmp ogt <4 x float> [[WIDE_LOAD]], splat (float 2.000000e+00) | |
| ; CHECK-NEXT: [[TMP3:%.*]] = fmul fast <4 x float> [[VEC_PHI]], [[WIDE_LOAD]] | |
| ; CHECK-NEXT: [[PREDPHI]] = select <4 x i1> [[TMP2]], <4 x float> [[TMP3]], <4 x float> [[VEC_PHI]] | |
| ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4 | |
| ; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]] | |
| ; CHECK-NEXT: br i1 [[TMP4]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP10:![0-9]+]] | |
| ; CHECK: [[MIDDLE_BLOCK]]: | |
| ; CHECK-NEXT: [[TMP5:%.*]] = call fast float @llvm.vector.reduce.fmul.v4f32(float 1.000000e+00, <4 x float> [[PREDPHI]]) | |
| ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]] | |
| ; CHECK-NEXT: br i1 [[CMP_N]], [[EXIT:label %.*]], label %[[SCALAR_PH]] | |
| ; CHECK: [[SCALAR_PH]]: | |
| ; | |
| ; INLOOP-LABEL: define float @cond_fmul( | |
| ; INLOOP-SAME: ptr [[SRC:%.*]], i64 [[N:%.*]]) { | |
| ; INLOOP-NEXT: [[ENTRY:.*:]] | |
| ; INLOOP-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N]], 4 | |
| ; INLOOP-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]] | |
| ; INLOOP: [[VECTOR_PH]]: | |
| ; INLOOP-NEXT: [[TMP0:%.*]] = and i64 [[N]], 3 | |
| ; INLOOP-NEXT: [[N_VEC:%.*]] = sub i64 [[N]], [[TMP0]] | |
| ; INLOOP-NEXT: br label %[[VECTOR_BODY:.*]] | |
| ; INLOOP: [[VECTOR_BODY]]: | |
| ; INLOOP-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ] | |
| ; INLOOP-NEXT: [[VEC_PHI:%.*]] = phi float [ -0.000000e+00, %[[VECTOR_PH]] ], [ [[TMP5:%.*]], %[[VECTOR_BODY]] ] | |
| ; INLOOP-NEXT: [[TMP1:%.*]] = getelementptr inbounds float, ptr [[SRC]], i64 [[INDEX]] | |
| ; INLOOP-NEXT: [[WIDE_LOAD:%.*]] = load <4 x float>, ptr [[TMP1]], align 4 | |
| ; INLOOP-NEXT: [[TMP2:%.*]] = fcmp ogt <4 x float> [[WIDE_LOAD]], splat (float 2.000000e+00) | |
| ; INLOOP-NEXT: [[TMP3:%.*]] = select fast <4 x i1> [[TMP2]], <4 x float> [[WIDE_LOAD]], <4 x float> splat (float 1.000000e+00) | |
| ; INLOOP-NEXT: [[TMP4:%.*]] = call fast float @llvm.vector.reduce.fmul.v4f32(float 1.000000e+00, <4 x float> [[TMP3]]) | |
| ; INLOOP-NEXT: [[TMP5]] = fmul fast float [[VEC_PHI]], [[TMP4]] | |
| ; INLOOP-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4 | |
| ; INLOOP-NEXT: [[TMP6:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]] | |
| ; INLOOP-NEXT: br i1 [[TMP6]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP10:![0-9]+]] | |
| ; INLOOP: [[MIDDLE_BLOCK]]: | |
| ; INLOOP-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]] | |
| ; INLOOP-NEXT: br i1 [[CMP_N]], [[EXIT:label %.*]], label %[[SCALAR_PH]] | |
| ; INLOOP: [[SCALAR_PH]]: | |
| ; | |
| entry: | |
| br label %loop.header | |
| loop.header: | |
| %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ] | |
| %red = phi float [ -0.0, %entry ], [ %red.next, %loop.latch ] | |
| %gep.src = getelementptr inbounds float, ptr %src, i64 %iv | |
| %l = load float, ptr %gep.src, align 4 | |
| %c = fcmp ogt float %l, 2.0 | |
| br i1 %c, label %then, label %loop.latch | |
| then: | |
| %mul = fmul fast float %red, %l | |
| br label %loop.latch | |
| loop.latch: | |
| %red.next = phi float [ %mul, %then ], [ %red, %loop.header ] | |
| %iv.next = add nuw nsw i64 %iv, 1 | |
| %ec = icmp eq i64 %iv.next, %n | |
| br i1 %ec, label %exit, label %loop.header | |
| exit: | |
| ret float %red.next | |
| } | |
| ; FP min/max reductions require nsz, which must be retained. | |
| define float @cond_fmaxnum(ptr %src, i64 %n) { | |
| ; CHECK-LABEL: define float @cond_fmaxnum( | |
| ; CHECK-SAME: ptr [[SRC:%.*]], i64 [[N:%.*]]) { | |
| ; CHECK-NEXT: [[ENTRY:.*:]] | |
| ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N]], 4 | |
| ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]] | |
| ; CHECK: [[VECTOR_PH]]: | |
| ; CHECK-NEXT: [[TMP0:%.*]] = and i64 [[N]], 3 | |
| ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N]], [[TMP0]] | |
| ; CHECK-NEXT: br label %[[VECTOR_BODY:.*]] | |
| ; CHECK: [[VECTOR_BODY]]: | |
| ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ] | |
| ; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <4 x float> [ splat (float -0.000000e+00), %[[VECTOR_PH]] ], [ [[PREDPHI:%.*]], %[[VECTOR_BODY]] ] | |
| ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds float, ptr [[SRC]], i64 [[INDEX]] | |
| ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x float>, ptr [[TMP1]], align 4 | |
| ; CHECK-NEXT: [[TMP2:%.*]] = fcmp ogt <4 x float> [[WIDE_LOAD]], splat (float 2.000000e+00) | |
| ; CHECK-NEXT: [[TMP3:%.*]] = call nnan nsz <4 x float> @llvm.maxnum.v4f32(<4 x float> [[VEC_PHI]], <4 x float> [[WIDE_LOAD]]) | |
| ; CHECK-NEXT: [[PREDPHI]] = select <4 x i1> [[TMP2]], <4 x float> [[TMP3]], <4 x float> [[VEC_PHI]] | |
| ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4 | |
| ; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]] | |
| ; CHECK-NEXT: br i1 [[TMP4]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP12:![0-9]+]] | |
| ; CHECK: [[MIDDLE_BLOCK]]: | |
| ; CHECK-NEXT: [[TMP5:%.*]] = call nnan nsz float @llvm.vector.reduce.fmax.v4f32(<4 x float> [[PREDPHI]]) | |
| ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]] | |
| ; CHECK-NEXT: br i1 [[CMP_N]], [[EXIT:label %.*]], label %[[SCALAR_PH]] | |
| ; CHECK: [[SCALAR_PH]]: | |
| ; | |
| ; INLOOP-LABEL: define float @cond_fmaxnum( | |
| ; INLOOP-SAME: ptr [[SRC:%.*]], i64 [[N:%.*]]) { | |
| ; INLOOP-NEXT: [[ENTRY:.*:]] | |
| ; INLOOP-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N]], 4 | |
| ; INLOOP-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]] | |
| ; INLOOP: [[VECTOR_PH]]: | |
| ; INLOOP-NEXT: [[TMP0:%.*]] = and i64 [[N]], 3 | |
| ; INLOOP-NEXT: [[N_VEC:%.*]] = sub i64 [[N]], [[TMP0]] | |
| ; INLOOP-NEXT: br label %[[VECTOR_BODY:.*]] | |
| ; INLOOP: [[VECTOR_BODY]]: | |
| ; INLOOP-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ] | |
| ; INLOOP-NEXT: [[VEC_PHI:%.*]] = phi <4 x float> [ splat (float -0.000000e+00), %[[VECTOR_PH]] ], [ [[PREDPHI:%.*]], %[[VECTOR_BODY]] ] | |
| ; INLOOP-NEXT: [[TMP1:%.*]] = getelementptr inbounds float, ptr [[SRC]], i64 [[INDEX]] | |
| ; INLOOP-NEXT: [[WIDE_LOAD:%.*]] = load <4 x float>, ptr [[TMP1]], align 4 | |
| ; INLOOP-NEXT: [[TMP2:%.*]] = fcmp ogt <4 x float> [[WIDE_LOAD]], splat (float 2.000000e+00) | |
| ; INLOOP-NEXT: [[TMP3:%.*]] = call nnan nsz <4 x float> @llvm.maxnum.v4f32(<4 x float> [[VEC_PHI]], <4 x float> [[WIDE_LOAD]]) | |
| ; INLOOP-NEXT: [[PREDPHI]] = select <4 x i1> [[TMP2]], <4 x float> [[TMP3]], <4 x float> [[VEC_PHI]] | |
| ; INLOOP-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4 | |
| ; INLOOP-NEXT: [[TMP4:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]] | |
| ; INLOOP-NEXT: br i1 [[TMP4]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP12:![0-9]+]] | |
| ; INLOOP: [[MIDDLE_BLOCK]]: | |
| ; INLOOP-NEXT: [[TMP5:%.*]] = call nnan nsz float @llvm.vector.reduce.fmax.v4f32(<4 x float> [[PREDPHI]]) | |
| ; INLOOP-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]] | |
| ; INLOOP-NEXT: br i1 [[CMP_N]], [[EXIT:label %.*]], label %[[SCALAR_PH]] | |
| ; INLOOP: [[SCALAR_PH]]: | |
| ; | |
| entry: | |
| br label %loop.header | |
| loop.header: | |
| %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ] | |
| %red = phi float [ -0.0, %entry ], [ %red.next, %loop.latch ] | |
| %gep.src = getelementptr inbounds float, ptr %src, i64 %iv | |
| %l = load float, ptr %gep.src, align 4 | |
| %c = fcmp ogt float %l, 2.0 | |
| br i1 %c, label %then, label %loop.latch | |
| then: | |
| %max = call nnan nsz float @llvm.maxnum.f32(float %red, float %l) | |
| br label %loop.latch | |
| loop.latch: | |
| %red.next = phi float [ %max, %then ], [ %red, %loop.header ] | |
| %iv.next = add nuw nsw i64 %iv, 1 | |
| %ec = icmp eq i64 %iv.next, %n | |
| br i1 %ec, label %exit, label %loop.header | |
| exit: | |
| ret float %red.next | |
| } |