Skip to content

Commit beabe4e

Browse files
committed
[InstSimplify][InstCombine] Add regresion tests for C23 math functions
1 parent adb7275 commit beabe4e

File tree

2 files changed

+201
-0
lines changed

2 files changed

+201
-0
lines changed

llvm/test/Transforms/InstCombine/float-shrink-compare.ll

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,40 @@ define i1 @test18(float %x, float %y, float %z) {
463463
ret i1 %5
464464
}
465465

466+
define i1 @test_fminimum_num(float %x, float %y, float %z) {
467+
; CHECK-LABEL: @test_fminimum_num(
468+
; CHECK-NEXT: [[TMP1:%.*]] = fpext float [[X:%.*]] to double
469+
; CHECK-NEXT: [[TMP2:%.*]] = fpext float [[Y:%.*]] to double
470+
; CHECK-NEXT: [[TMP3:%.*]] = call double @fminimum_num(double [[TMP1]], double [[TMP2]]) #[[ATTR3:[0-9]+]]
471+
; CHECK-NEXT: [[TMP4:%.*]] = fpext float [[Z:%.*]] to double
472+
; CHECK-NEXT: [[TMP5:%.*]] = fcmp oeq double [[TMP3]], [[TMP4]]
473+
; CHECK-NEXT: ret i1 [[TMP5]]
474+
;
475+
%1 = fpext float %x to double
476+
%2 = fpext float %y to double
477+
%3 = call double @fminimum_num(double %1, double %2) nounwind
478+
%4 = fpext float %z to double
479+
%5 = fcmp oeq double %3, %4
480+
ret i1 %5
481+
}
482+
483+
define i1 @test_fmaximum_num(float %x, float %y, float %z) {
484+
; CHECK-LABEL: @test_fmaximum_num(
485+
; CHECK-NEXT: [[TMP1:%.*]] = fpext float [[X:%.*]] to double
486+
; CHECK-NEXT: [[TMP2:%.*]] = fpext float [[Y:%.*]] to double
487+
; CHECK-NEXT: [[TMP3:%.*]] = call double @fmaximum_num(double [[TMP1]], double [[TMP2]]) #[[ATTR3]]
488+
; CHECK-NEXT: [[TMP4:%.*]] = fpext float [[Z:%.*]] to double
489+
; CHECK-NEXT: [[TMP5:%.*]] = fcmp oeq double [[TMP3]], [[TMP4]]
490+
; CHECK-NEXT: ret i1 [[TMP5]]
491+
;
492+
%1 = fpext float %x to double
493+
%2 = fpext float %y to double
494+
%3 = call double @fmaximum_num(double %1, double %2) nounwind
495+
%4 = fpext float %z to double
496+
%5 = fcmp oeq double %3, %4
497+
ret i1 %5
498+
}
499+
466500
define i1 @test19(float %x, float %y, float %z) {
467501
; CHECK-LABEL: @test19(
468502
; CHECK-NEXT: [[COPYSIGNF:%.*]] = call float @copysignf(float [[X:%.*]], float [[Y:%.*]]) #[[ATTR0:[0-9]+]]
@@ -518,6 +552,8 @@ declare double @roundeven(double) nounwind readnone
518552
declare double @trunc(double) nounwind readnone
519553
declare double @fmin(double, double) nounwind readnone
520554
declare double @fmax(double, double) nounwind readnone
555+
declare double @fminimum_num(double, double) nounwind readnone
556+
declare double @fmaximum_num(double, double) nounwind readnone
521557

522558
declare double @llvm.fabs.f64(double) nounwind readnone
523559
declare double @llvm.ceil.f64(double) nounwind readnone
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
2+
; RUN: opt -S -passes=early-cse -earlycse-debug-hash < %s | FileCheck %s
3+
4+
declare float @roundevenf(float) #0
5+
declare float @llvm.roundeven.f32(float)
6+
declare double @roundeven(double) #0
7+
declare double @llvm.roundeven.f64(double)
8+
9+
define float @constant_fold_roundeven_f32_01() #0 {
10+
; CHECK-LABEL: define float @constant_fold_roundeven_f32_01(
11+
; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
12+
; CHECK-NEXT: [[X:%.*]] = call float @roundevenf(float 1.250000e+00) #[[ATTR0]]
13+
; CHECK-NEXT: ret float [[X]]
14+
;
15+
%x = call float @roundevenf(float 1.25) #0
16+
ret float %x
17+
}
18+
19+
define float @constant_fold_roundeven_f32_02() #0 {
20+
; CHECK-LABEL: define float @constant_fold_roundeven_f32_02(
21+
; CHECK-SAME: ) #[[ATTR0]] {
22+
; CHECK-NEXT: ret float -1.000000e+00
23+
;
24+
%x = call float @llvm.roundeven.f32(float -1.25) #0
25+
ret float %x
26+
}
27+
28+
; roundeven rounds ties to even, so 1.5 -> 2.0 (nearest even)
29+
define float @constant_fold_roundeven_f32_03() #0 {
30+
; CHECK-LABEL: define float @constant_fold_roundeven_f32_03(
31+
; CHECK-SAME: ) #[[ATTR0]] {
32+
; CHECK-NEXT: [[X:%.*]] = call float @roundevenf(float 1.500000e+00) #[[ATTR0]]
33+
; CHECK-NEXT: ret float [[X]]
34+
;
35+
%x = call float @roundevenf(float 1.5) #0
36+
ret float %x
37+
}
38+
39+
; roundeven rounds ties to even, so -1.5 -> -2.0 (nearest even)
40+
define float @constant_fold_roundeven_f32_04() #0 {
41+
; CHECK-LABEL: define float @constant_fold_roundeven_f32_04(
42+
; CHECK-SAME: ) #[[ATTR0]] {
43+
; CHECK-NEXT: ret float -2.000000e+00
44+
;
45+
%x = call float @llvm.roundeven.f32(float -1.5) #0
46+
ret float %x
47+
}
48+
49+
; roundeven rounds ties to even, so 2.5 -> 2.0 (nearest even)
50+
define float @constant_fold_roundeven_f32_05() #0 {
51+
; CHECK-LABEL: define float @constant_fold_roundeven_f32_05(
52+
; CHECK-SAME: ) #[[ATTR0]] {
53+
; CHECK-NEXT: [[X:%.*]] = call float @roundevenf(float 2.500000e+00) #[[ATTR0]]
54+
; CHECK-NEXT: ret float [[X]]
55+
;
56+
%x = call float @roundevenf(float 2.5) #0
57+
ret float %x
58+
}
59+
60+
; roundeven rounds ties to even, so -2.5 -> -2.0 (nearest even)
61+
define float @constant_fold_roundeven_f32_06() #0 {
62+
; CHECK-LABEL: define float @constant_fold_roundeven_f32_06(
63+
; CHECK-SAME: ) #[[ATTR0]] {
64+
; CHECK-NEXT: ret float -2.000000e+00
65+
;
66+
%x = call float @llvm.roundeven.f32(float -2.5) #0
67+
ret float %x
68+
}
69+
70+
define float @constant_fold_roundeven_f32_07() #0 {
71+
; CHECK-LABEL: define float @constant_fold_roundeven_f32_07(
72+
; CHECK-SAME: ) #[[ATTR0]] {
73+
; CHECK-NEXT: [[X:%.*]] = call float @roundevenf(float 2.750000e+00) #[[ATTR0]]
74+
; CHECK-NEXT: ret float [[X]]
75+
;
76+
%x = call float @roundevenf(float 2.75) #0
77+
ret float %x
78+
}
79+
80+
define float @constant_fold_roundeven_f32_08() #0 {
81+
; CHECK-LABEL: define float @constant_fold_roundeven_f32_08(
82+
; CHECK-SAME: ) #[[ATTR0]] {
83+
; CHECK-NEXT: ret float -3.000000e+00
84+
;
85+
%x = call float @llvm.roundeven.f32(float -2.75) #0
86+
ret float %x
87+
}
88+
89+
define double @constant_fold_roundeven_f64_01() #0 {
90+
; CHECK-LABEL: define double @constant_fold_roundeven_f64_01(
91+
; CHECK-SAME: ) #[[ATTR0]] {
92+
; CHECK-NEXT: [[X:%.*]] = call double @roundeven(double 1.300000e+00) #[[ATTR0]]
93+
; CHECK-NEXT: ret double [[X]]
94+
;
95+
%x = call double @roundeven(double 1.3) #0
96+
ret double %x
97+
}
98+
99+
define double @constant_fold_roundeven_f64_02() #0 {
100+
; CHECK-LABEL: define double @constant_fold_roundeven_f64_02(
101+
; CHECK-SAME: ) #[[ATTR0]] {
102+
; CHECK-NEXT: ret double -1.000000e+00
103+
;
104+
%x = call double @llvm.roundeven.f64(double -1.3) #0
105+
ret double %x
106+
}
107+
108+
define double @constant_fold_roundeven_f64_03() #0 {
109+
; CHECK-LABEL: define double @constant_fold_roundeven_f64_03(
110+
; CHECK-SAME: ) #[[ATTR0]] {
111+
; CHECK-NEXT: [[X:%.*]] = call double @roundeven(double 1.500000e+00) #[[ATTR0]]
112+
; CHECK-NEXT: ret double [[X]]
113+
;
114+
%x = call double @roundeven(double 1.5) #0
115+
ret double %x
116+
}
117+
118+
define double @constant_fold_roundeven_f64_04() #0 {
119+
; CHECK-LABEL: define double @constant_fold_roundeven_f64_04(
120+
; CHECK-SAME: ) #[[ATTR0]] {
121+
; CHECK-NEXT: ret double -2.000000e+00
122+
;
123+
%x = call double @llvm.roundeven.f64(double -1.5) #0
124+
ret double %x
125+
}
126+
127+
define double @constant_fold_roundeven_f64_05() #0 {
128+
; CHECK-LABEL: define double @constant_fold_roundeven_f64_05(
129+
; CHECK-SAME: ) #[[ATTR0]] {
130+
; CHECK-NEXT: [[X:%.*]] = call double @roundeven(double 2.500000e+00) #[[ATTR0]]
131+
; CHECK-NEXT: ret double [[X]]
132+
;
133+
%x = call double @roundeven(double 2.5) #0
134+
ret double %x
135+
}
136+
137+
define double @constant_fold_roundeven_f64_06() #0 {
138+
; CHECK-LABEL: define double @constant_fold_roundeven_f64_06(
139+
; CHECK-SAME: ) #[[ATTR0]] {
140+
; CHECK-NEXT: ret double -2.000000e+00
141+
;
142+
%x = call double @llvm.roundeven.f64(double -2.5) #0
143+
ret double %x
144+
}
145+
146+
define double @constant_fold_roundeven_f64_07() #0 {
147+
; CHECK-LABEL: define double @constant_fold_roundeven_f64_07(
148+
; CHECK-SAME: ) #[[ATTR0]] {
149+
; CHECK-NEXT: [[X:%.*]] = call double @roundeven(double 2.700000e+00) #[[ATTR0]]
150+
; CHECK-NEXT: ret double [[X]]
151+
;
152+
%x = call double @roundeven(double 2.7) #0
153+
ret double %x
154+
}
155+
156+
define double @constant_fold_roundeven_f64_08() #0 {
157+
; CHECK-LABEL: define double @constant_fold_roundeven_f64_08(
158+
; CHECK-SAME: ) #[[ATTR0]] {
159+
; CHECK-NEXT: ret double -3.000000e+00
160+
;
161+
%x = call double @llvm.roundeven.f64(double -2.7) #0
162+
ret double %x
163+
}
164+
165+
attributes #0 = { nounwind readnone willreturn }

0 commit comments

Comments
 (0)