blob: be13d7bbd1a1a2adcd9e60728720bec769563081 [file] [edit]
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals none --version 6
; RUN: opt -p loop-vectorize -force-vector-width=4 -force-target-supports-masked-memory-ops -tail-folding-policy=must-fold-tail -force-tail-folding-style=data -S %s | FileCheck --check-prefixes=CHECK,DATA %s
; RUN: opt -p loop-vectorize -force-vector-width=4 -force-target-supports-masked-memory-ops -tail-folding-policy=must-fold-tail -force-tail-folding-style=data-and-control -S %s | FileCheck --check-prefixes=CHECK,DATA-AND-CONTROL %s
; Select-based max reduction with tail folding.
define float @fmax_ogt_with_select(ptr %src, i64 %n) {
; DATA-LABEL: define float @fmax_ogt_with_select(
; DATA-SAME: ptr [[SRC:%.*]], i64 [[N:%.*]]) {
; DATA-NEXT: [[ENTRY:.*:]]
; DATA-NEXT: br label %[[VECTOR_PH:.*]]
; DATA: [[VECTOR_PH]]:
; DATA-NEXT: [[N_RND_UP:%.*]] = add i64 [[N]], 3
; DATA-NEXT: [[TMP0:%.*]] = and i64 [[N_RND_UP]], 3
; DATA-NEXT: [[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[TMP0]]
; DATA-NEXT: br label %[[VECTOR_BODY:.*]]
; DATA: [[VECTOR_BODY]]:
; DATA-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
; DATA-NEXT: [[VEC_PHI:%.*]] = phi <4 x float> [ splat (float -1.000000e+07), %[[VECTOR_PH]] ], [ [[TMP4:%.*]], %[[VECTOR_BODY]] ]
; DATA-NEXT: [[ACTIVE_LANE_MASK:%.*]] = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i64(i64 [[INDEX]], i64 [[N]])
; DATA-NEXT: [[TMP1:%.*]] = getelementptr inbounds nuw float, ptr [[SRC]], i64 [[INDEX]]
; DATA-NEXT: [[WIDE_MASKED_LOAD:%.*]] = call <4 x float> @llvm.masked.load.v4f32.p0(ptr align 4 [[TMP1]], <4 x i1> [[ACTIVE_LANE_MASK]], <4 x float> poison)
; DATA-NEXT: [[TMP3:%.*]] = freeze <4 x float> [[WIDE_MASKED_LOAD]]
; DATA-NEXT: [[TMP2:%.*]] = fcmp ogt <4 x float> [[VEC_PHI]], [[TMP3]]
; DATA-NEXT: [[TMP4]] = select <4 x i1> [[TMP2]], <4 x float> [[VEC_PHI]], <4 x float> [[TMP3]]
; DATA-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], 4
; DATA-NEXT: [[TMP5:%.*]] = fcmp uno <4 x float> [[TMP3]], [[TMP3]]
; DATA-NEXT: [[TMP6:%.*]] = bitcast <4 x float> [[TMP3]] to <4 x i32>
; DATA-NEXT: [[TMP7:%.*]] = icmp eq <4 x i32> [[TMP6]], splat (i32 -2147483648)
; DATA-NEXT: [[TMP8:%.*]] = or <4 x i1> [[TMP5]], [[TMP7]]
; DATA-NEXT: [[TMP9:%.*]] = call i1 @llvm.vector.reduce.or.v4i1(<4 x i1> [[TMP8]])
; DATA-NEXT: [[TMP10:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
; DATA-NEXT: [[TMP11:%.*]] = or i1 [[TMP9]], [[TMP10]]
; DATA-NEXT: br i1 [[TMP11]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
; DATA: [[MIDDLE_BLOCK]]:
; DATA-NEXT: [[TMP12:%.*]] = select <4 x i1> [[ACTIVE_LANE_MASK]], <4 x float> [[TMP4]], <4 x float> [[VEC_PHI]]
; DATA-NEXT: [[TMP13:%.*]] = select i1 [[TMP9]], <4 x float> [[VEC_PHI]], <4 x float> [[TMP12]]
; DATA-NEXT: [[TMP14:%.*]] = select i1 [[TMP9]], i64 [[INDEX]], i64 [[N]]
; DATA-NEXT: [[TMP15:%.*]] = call nnan float @llvm.vector.reduce.fmax.v4f32(<4 x float> [[TMP13]])
; DATA-NEXT: [[TMP16:%.*]] = xor i1 [[TMP9]], true
; DATA-NEXT: br i1 [[TMP16]], label %[[EXIT:.*]], label %[[SCALAR_PH:.*]]
; DATA: [[SCALAR_PH]]:
; DATA-NEXT: br label %[[LOOP:.*]]
; DATA: [[LOOP]]:
; DATA-NEXT: [[IV:%.*]] = phi i64 [ [[TMP14]], %[[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
; DATA-NEXT: [[MAX:%.*]] = phi float [ [[TMP15]], %[[SCALAR_PH]] ], [ [[MAX_NEXT:%.*]], %[[LOOP]] ]
; DATA-NEXT: [[GEP_SRC:%.*]] = getelementptr inbounds nuw float, ptr [[SRC]], i64 [[IV]]
; DATA-NEXT: [[L:%.*]] = load float, ptr [[GEP_SRC]], align 4
; DATA-NEXT: [[CMP:%.*]] = fcmp ogt float [[MAX]], [[L]]
; DATA-NEXT: [[MAX_NEXT]] = select i1 [[CMP]], float [[MAX]], float [[L]]
; DATA-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
; DATA-NEXT: [[EC:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
; DATA-NEXT: br i1 [[EC]], label %[[EXIT]], label %[[LOOP]], !llvm.loop [[LOOP3:![0-9]+]]
; DATA: [[EXIT]]:
; DATA-NEXT: [[MAX_NEXT_LCSSA:%.*]] = phi float [ [[MAX_NEXT]], %[[LOOP]] ], [ [[TMP15]], %[[MIDDLE_BLOCK]] ]
; DATA-NEXT: ret float [[MAX_NEXT_LCSSA]]
;
; DATA-AND-CONTROL-LABEL: define float @fmax_ogt_with_select(
; DATA-AND-CONTROL-SAME: ptr [[SRC:%.*]], i64 [[N:%.*]]) {
; DATA-AND-CONTROL-NEXT: [[ENTRY:.*:]]
; DATA-AND-CONTROL-NEXT: br label %[[VECTOR_PH:.*]]
; DATA-AND-CONTROL: [[VECTOR_PH]]:
; DATA-AND-CONTROL-NEXT: [[ACTIVE_LANE_MASK_ENTRY:%.*]] = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i64(i64 0, i64 [[N]])
; DATA-AND-CONTROL-NEXT: [[TRIP_COUNT_MINUS_VF:%.*]] = call i64 @llvm.usub.sat.i64(i64 [[N]], i64 4)
; DATA-AND-CONTROL-NEXT: br label %[[VECTOR_BODY:.*]]
; DATA-AND-CONTROL: [[VECTOR_BODY]]:
; DATA-AND-CONTROL-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
; DATA-AND-CONTROL-NEXT: [[ACTIVE_LANE_MASK:%.*]] = phi <4 x i1> [ [[ACTIVE_LANE_MASK_ENTRY]], %[[VECTOR_PH]] ], [ [[ACTIVE_LANE_MASK_NEXT:%.*]], %[[VECTOR_BODY]] ]
; DATA-AND-CONTROL-NEXT: [[VEC_PHI:%.*]] = phi <4 x float> [ splat (float -1.000000e+07), %[[VECTOR_PH]] ], [ [[TMP3:%.*]], %[[VECTOR_BODY]] ]
; DATA-AND-CONTROL-NEXT: [[TMP0:%.*]] = getelementptr inbounds nuw float, ptr [[SRC]], i64 [[INDEX]]
; DATA-AND-CONTROL-NEXT: [[WIDE_MASKED_LOAD:%.*]] = call <4 x float> @llvm.masked.load.v4f32.p0(ptr align 4 [[TMP0]], <4 x i1> [[ACTIVE_LANE_MASK]], <4 x float> poison)
; DATA-AND-CONTROL-NEXT: [[TMP2:%.*]] = freeze <4 x float> [[WIDE_MASKED_LOAD]]
; DATA-AND-CONTROL-NEXT: [[TMP1:%.*]] = fcmp ogt <4 x float> [[VEC_PHI]], [[TMP2]]
; DATA-AND-CONTROL-NEXT: [[TMP3]] = select <4 x i1> [[TMP1]], <4 x float> [[VEC_PHI]], <4 x float> [[TMP2]]
; DATA-AND-CONTROL-NEXT: [[TMP4:%.*]] = fcmp uno <4 x float> [[TMP2]], [[TMP2]]
; DATA-AND-CONTROL-NEXT: [[TMP5:%.*]] = bitcast <4 x float> [[TMP2]] to <4 x i32>
; DATA-AND-CONTROL-NEXT: [[TMP6:%.*]] = icmp eq <4 x i32> [[TMP5]], splat (i32 -2147483648)
; DATA-AND-CONTROL-NEXT: [[TMP7:%.*]] = or <4 x i1> [[TMP4]], [[TMP6]]
; DATA-AND-CONTROL-NEXT: [[TMP8:%.*]] = call i1 @llvm.vector.reduce.or.v4i1(<4 x i1> [[TMP7]])
; DATA-AND-CONTROL-NEXT: [[ACTIVE_LANE_MASK_NEXT]] = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i64(i64 [[INDEX]], i64 [[TRIP_COUNT_MINUS_VF]])
; DATA-AND-CONTROL-NEXT: [[TMP9:%.*]] = extractelement <4 x i1> [[ACTIVE_LANE_MASK_NEXT]], i64 0
; DATA-AND-CONTROL-NEXT: [[TMP10:%.*]] = xor i1 [[TMP9]], true
; DATA-AND-CONTROL-NEXT: [[TMP11:%.*]] = or i1 [[TMP8]], [[TMP10]]
; DATA-AND-CONTROL-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], 4
; DATA-AND-CONTROL-NEXT: br i1 [[TMP11]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
; DATA-AND-CONTROL: [[MIDDLE_BLOCK]]:
; DATA-AND-CONTROL-NEXT: [[TMP12:%.*]] = select <4 x i1> [[ACTIVE_LANE_MASK]], <4 x float> [[TMP3]], <4 x float> [[VEC_PHI]]
; DATA-AND-CONTROL-NEXT: [[TMP13:%.*]] = select i1 [[TMP8]], <4 x float> [[VEC_PHI]], <4 x float> [[TMP12]]
; DATA-AND-CONTROL-NEXT: [[TMP14:%.*]] = select i1 [[TMP8]], i64 [[INDEX]], i64 [[N]]
; DATA-AND-CONTROL-NEXT: [[TMP15:%.*]] = call nnan float @llvm.vector.reduce.fmax.v4f32(<4 x float> [[TMP13]])
; DATA-AND-CONTROL-NEXT: [[TMP16:%.*]] = xor i1 [[TMP8]], true
; DATA-AND-CONTROL-NEXT: br i1 [[TMP16]], label %[[EXIT:.*]], label %[[SCALAR_PH:.*]]
; DATA-AND-CONTROL: [[SCALAR_PH]]:
; DATA-AND-CONTROL-NEXT: br label %[[LOOP:.*]]
; DATA-AND-CONTROL: [[LOOP]]:
; DATA-AND-CONTROL-NEXT: [[IV:%.*]] = phi i64 [ [[TMP14]], %[[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
; DATA-AND-CONTROL-NEXT: [[MAX:%.*]] = phi float [ [[TMP15]], %[[SCALAR_PH]] ], [ [[MAX_NEXT:%.*]], %[[LOOP]] ]
; DATA-AND-CONTROL-NEXT: [[GEP_SRC:%.*]] = getelementptr inbounds nuw float, ptr [[SRC]], i64 [[IV]]
; DATA-AND-CONTROL-NEXT: [[L:%.*]] = load float, ptr [[GEP_SRC]], align 4
; DATA-AND-CONTROL-NEXT: [[CMP:%.*]] = fcmp ogt float [[MAX]], [[L]]
; DATA-AND-CONTROL-NEXT: [[MAX_NEXT]] = select i1 [[CMP]], float [[MAX]], float [[L]]
; DATA-AND-CONTROL-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
; DATA-AND-CONTROL-NEXT: [[EC:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
; DATA-AND-CONTROL-NEXT: br i1 [[EC]], label %[[EXIT]], label %[[LOOP]], !llvm.loop [[LOOP3:![0-9]+]]
; DATA-AND-CONTROL: [[EXIT]]:
; DATA-AND-CONTROL-NEXT: [[MAX_NEXT_LCSSA:%.*]] = phi float [ [[MAX_NEXT]], %[[LOOP]] ], [ [[TMP15]], %[[MIDDLE_BLOCK]] ]
; DATA-AND-CONTROL-NEXT: ret float [[MAX_NEXT_LCSSA]]
;
entry:
br label %loop
loop:
%iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
%max = phi float [ -1.000000e+07, %entry ], [ %max.next, %loop ]
%gep.src = getelementptr inbounds nuw float, ptr %src, i64 %iv
%l = load float, ptr %gep.src, align 4
%cmp = fcmp ogt float %max, %l
%max.next = select i1 %cmp, float %max, float %l
%iv.next = add nuw nsw i64 %iv, 1
%ec = icmp eq i64 %iv.next, %n
br i1 %ec, label %exit, label %loop
exit:
ret float %max.next
}
; Select-based max reduction with tail folding, ninf and an -inf start value.
define float @fmax_ogt_with_select_ninf_inf_start(ptr %src, i64 %n) {
; DATA-LABEL: define float @fmax_ogt_with_select_ninf_inf_start(
; DATA-SAME: ptr [[SRC:%.*]], i64 [[N:%.*]]) {
; DATA-NEXT: [[ENTRY:.*:]]
; DATA-NEXT: br label %[[VECTOR_PH:.*]]
; DATA: [[VECTOR_PH]]:
; DATA-NEXT: [[N_RND_UP:%.*]] = add i64 [[N]], 3
; DATA-NEXT: [[TMP0:%.*]] = and i64 [[N_RND_UP]], 3
; DATA-NEXT: [[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[TMP0]]
; DATA-NEXT: br label %[[VECTOR_BODY:.*]]
; DATA: [[VECTOR_BODY]]:
; DATA-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
; DATA-NEXT: [[VEC_PHI:%.*]] = phi <4 x float> [ splat (float -inf), %[[VECTOR_PH]] ], [ [[TMP4:%.*]], %[[VECTOR_BODY]] ]
; DATA-NEXT: [[ACTIVE_LANE_MASK:%.*]] = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i64(i64 [[INDEX]], i64 [[N]])
; DATA-NEXT: [[TMP1:%.*]] = getelementptr inbounds nuw float, ptr [[SRC]], i64 [[INDEX]]
; DATA-NEXT: [[WIDE_MASKED_LOAD:%.*]] = call <4 x float> @llvm.masked.load.v4f32.p0(ptr align 4 [[TMP1]], <4 x i1> [[ACTIVE_LANE_MASK]], <4 x float> poison)
; DATA-NEXT: [[TMP3:%.*]] = freeze <4 x float> [[WIDE_MASKED_LOAD]]
; DATA-NEXT: [[TMP2:%.*]] = fcmp ogt <4 x float> [[VEC_PHI]], [[TMP3]]
; DATA-NEXT: [[TMP4]] = select <4 x i1> [[TMP2]], <4 x float> [[VEC_PHI]], <4 x float> [[TMP3]]
; DATA-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], 4
; DATA-NEXT: [[TMP5:%.*]] = fcmp uno <4 x float> [[TMP3]], [[TMP3]]
; DATA-NEXT: [[TMP6:%.*]] = bitcast <4 x float> [[TMP3]] to <4 x i32>
; DATA-NEXT: [[TMP7:%.*]] = icmp eq <4 x i32> [[TMP6]], splat (i32 -2147483648)
; DATA-NEXT: [[TMP8:%.*]] = or <4 x i1> [[TMP5]], [[TMP7]]
; DATA-NEXT: [[TMP9:%.*]] = call i1 @llvm.vector.reduce.or.v4i1(<4 x i1> [[TMP8]])
; DATA-NEXT: [[TMP10:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
; DATA-NEXT: [[TMP11:%.*]] = or i1 [[TMP9]], [[TMP10]]
; DATA-NEXT: br i1 [[TMP11]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
; DATA: [[MIDDLE_BLOCK]]:
; DATA-NEXT: [[TMP12:%.*]] = select <4 x i1> [[ACTIVE_LANE_MASK]], <4 x float> [[TMP4]], <4 x float> [[VEC_PHI]]
; DATA-NEXT: [[TMP13:%.*]] = select i1 [[TMP9]], <4 x float> [[VEC_PHI]], <4 x float> [[TMP12]]
; DATA-NEXT: [[TMP14:%.*]] = select i1 [[TMP9]], i64 [[INDEX]], i64 [[N]]
; DATA-NEXT: [[TMP15:%.*]] = call nnan float @llvm.vector.reduce.fmax.v4f32(<4 x float> [[TMP13]])
; DATA-NEXT: [[TMP16:%.*]] = xor i1 [[TMP9]], true
; DATA-NEXT: br i1 [[TMP16]], label %[[EXIT:.*]], label %[[SCALAR_PH:.*]]
; DATA: [[SCALAR_PH]]:
; DATA-NEXT: br label %[[LOOP:.*]]
; DATA: [[LOOP]]:
; DATA-NEXT: [[IV:%.*]] = phi i64 [ [[TMP14]], %[[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
; DATA-NEXT: [[MAX:%.*]] = phi float [ [[TMP15]], %[[SCALAR_PH]] ], [ [[MAX_NEXT:%.*]], %[[LOOP]] ]
; DATA-NEXT: [[GEP_SRC:%.*]] = getelementptr inbounds nuw float, ptr [[SRC]], i64 [[IV]]
; DATA-NEXT: [[L:%.*]] = load float, ptr [[GEP_SRC]], align 4
; DATA-NEXT: [[CMP:%.*]] = fcmp ogt float [[MAX]], [[L]]
; DATA-NEXT: [[MAX_NEXT]] = select ninf i1 [[CMP]], float [[MAX]], float [[L]]
; DATA-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
; DATA-NEXT: [[EC:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
; DATA-NEXT: br i1 [[EC]], label %[[EXIT]], label %[[LOOP]], !llvm.loop [[LOOP5:![0-9]+]]
; DATA: [[EXIT]]:
; DATA-NEXT: [[MAX_NEXT_LCSSA:%.*]] = phi float [ [[MAX_NEXT]], %[[LOOP]] ], [ [[TMP15]], %[[MIDDLE_BLOCK]] ]
; DATA-NEXT: ret float [[MAX_NEXT_LCSSA]]
;
; DATA-AND-CONTROL-LABEL: define float @fmax_ogt_with_select_ninf_inf_start(
; DATA-AND-CONTROL-SAME: ptr [[SRC:%.*]], i64 [[N:%.*]]) {
; DATA-AND-CONTROL-NEXT: [[ENTRY:.*:]]
; DATA-AND-CONTROL-NEXT: br label %[[VECTOR_PH:.*]]
; DATA-AND-CONTROL: [[VECTOR_PH]]:
; DATA-AND-CONTROL-NEXT: [[ACTIVE_LANE_MASK_ENTRY:%.*]] = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i64(i64 0, i64 [[N]])
; DATA-AND-CONTROL-NEXT: [[TRIP_COUNT_MINUS_VF:%.*]] = call i64 @llvm.usub.sat.i64(i64 [[N]], i64 4)
; DATA-AND-CONTROL-NEXT: br label %[[VECTOR_BODY:.*]]
; DATA-AND-CONTROL: [[VECTOR_BODY]]:
; DATA-AND-CONTROL-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
; DATA-AND-CONTROL-NEXT: [[ACTIVE_LANE_MASK:%.*]] = phi <4 x i1> [ [[ACTIVE_LANE_MASK_ENTRY]], %[[VECTOR_PH]] ], [ [[ACTIVE_LANE_MASK_NEXT:%.*]], %[[VECTOR_BODY]] ]
; DATA-AND-CONTROL-NEXT: [[VEC_PHI:%.*]] = phi <4 x float> [ splat (float -inf), %[[VECTOR_PH]] ], [ [[TMP3:%.*]], %[[VECTOR_BODY]] ]
; DATA-AND-CONTROL-NEXT: [[TMP0:%.*]] = getelementptr inbounds nuw float, ptr [[SRC]], i64 [[INDEX]]
; DATA-AND-CONTROL-NEXT: [[WIDE_MASKED_LOAD:%.*]] = call <4 x float> @llvm.masked.load.v4f32.p0(ptr align 4 [[TMP0]], <4 x i1> [[ACTIVE_LANE_MASK]], <4 x float> poison)
; DATA-AND-CONTROL-NEXT: [[TMP2:%.*]] = freeze <4 x float> [[WIDE_MASKED_LOAD]]
; DATA-AND-CONTROL-NEXT: [[TMP1:%.*]] = fcmp ogt <4 x float> [[VEC_PHI]], [[TMP2]]
; DATA-AND-CONTROL-NEXT: [[TMP3]] = select <4 x i1> [[TMP1]], <4 x float> [[VEC_PHI]], <4 x float> [[TMP2]]
; DATA-AND-CONTROL-NEXT: [[TMP4:%.*]] = fcmp uno <4 x float> [[TMP2]], [[TMP2]]
; DATA-AND-CONTROL-NEXT: [[TMP5:%.*]] = bitcast <4 x float> [[TMP2]] to <4 x i32>
; DATA-AND-CONTROL-NEXT: [[TMP6:%.*]] = icmp eq <4 x i32> [[TMP5]], splat (i32 -2147483648)
; DATA-AND-CONTROL-NEXT: [[TMP7:%.*]] = or <4 x i1> [[TMP4]], [[TMP6]]
; DATA-AND-CONTROL-NEXT: [[TMP8:%.*]] = call i1 @llvm.vector.reduce.or.v4i1(<4 x i1> [[TMP7]])
; DATA-AND-CONTROL-NEXT: [[ACTIVE_LANE_MASK_NEXT]] = call <4 x i1> @llvm.get.active.lane.mask.v4i1.i64(i64 [[INDEX]], i64 [[TRIP_COUNT_MINUS_VF]])
; DATA-AND-CONTROL-NEXT: [[TMP9:%.*]] = extractelement <4 x i1> [[ACTIVE_LANE_MASK_NEXT]], i64 0
; DATA-AND-CONTROL-NEXT: [[TMP10:%.*]] = xor i1 [[TMP9]], true
; DATA-AND-CONTROL-NEXT: [[TMP11:%.*]] = or i1 [[TMP8]], [[TMP10]]
; DATA-AND-CONTROL-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], 4
; DATA-AND-CONTROL-NEXT: br i1 [[TMP11]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
; DATA-AND-CONTROL: [[MIDDLE_BLOCK]]:
; DATA-AND-CONTROL-NEXT: [[TMP12:%.*]] = select <4 x i1> [[ACTIVE_LANE_MASK]], <4 x float> [[TMP3]], <4 x float> [[VEC_PHI]]
; DATA-AND-CONTROL-NEXT: [[TMP13:%.*]] = select i1 [[TMP8]], <4 x float> [[VEC_PHI]], <4 x float> [[TMP12]]
; DATA-AND-CONTROL-NEXT: [[TMP14:%.*]] = select i1 [[TMP8]], i64 [[INDEX]], i64 [[N]]
; DATA-AND-CONTROL-NEXT: [[TMP15:%.*]] = call nnan float @llvm.vector.reduce.fmax.v4f32(<4 x float> [[TMP13]])
; DATA-AND-CONTROL-NEXT: [[TMP16:%.*]] = xor i1 [[TMP8]], true
; DATA-AND-CONTROL-NEXT: br i1 [[TMP16]], label %[[EXIT:.*]], label %[[SCALAR_PH:.*]]
; DATA-AND-CONTROL: [[SCALAR_PH]]:
; DATA-AND-CONTROL-NEXT: br label %[[LOOP:.*]]
; DATA-AND-CONTROL: [[LOOP]]:
; DATA-AND-CONTROL-NEXT: [[IV:%.*]] = phi i64 [ [[TMP14]], %[[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
; DATA-AND-CONTROL-NEXT: [[MAX:%.*]] = phi float [ [[TMP15]], %[[SCALAR_PH]] ], [ [[MAX_NEXT:%.*]], %[[LOOP]] ]
; DATA-AND-CONTROL-NEXT: [[GEP_SRC:%.*]] = getelementptr inbounds nuw float, ptr [[SRC]], i64 [[IV]]
; DATA-AND-CONTROL-NEXT: [[L:%.*]] = load float, ptr [[GEP_SRC]], align 4
; DATA-AND-CONTROL-NEXT: [[CMP:%.*]] = fcmp ogt float [[MAX]], [[L]]
; DATA-AND-CONTROL-NEXT: [[MAX_NEXT]] = select ninf i1 [[CMP]], float [[MAX]], float [[L]]
; DATA-AND-CONTROL-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
; DATA-AND-CONTROL-NEXT: [[EC:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
; DATA-AND-CONTROL-NEXT: br i1 [[EC]], label %[[EXIT]], label %[[LOOP]], !llvm.loop [[LOOP5:![0-9]+]]
; DATA-AND-CONTROL: [[EXIT]]:
; DATA-AND-CONTROL-NEXT: [[MAX_NEXT_LCSSA:%.*]] = phi float [ [[MAX_NEXT]], %[[LOOP]] ], [ [[TMP15]], %[[MIDDLE_BLOCK]] ]
; DATA-AND-CONTROL-NEXT: ret float [[MAX_NEXT_LCSSA]]
;
entry:
br label %loop
loop:
%iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
%max = phi float [ 0xFFF0000000000000, %entry ], [ %max.next, %loop ]
%gep.src = getelementptr inbounds nuw float, ptr %src, i64 %iv
%l = load float, ptr %gep.src, align 4
%cmp = fcmp ogt float %max, %l
%max.next = select ninf i1 %cmp, float %max, float %l
%iv.next = add nuw nsw i64 %iv, 1
%ec = icmp eq i64 %iv.next, %n
br i1 %ec, label %exit, label %loop
exit:
ret float %max.next
}
; Select-based max reduction with tail folding and a start value that may be
; NaN.
define float @fmax_ogt_with_select_start_arg(ptr %src, float %start, i64 %n) {
; CHECK-LABEL: define float @fmax_ogt_with_select_start_arg(
; CHECK-SAME: ptr [[SRC:%.*]], float [[START:%.*]], i64 [[N:%.*]]) {
; CHECK-NEXT: [[ENTRY:.*]]:
; CHECK-NEXT: br label %[[LOOP:.*]]
; CHECK: [[LOOP]]:
; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
; CHECK-NEXT: [[MAX:%.*]] = phi float [ [[START]], %[[ENTRY]] ], [ [[MAX_NEXT:%.*]], %[[LOOP]] ]
; CHECK-NEXT: [[GEP_SRC:%.*]] = getelementptr inbounds nuw float, ptr [[SRC]], i64 [[IV]]
; CHECK-NEXT: [[L:%.*]] = load float, ptr [[GEP_SRC]], align 4
; CHECK-NEXT: [[CMP:%.*]] = fcmp ogt float [[MAX]], [[L]]
; CHECK-NEXT: [[MAX_NEXT]] = select i1 [[CMP]], float [[MAX]], float [[L]]
; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
; CHECK-NEXT: [[EC:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
; CHECK-NEXT: br i1 [[EC]], label %[[EXIT:.*]], label %[[LOOP]]
; CHECK: [[EXIT]]:
; CHECK-NEXT: [[MAX_NEXT_LCSSA:%.*]] = phi float [ [[MAX_NEXT]], %[[LOOP]] ]
; CHECK-NEXT: ret float [[MAX_NEXT_LCSSA]]
;
entry:
br label %loop
loop:
%iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
%max = phi float [ %start, %entry ], [ %max.next, %loop ]
%gep.src = getelementptr inbounds nuw float, ptr %src, i64 %iv
%l = load float, ptr %gep.src, align 4
%cmp = fcmp ogt float %max, %l
%max.next = select i1 %cmp, float %max, float %l
%iv.next = add nuw nsw i64 %iv, 1
%ec = icmp eq i64 %iv.next, %n
br i1 %ec, label %exit, label %loop
exit:
ret float %max.next
}