Skip to content

Commit 3295970

Browse files
authored
[ConstantFolding] Add support for sinh and cosh intrinsics in constant folding (llvm#132671)
Closes llvm#132503.
1 parent 7e65944 commit 3295970

File tree

2 files changed

+180
-0
lines changed

2 files changed

+180
-0
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,8 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) {
16511651
case Intrinsic::sin:
16521652
case Intrinsic::cos:
16531653
case Intrinsic::sincos:
1654+
case Intrinsic::sinh:
1655+
case Intrinsic::cosh:
16541656
case Intrinsic::pow:
16551657
case Intrinsic::powi:
16561658
case Intrinsic::ldexp:
@@ -2513,6 +2515,10 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
25132515
return ConstantFoldFP(sin, APF, Ty);
25142516
case Intrinsic::cos:
25152517
return ConstantFoldFP(cos, APF, Ty);
2518+
case Intrinsic::sinh:
2519+
return ConstantFoldFP(sinh, APF, Ty);
2520+
case Intrinsic::cosh:
2521+
return ConstantFoldFP(cosh, APF, Ty);
25162522
case Intrinsic::sqrt:
25172523
return ConstantFoldFP(sqrt, APF, Ty);
25182524
case Intrinsic::amdgcn_cos:
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -S -passes=instsimplify < %s | FileCheck %s
3+
4+
define double @test_sinh_0() {
5+
; CHECK-LABEL: define double @test_sinh_0() {
6+
; CHECK-NEXT: ret double 0.000000e+00
7+
;
8+
%result = call double @llvm.sinh.f64(double 0.0)
9+
ret double %result
10+
}
11+
12+
define double @test_sinh_ln2() {
13+
; CHECK-LABEL: define double @test_sinh_ln2() {
14+
; CHECK-NEXT: ret double 7.500000e-01
15+
;
16+
%res = call double @llvm.sinh.f64(double 0x3fe62e42fefa39ef)
17+
ret double %res
18+
}
19+
20+
define <2 x double> @test_sinh_v2() {
21+
; CHECK-LABEL: define <2 x double> @test_sinh_v2() {
22+
; CHECK-NEXT: ret <2 x double> zeroinitializer
23+
;
24+
%result = call <2 x double> @llvm.sinh.v2f64(<2 x double> zeroinitializer)
25+
ret <2 x double> %result
26+
}
27+
28+
define double @test_sinh_neg0() {
29+
; CHECK-LABEL: define double @test_sinh_neg0() {
30+
; CHECK-NEXT: ret double -0.000000e+00
31+
;
32+
%res = call double @llvm.sinh.f64(double -0.0)
33+
ret double %res
34+
}
35+
36+
define double @test_sinh_poison() {
37+
; CHECK-LABEL: define double @test_sinh_poison() {
38+
; CHECK-NEXT: [[RES:%.*]] = call double @llvm.sinh.f64(double poison)
39+
; CHECK-NEXT: ret double [[RES]]
40+
;
41+
%res = call double @llvm.sinh.f64(double poison)
42+
ret double %res
43+
}
44+
45+
define double @test_sinh_undef() {
46+
; CHECK-LABEL: define double @test_sinh_undef() {
47+
; CHECK-NEXT: [[RES:%.*]] = call double @llvm.sinh.f64(double undef)
48+
; CHECK-NEXT: ret double [[RES]]
49+
;
50+
%res = call double @llvm.sinh.f64(double undef)
51+
ret double %res
52+
}
53+
54+
define double @test_sinh_snan() {
55+
; CHECK-LABEL: define double @test_sinh_snan() {
56+
; CHECK-NEXT: [[RES:%.*]] = call double @llvm.sinh.f64(double 0x7FF0000000000001)
57+
; CHECK-NEXT: ret double [[RES]]
58+
;
59+
%res = call double @llvm.sinh.f64(double 0x7ff0000000000001)
60+
ret double %res
61+
}
62+
63+
define double @test_sinh_qnan() {
64+
; CHECK-LABEL: define double @test_sinh_qnan() {
65+
; CHECK-NEXT: [[RES:%.*]] = call double @llvm.sinh.f64(double 0x7FF8000000000000)
66+
; CHECK-NEXT: ret double [[RES]]
67+
;
68+
%res = call double @llvm.sinh.f64(double 0x7ff8000000000000)
69+
ret double %res
70+
}
71+
72+
define double @test_sinh_pos_inf() {
73+
; CHECK-LABEL: define double @test_sinh_pos_inf() {
74+
; CHECK-NEXT: [[RES:%.*]] = call double @llvm.sinh.f64(double 0x7FF0000000000000)
75+
; CHECK-NEXT: ret double [[RES]]
76+
;
77+
%res = call double @llvm.sinh.f64(double 0x7ff0000000000000)
78+
ret double %res
79+
}
80+
81+
define double @test_sinh_neg_inf() {
82+
; CHECK-LABEL: define double @test_sinh_neg_inf() {
83+
; CHECK-NEXT: [[RES:%.*]] = call double @llvm.sinh.f64(double 0xFFF0000000000000)
84+
; CHECK-NEXT: ret double [[RES]]
85+
;
86+
%res = call double @llvm.sinh.f64(double 0xfff0000000000000)
87+
ret double %res
88+
}
89+
90+
define double @test_cosh_0() {
91+
; CHECK-LABEL: define double @test_cosh_0() {
92+
; CHECK-NEXT: ret double 1.000000e+00
93+
;
94+
%result = call double @llvm.cosh.f64(double 0.0)
95+
ret double %result
96+
}
97+
98+
define double @test_cosh_ln2() {
99+
; CHECK-LABEL: define double @test_cosh_ln2() {
100+
; CHECK-NEXT: ret double 1.250000e+00
101+
;
102+
%res = call double @llvm.cosh.f64(double 0x3fe62e42fefa39ef)
103+
ret double %res
104+
}
105+
106+
define <2 x double> @test_cosh_v2() {
107+
; CHECK-LABEL: define <2 x double> @test_cosh_v2() {
108+
; CHECK-NEXT: ret <2 x double> splat (double 1.000000e+00)
109+
;
110+
%result = call <2 x double> @llvm.cosh.v2f64(<2 x double> zeroinitializer)
111+
ret <2 x double> %result
112+
}
113+
114+
define double @test_cosh_neg0() {
115+
; CHECK-LABEL: define double @test_cosh_neg0() {
116+
; CHECK-NEXT: ret double 1.000000e+00
117+
;
118+
%res = call double @llvm.cosh.f64(double -0.0)
119+
ret double %res
120+
}
121+
122+
define double @test_cosh_poison() {
123+
; CHECK-LABEL: define double @test_cosh_poison() {
124+
; CHECK-NEXT: [[RES:%.*]] = call double @llvm.cosh.f64(double poison)
125+
; CHECK-NEXT: ret double [[RES]]
126+
;
127+
%res = call double @llvm.cosh.f64(double poison)
128+
ret double %res
129+
}
130+
131+
define double @test_cosh_undef() {
132+
; CHECK-LABEL: define double @test_cosh_undef() {
133+
; CHECK-NEXT: [[RES:%.*]] = call double @llvm.cosh.f64(double undef)
134+
; CHECK-NEXT: ret double [[RES]]
135+
;
136+
%res = call double @llvm.cosh.f64(double undef)
137+
ret double %res
138+
}
139+
140+
define double @test_cosh_snan() {
141+
; CHECK-LABEL: define double @test_cosh_snan() {
142+
; CHECK-NEXT: [[RES:%.*]] = call double @llvm.cosh.f64(double 0x7FF0000000000001)
143+
; CHECK-NEXT: ret double [[RES]]
144+
;
145+
%res = call double @llvm.cosh.f64(double 0x7ff0000000000001)
146+
ret double %res
147+
}
148+
149+
define double @test_cosh_qnan() {
150+
; CHECK-LABEL: define double @test_cosh_qnan() {
151+
; CHECK-NEXT: [[RES:%.*]] = call double @llvm.cosh.f64(double 0x7FF8000000000000)
152+
; CHECK-NEXT: ret double [[RES]]
153+
;
154+
%res = call double @llvm.cosh.f64(double 0x7ff8000000000000)
155+
ret double %res
156+
}
157+
158+
define double @test_cosh_pos_inf() {
159+
; CHECK-LABEL: define double @test_cosh_pos_inf() {
160+
; CHECK-NEXT: [[RES:%.*]] = call double @llvm.cosh.f64(double 0x7FF0000000000000)
161+
; CHECK-NEXT: ret double [[RES]]
162+
;
163+
%res = call double @llvm.cosh.f64(double 0x7ff0000000000000)
164+
ret double %res
165+
}
166+
167+
define double @test_cosh_neg_inf() {
168+
; CHECK-LABEL: define double @test_cosh_neg_inf() {
169+
; CHECK-NEXT: [[RES:%.*]] = call double @llvm.cosh.f64(double 0xFFF0000000000000)
170+
; CHECK-NEXT: ret double [[RES]]
171+
;
172+
%res = call double @llvm.cosh.f64(double 0xfff0000000000000)
173+
ret double %res
174+
}

0 commit comments

Comments
 (0)