Skip to content

Commit b9a58cf

Browse files
topperctomtor
authored andcommitted
[ConstantFolding] Add support for llvm.atan in constant folding. (llvm#143416)
Fixes llvm#143360
1 parent a7b7ace commit b9a58cf

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1672,6 +1672,7 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) {
16721672
case Intrinsic::sincos:
16731673
case Intrinsic::sinh:
16741674
case Intrinsic::cosh:
1675+
case Intrinsic::atan:
16751676
case Intrinsic::pow:
16761677
case Intrinsic::powi:
16771678
case Intrinsic::ldexp:
@@ -2538,6 +2539,8 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
25382539
return ConstantFoldFP(sinh, APF, Ty);
25392540
case Intrinsic::cosh:
25402541
return ConstantFoldFP(cosh, APF, Ty);
2542+
case Intrinsic::atan:
2543+
return ConstantFoldFP(atan, APF, Ty);
25412544
case Intrinsic::sqrt:
25422545
return ConstantFoldFP(sqrt, APF, Ty);
25432546
case Intrinsic::amdgcn_cos:
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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_atan_0() {
5+
; CHECK-LABEL: define double @test_atan_0() {
6+
; CHECK-NEXT: ret double 0.000000e+00
7+
;
8+
%result = call double @llvm.atan.f64(double 0.0)
9+
ret double %result
10+
}
11+
12+
define double @test_atan_one() {
13+
; CHECK-LABEL: define double @test_atan_one() {
14+
; CHECK-NEXT: ret double 0x3FE921FB54442D18
15+
;
16+
%res = call double @llvm.atan.f64(double 1.0)
17+
ret double %res
18+
}
19+
20+
define <2 x double> @test_atan_v2() {
21+
; CHECK-LABEL: define <2 x double> @test_atan_v2() {
22+
; CHECK-NEXT: ret <2 x double> zeroinitializer
23+
;
24+
%result = call <2 x double> @llvm.atan.v2f64(<2 x double> zeroinitializer)
25+
ret <2 x double> %result
26+
}
27+
28+
define double @test_atan_neg0() {
29+
; CHECK-LABEL: define double @test_atan_neg0() {
30+
; CHECK-NEXT: ret double -0.000000e+00
31+
;
32+
%res = call double @llvm.atan.f64(double -0.0)
33+
ret double %res
34+
}
35+
36+
define double @test_atan_poison() {
37+
; CHECK-LABEL: define double @test_atan_poison() {
38+
; CHECK-NEXT: [[RES:%.*]] = call double @llvm.atan.f64(double poison)
39+
; CHECK-NEXT: ret double [[RES]]
40+
;
41+
%res = call double @llvm.atan.f64(double poison)
42+
ret double %res
43+
}
44+
45+
define double @test_atan_undef() {
46+
; CHECK-LABEL: define double @test_atan_undef() {
47+
; CHECK-NEXT: [[RES:%.*]] = call double @llvm.atan.f64(double undef)
48+
; CHECK-NEXT: ret double [[RES]]
49+
;
50+
%res = call double @llvm.atan.f64(double undef)
51+
ret double %res
52+
}
53+
54+
define double @test_atan_snan() {
55+
; CHECK-LABEL: define double @test_atan_snan() {
56+
; CHECK-NEXT: [[RES:%.*]] = call double @llvm.atan.f64(double 0x7FF0000000000001)
57+
; CHECK-NEXT: ret double [[RES]]
58+
;
59+
%res = call double @llvm.atan.f64(double 0x7ff0000000000001)
60+
ret double %res
61+
}
62+
63+
define double @test_atan_qnan() {
64+
; CHECK-LABEL: define double @test_atan_qnan() {
65+
; CHECK-NEXT: [[RES:%.*]] = call double @llvm.atan.f64(double 0x7FF8000000000000)
66+
; CHECK-NEXT: ret double [[RES]]
67+
;
68+
%res = call double @llvm.atan.f64(double 0x7ff8000000000000)
69+
ret double %res
70+
}
71+
72+
define double @test_atan_pos_inf() {
73+
; CHECK-LABEL: define double @test_atan_pos_inf() {
74+
; CHECK-NEXT: [[RES:%.*]] = call double @llvm.atan.f64(double 0x7FF0000000000000)
75+
; CHECK-NEXT: ret double [[RES]]
76+
;
77+
%res = call double @llvm.atan.f64(double 0x7ff0000000000000)
78+
ret double %res
79+
}
80+
81+
define double @test_atan_neg_inf() {
82+
; CHECK-LABEL: define double @test_atan_neg_inf() {
83+
; CHECK-NEXT: [[RES:%.*]] = call double @llvm.atan.f64(double 0xFFF0000000000000)
84+
; CHECK-NEXT: ret double [[RES]]
85+
;
86+
%res = call double @llvm.atan.f64(double 0xfff0000000000000)
87+
ret double %res
88+
}

0 commit comments

Comments
 (0)