xref: /llvm-project/llvm/test/Transforms/InstSimplify/ConstProp/round.ll (revision ac696ac4530fb3df626195e94e83649bf7114754)
1; RUN: opt -S -passes=early-cse -earlycse-debug-hash < %s | FileCheck %s
2
3declare float @roundf(float) #0
4declare float @llvm.round.f32(float)
5declare double @round(double) #0
6declare double @llvm.round.f64(double)
7
8; CHECK-LABEL: @constant_fold_round_f32_01
9; CHECK-NEXT: ret float 1.000000e+00
10define float @constant_fold_round_f32_01() #0 {
11  %x = call float @roundf(float 1.25) #0
12  ret float %x
13}
14
15; CHECK-LABEL: @constant_fold_round_f32_02
16; CHECK-NEXT: ret float -1.000000e+00
17define float @constant_fold_round_f32_02() #0 {
18  %x = call float @llvm.round.f32(float -1.25) #0
19  ret float %x
20}
21
22; CHECK-LABEL: @constant_fold_round_f32_03
23; CHECK-NEXT: ret float 2.000000e+00
24define float @constant_fold_round_f32_03() #0 {
25  %x = call float @roundf(float 1.5) #0
26  ret float %x
27}
28
29; CHECK-LABEL: @constant_fold_round_f32_04
30; CHECK-NEXT: ret float -2.000000e+00
31define float @constant_fold_round_f32_04() #0 {
32  %x = call float @llvm.round.f32(float -1.5) #0
33  ret float %x
34}
35
36; CHECK-LABEL: @constant_fold_round_f32_05
37; CHECK-NEXT: ret float 3.000000e+00
38define float @constant_fold_round_f32_05() #0 {
39  %x = call float @roundf(float 2.75) #0
40  ret float %x
41}
42
43; CHECK-LABEL: @constant_fold_round_f32_06
44; CHECK-NEXT: ret float -3.000000e+00
45define float @constant_fold_round_f32_06() #0 {
46  %x = call float @llvm.round.f32(float -2.75) #0
47  ret float %x
48}
49
50; CHECK-LABEL: @constant_fold_round_f64_01
51; CHECK-NEXT: ret double 1.000000e+00
52define double @constant_fold_round_f64_01() #0 {
53  %x = call double @round(double 1.3) #0
54  ret double %x
55}
56
57; CHECK-LABEL: @constant_fold_round_f64_02
58; CHECK-NEXT: ret double -1.000000e+00
59define double @constant_fold_round_f64_02() #0 {
60  %x = call double @llvm.round.f64(double -1.3) #0
61  ret double %x
62}
63
64; CHECK-LABEL: @constant_fold_round_f64_03
65; CHECK-NEXT: ret double 2.000000e+00
66define double @constant_fold_round_f64_03() #0 {
67  %x = call double @round(double 1.5) #0
68  ret double %x
69}
70
71; CHECK-LABEL: @constant_fold_round_f64_04
72; CHECK-NEXT: ret double -2.000000e+00
73define double @constant_fold_round_f64_04() #0 {
74  %x = call double @llvm.round.f64(double -1.5) #0
75  ret double %x
76}
77
78; CHECK-LABEL: @constant_fold_round_f64_05
79; CHECK-NEXT: ret double 3.000000e+00
80define double @constant_fold_round_f64_05() #0 {
81  %x = call double @round(double 2.7) #0
82  ret double %x
83}
84
85; CHECK-LABEL: @constant_fold_round_f64_06
86; CHECK-NEXT: ret double -3.000000e+00
87define double @constant_fold_round_f64_06() #0 {
88  %x = call double @llvm.round.f64(double -2.7) #0
89  ret double %x
90}
91
92attributes #0 = { nounwind readnone willreturn }
93