Skip to content

Commit 2b2bc63

Browse files
committed
[LV] Add tests with multiple F(Max|Min)Num reductions w/o fast-math.
Pre-commits extra test coverage for loops with multiple F(Max|Min)Num reductions w/o fast-math-flags for follow-up PR.
1 parent a035ef4 commit 2b2bc63

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed

llvm/test/Transforms/LoopVectorize/AArch64/fmax-without-fast-math-flags.ll

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,49 @@ loop:
113113
exit:
114114
ret float %max.next
115115
}
116+
117+
define float @test_fmax_and_fmin(ptr %src.0, ptr %src.1, i64 %n) {
118+
; CHECK-LABEL: define float @test_fmax_and_fmin(
119+
; CHECK-SAME: ptr [[SRC_0:%.*]], ptr [[SRC_1:%.*]], i64 [[N:%.*]]) {
120+
; CHECK-NEXT: [[ENTRY:.*]]:
121+
; CHECK-NEXT: br label %[[LOOP:.*]]
122+
; CHECK: [[LOOP]]:
123+
; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
124+
; CHECK-NEXT: [[MIN:%.*]] = phi float [ 0.000000e+00, %[[ENTRY]] ], [ [[MIN_NEXT:%.*]], %[[LOOP]] ]
125+
; CHECK-NEXT: [[MAX:%.*]] = phi float [ 0.000000e+00, %[[ENTRY]] ], [ [[MAX_NEXT:%.*]], %[[LOOP]] ]
126+
; CHECK-NEXT: [[GEP_SRC_0:%.*]] = getelementptr inbounds nuw float, ptr [[SRC_0]], i64 [[IV]]
127+
; CHECK-NEXT: [[GEP_SRC_1:%.*]] = getelementptr inbounds nuw float, ptr [[SRC_1]], i64 [[IV]]
128+
; CHECK-NEXT: [[L_0:%.*]] = load float, ptr [[GEP_SRC_0]], align 4
129+
; CHECK-NEXT: [[L_1:%.*]] = load float, ptr [[GEP_SRC_1]], align 4
130+
; CHECK-NEXT: [[MAX_NEXT]] = tail call noundef float @llvm.maxnum.f32(float [[MAX]], float [[L_0]])
131+
; CHECK-NEXT: [[MIN_NEXT]] = tail call noundef float @llvm.minnum.f32(float [[MIN]], float [[L_1]])
132+
; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
133+
; CHECK-NEXT: [[EC:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
134+
; CHECK-NEXT: br i1 [[EC]], label %[[EXIT:.*]], label %[[LOOP]]
135+
; CHECK: [[EXIT]]:
136+
; CHECK-NEXT: [[MAX_NEXT_LCSSA:%.*]] = phi float [ [[MAX_NEXT]], %[[LOOP]] ]
137+
; CHECK-NEXT: [[MIN_NEXT_LCSSA:%.*]] = phi float [ [[MIN_NEXT]], %[[LOOP]] ]
138+
; CHECK-NEXT: [[SUB:%.*]] = fsub float [[MAX_NEXT_LCSSA]], [[MIN_NEXT_LCSSA]]
139+
; CHECK-NEXT: ret float [[SUB]]
140+
;
141+
entry:
142+
br label %loop
143+
144+
loop:
145+
%iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
146+
%min = phi float [ 0.000000e+00, %entry ], [ %min.next, %loop ]
147+
%max = phi float [ 0.000000e+00, %entry ], [ %max.next, %loop ]
148+
%gep.src.0 = getelementptr inbounds nuw float, ptr %src.0, i64 %iv
149+
%gep.src.1 = getelementptr inbounds nuw float, ptr %src.1, i64 %iv
150+
%l.0 = load float, ptr %gep.src.0, align 4
151+
%l.1 = load float, ptr %gep.src.1, align 4
152+
%max.next = tail call noundef float @llvm.maxnum.f32(float %max, float %l.0)
153+
%min.next = tail call noundef float @llvm.minnum.f32(float %min, float %l.1)
154+
%iv.next = add nuw nsw i64 %iv, 1
155+
%ec = icmp eq i64 %iv.next, %n
156+
br i1 %ec, label %exit, label %loop
157+
158+
exit:
159+
%sub = fsub float %max.next, %min.next
160+
ret float %sub
161+
}

llvm/test/Transforms/LoopVectorize/fmax-without-fast-math-flags-interleave.ll

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,49 @@ loop:
113113
exit:
114114
ret float %max.next
115115
}
116+
117+
define float @test_fmax_and_fmin(ptr %src.0, ptr %src.1, i64 %n) {
118+
; CHECK-LABEL: define float @test_fmax_and_fmin(
119+
; CHECK-SAME: ptr [[SRC_0:%.*]], ptr [[SRC_1:%.*]], i64 [[N:%.*]]) {
120+
; CHECK-NEXT: [[ENTRY:.*]]:
121+
; CHECK-NEXT: br label %[[LOOP:.*]]
122+
; CHECK: [[LOOP]]:
123+
; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
124+
; CHECK-NEXT: [[MIN:%.*]] = phi float [ 0.000000e+00, %[[ENTRY]] ], [ [[MIN_NEXT:%.*]], %[[LOOP]] ]
125+
; CHECK-NEXT: [[MAX:%.*]] = phi float [ 0.000000e+00, %[[ENTRY]] ], [ [[MAX_NEXT:%.*]], %[[LOOP]] ]
126+
; CHECK-NEXT: [[GEP_SRC_0:%.*]] = getelementptr inbounds nuw float, ptr [[SRC_0]], i64 [[IV]]
127+
; CHECK-NEXT: [[GEP_SRC_1:%.*]] = getelementptr inbounds nuw float, ptr [[SRC_1]], i64 [[IV]]
128+
; CHECK-NEXT: [[L_0:%.*]] = load float, ptr [[GEP_SRC_0]], align 4
129+
; CHECK-NEXT: [[L_1:%.*]] = load float, ptr [[GEP_SRC_1]], align 4
130+
; CHECK-NEXT: [[MAX_NEXT]] = tail call noundef float @llvm.maxnum.f32(float [[MAX]], float [[L_0]])
131+
; CHECK-NEXT: [[MIN_NEXT]] = tail call noundef float @llvm.minnum.f32(float [[MIN]], float [[L_1]])
132+
; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
133+
; CHECK-NEXT: [[EC:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
134+
; CHECK-NEXT: br i1 [[EC]], label %[[EXIT:.*]], label %[[LOOP]]
135+
; CHECK: [[EXIT]]:
136+
; CHECK-NEXT: [[MAX_NEXT_LCSSA:%.*]] = phi float [ [[MAX_NEXT]], %[[LOOP]] ]
137+
; CHECK-NEXT: [[MIN_NEXT_LCSSA:%.*]] = phi float [ [[MIN_NEXT]], %[[LOOP]] ]
138+
; CHECK-NEXT: [[SUB:%.*]] = fsub float [[MAX_NEXT_LCSSA]], [[MIN_NEXT_LCSSA]]
139+
; CHECK-NEXT: ret float [[SUB]]
140+
;
141+
entry:
142+
br label %loop
143+
144+
loop:
145+
%iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
146+
%min = phi float [ 0.000000e+00, %entry ], [ %min.next, %loop ]
147+
%max = phi float [ 0.000000e+00, %entry ], [ %max.next, %loop ]
148+
%gep.src.0 = getelementptr inbounds nuw float, ptr %src.0, i64 %iv
149+
%gep.src.1 = getelementptr inbounds nuw float, ptr %src.1, i64 %iv
150+
%l.0 = load float, ptr %gep.src.0, align 4
151+
%l.1 = load float, ptr %gep.src.1, align 4
152+
%max.next = tail call noundef float @llvm.maxnum.f32(float %max, float %l.0)
153+
%min.next = tail call noundef float @llvm.minnum.f32(float %min, float %l.1)
154+
%iv.next = add nuw nsw i64 %iv, 1
155+
%ec = icmp eq i64 %iv.next, %n
156+
br i1 %ec, label %exit, label %loop
157+
158+
exit:
159+
%sub = fsub float %max.next, %min.next
160+
ret float %sub
161+
}

llvm/test/Transforms/LoopVectorize/fmax-without-fast-math-flags.ll

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,3 +683,49 @@ loop:
683683
exit:
684684
ret float %max.next
685685
}
686+
687+
define float @test_fmax_and_fmax(ptr %src.0, ptr %src.1, i64 %n) {
688+
; CHECK-LABEL: define float @test_fmax_and_fmax(
689+
; CHECK-SAME: ptr [[SRC_0:%.*]], ptr [[SRC_1:%.*]], i64 [[N:%.*]]) {
690+
; CHECK-NEXT: [[ENTRY:.*]]:
691+
; CHECK-NEXT: br label %[[LOOP:.*]]
692+
; CHECK: [[LOOP]]:
693+
; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
694+
; CHECK-NEXT: [[MIN:%.*]] = phi float [ 0.000000e+00, %[[ENTRY]] ], [ [[MIN_NEXT:%.*]], %[[LOOP]] ]
695+
; CHECK-NEXT: [[MAX:%.*]] = phi float [ 0.000000e+00, %[[ENTRY]] ], [ [[MAX_NEXT:%.*]], %[[LOOP]] ]
696+
; CHECK-NEXT: [[GEP_SRC_0:%.*]] = getelementptr inbounds nuw float, ptr [[SRC_0]], i64 [[IV]]
697+
; CHECK-NEXT: [[GEP_SRC_1:%.*]] = getelementptr inbounds nuw float, ptr [[SRC_1]], i64 [[IV]]
698+
; CHECK-NEXT: [[L_0:%.*]] = load float, ptr [[GEP_SRC_0]], align 4
699+
; CHECK-NEXT: [[L_1:%.*]] = load float, ptr [[GEP_SRC_1]], align 4
700+
; CHECK-NEXT: [[MAX_NEXT]] = tail call noundef float @llvm.maxnum.f32(float [[MAX]], float [[L_0]])
701+
; CHECK-NEXT: [[MIN_NEXT]] = tail call noundef float @llvm.minnum.f32(float [[MIN]], float [[L_1]])
702+
; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
703+
; CHECK-NEXT: [[EC:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
704+
; CHECK-NEXT: br i1 [[EC]], label %[[EXIT:.*]], label %[[LOOP]]
705+
; CHECK: [[EXIT]]:
706+
; CHECK-NEXT: [[MAX_NEXT_LCSSA:%.*]] = phi float [ [[MAX_NEXT]], %[[LOOP]] ]
707+
; CHECK-NEXT: [[MIN_NEXT_LCSSA:%.*]] = phi float [ [[MIN_NEXT]], %[[LOOP]] ]
708+
; CHECK-NEXT: [[SUB:%.*]] = fsub float [[MAX_NEXT_LCSSA]], [[MIN_NEXT_LCSSA]]
709+
; CHECK-NEXT: ret float [[SUB]]
710+
;
711+
entry:
712+
br label %loop
713+
714+
loop:
715+
%iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
716+
%min = phi float [ 0.000000e+00, %entry ], [ %min.next, %loop ]
717+
%max = phi float [ 0.000000e+00, %entry ], [ %max.next, %loop ]
718+
%gep.src.0 = getelementptr inbounds nuw float, ptr %src.0, i64 %iv
719+
%gep.src.1 = getelementptr inbounds nuw float, ptr %src.1, i64 %iv
720+
%l.0 = load float, ptr %gep.src.0, align 4
721+
%l.1 = load float, ptr %gep.src.1, align 4
722+
%max.next = tail call noundef float @llvm.maxnum.f32(float %max, float %l.0)
723+
%min.next = tail call noundef float @llvm.minnum.f32(float %min, float %l.1)
724+
%iv.next = add nuw nsw i64 %iv, 1
725+
%ec = icmp eq i64 %iv.next, %n
726+
br i1 %ec, label %exit, label %loop
727+
728+
exit:
729+
%sub = fsub float %max.next, %min.next
730+
ret float %sub
731+
}

0 commit comments

Comments
 (0)