Skip to content

Commit bb91f9a

Browse files
committed
update
1 parent 8c345ec commit bb91f9a

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2421,10 +2421,9 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
24212421
case LibFunc_tgamma:
24222422
case LibFunc_tgammaf:
24232423
// NOTE: These boundaries are somewhat conservative.
2424-
if (TLI->has(Func) && (Ty->isDoubleTy() && (APF > APFloat(1 / DBL_MAX) &&
2425-
APF < APFloat(171.0)) ||
2426-
Ty->isFloatTy() && (APF > APFloat(1 / FLT_MAX) &&
2427-
APF < APFloat(35.0f))))
2424+
if (TLI->has(Func) &&
2425+
(Ty->isDoubleTy() && APF > APFloat(DBL_MIN) && APF < APFloat(171.0) ||
2426+
Ty->isFloatTy() && APF > APFloat(FLT_MIN) && APF < APFloat(35.0f)))
24282427
return ConstantFoldFP(tgamma, APF, Ty);
24292428
break;
24302429
case LibFunc_nearbyint:

llvm/test/Transforms/InstCombine/tgamma.ll

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,51 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
22
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
33

4-
define float @tgammaf_const() {
5-
; CHECK-LABEL: define float @tgammaf_const() {
4+
define float @tgammaf_in_range() {
5+
; CHECK-LABEL: define float @tgammaf_in_range() {
66
; CHECK-NEXT: ret float 0x479A216280000000
77
;
88
%r = call float @tgammaf(float 34.0)
99
ret float %r
1010
}
1111

12-
define double @tgamma_const() {
13-
; CHECK-LABEL: define double @tgamma_const() {
12+
define double @tgamma_in_range() {
13+
; CHECK-LABEL: define double @tgamma_in_range() {
1414
; CHECK-NEXT: ret double 0x605166C698CF183B
1515
;
1616
%r = call double @tgamma(double 100.0)
1717
ret double %r
1818
}
1919

20-
define float @tgammaf_const_overflow() {
21-
; CHECK-LABEL: define float @tgammaf_const_overflow() {
20+
define float @tgammaf_const_left_range() {
21+
; CHECK-LABEL: define float @tgammaf_const_left_range() {
22+
; CHECK-NEXT: [[R:%.*]] = call float @tgammaf(float 0x3810000000000000)
23+
; CHECK-NEXT: ret float [[R]]
24+
;
25+
%r = call float @tgammaf(float 0x3810000000000000)
26+
ret float %r
27+
}
28+
29+
define double @tgamma_const_left_range() {
30+
; CHECK-LABEL: define double @tgamma_const_left_range() {
31+
; CHECK-NEXT: [[R:%.*]] = call double @tgamma(double 0x10000000000000)
32+
; CHECK-NEXT: ret double [[R]]
33+
;
34+
%r = call double @tgamma(double 0x0010000000000000)
35+
ret double %r
36+
}
37+
38+
define float @tgammaf_const_right_range() {
39+
; CHECK-LABEL: define float @tgammaf_const_right_range() {
2240
; CHECK-NEXT: [[R:%.*]] = call float @tgammaf(float 3.600000e+01)
2341
; CHECK-NEXT: ret float [[R]]
2442
;
2543
%r = call float @tgammaf(float 36.0)
2644
ret float %r
2745
}
2846

29-
define double @tgamma_const_overflow() {
30-
; CHECK-LABEL: define double @tgamma_const_overflow() {
47+
define double @tgamma_const_right_range() {
48+
; CHECK-LABEL: define double @tgamma_const_right_range() {
3149
; CHECK-NEXT: [[R:%.*]] = call double @tgamma(double 1.720000e+02)
3250
; CHECK-NEXT: ret double [[R]]
3351
;

0 commit comments

Comments
 (0)