Skip to content

Commit 2870c1b

Browse files
committed
Add roundeven* libcalls to remaining analyses
1 parent ce472f4 commit 2870c1b

File tree

7 files changed

+38
-18
lines changed

7 files changed

+38
-18
lines changed

llvm/include/llvm/Analysis/TargetLibraryInfo.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ class TargetLibraryInfo {
417417
case LibFunc_nearbyint: case LibFunc_nearbyintf: case LibFunc_nearbyintl:
418418
case LibFunc_rint: case LibFunc_rintf: case LibFunc_rintl:
419419
case LibFunc_round: case LibFunc_roundf: case LibFunc_roundl:
420+
case LibFunc_roundeven: case LibFunc_roundevenf: case LibFunc_roundevenl:
420421
case LibFunc_sin: case LibFunc_sinf: case LibFunc_sinl:
421422
case LibFunc_sinh: case LibFunc_sinhf: case LibFunc_sinhl:
422423
case LibFunc_sqrt: case LibFunc_sqrtf: case LibFunc_sqrtl:

llvm/lib/Analysis/ConstantFolding.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,6 +1984,7 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) {
19841984
switch (Name[0]) {
19851985
default:
19861986
return false;
1987+
// clang-format off
19871988
case 'a':
19881989
return Name == "acos" || Name == "acosf" ||
19891990
Name == "asin" || Name == "asinf" ||
@@ -2014,7 +2015,8 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) {
20142015
case 'r':
20152016
return Name == "remainder" || Name == "remainderf" ||
20162017
Name == "rint" || Name == "rintf" ||
2017-
Name == "round" || Name == "roundf";
2018+
Name == "round" || Name == "roundf" ||
2019+
Name == "roundeven" || Name == "roundevenf";
20182020
case 's':
20192021
return Name == "sin" || Name == "sinf" ||
20202022
Name == "sinh" || Name == "sinhf" ||
@@ -2052,6 +2054,7 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) {
20522054
case 's':
20532055
return Name == "__sinh_finite" || Name == "__sinhf_finite";
20542056
}
2057+
// clang-format on
20552058
}
20562059
}
20572060

@@ -2516,7 +2519,8 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
25162519

25172520
// Use internal versions of these intrinsics.
25182521

2519-
if (IntrinsicID == Intrinsic::nearbyint || IntrinsicID == Intrinsic::rint) {
2522+
if (IntrinsicID == Intrinsic::nearbyint || IntrinsicID == Intrinsic::rint ||
2523+
IntrinsicID == Intrinsic::roundeven) {
25202524
U.roundToIntegral(APFloat::rmNearestTiesToEven);
25212525
return ConstantFP::get(Ty->getContext(), U);
25222526
}
@@ -2988,6 +2992,8 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
29882992
case LibFunc_nearbyintf:
29892993
case LibFunc_rint:
29902994
case LibFunc_rintf:
2995+
case LibFunc_roundeven:
2996+
case LibFunc_roundevenf:
29912997
if (TLI->has(Func)) {
29922998
U.roundToIntegral(APFloat::rmNearestTiesToEven);
29932999
return ConstantFP::get(Ty->getContext(), U);

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9710,6 +9710,12 @@ void SelectionDAGBuilder::visitCall(const CallInst &I) {
97109710
if (visitUnaryFloatCall(I, ISD::FROUND))
97119711
return;
97129712
break;
9713+
case LibFunc_roundeven:
9714+
case LibFunc_roundevenf:
9715+
case LibFunc_roundevenl:
9716+
if (visitUnaryFloatCall(I, ISD::FROUNDEVEN))
9717+
return;
9718+
break;
97139719
case LibFunc_trunc:
97149720
case LibFunc_truncf:
97159721
case LibFunc_truncl:

llvm/lib/Transforms/Instrumentation/NumericalStabilitySanitizer.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,6 +1514,9 @@ const KnownIntrinsic::LFEntry KnownIntrinsic::kLibfuncIntrinsics[] = {
15141514
{LibFunc_roundf, "llvm.round.f32"},
15151515
{LibFunc_round, "llvm.round.f64"},
15161516
{LibFunc_roundl, "llvm.round.f80"},
1517+
{LibFunc_roundevenf, "llvm.roundeven.f32"},
1518+
{LibFunc_roundeven, "llvm.roundeven.f64"},
1519+
{LibFunc_roundevenl, "llvm.roundeven.f80"},
15171520
};
15181521

15191522
const char *KnownIntrinsic::get(LibFunc LFunc) {

llvm/lib/Transforms/Utils/BuildLibCalls.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,6 +1361,9 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
13611361
case LibFunc_round:
13621362
case LibFunc_roundf:
13631363
case LibFunc_roundl:
1364+
case LibFunc_roundeven:
1365+
case LibFunc_roundevenf:
1366+
case LibFunc_roundevenl:
13641367
case LibFunc_toascii:
13651368
case LibFunc_trunc:
13661369
case LibFunc_truncf:

llvm/test/Transforms/InferFunctionAttrs/annotate.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,15 @@ declare float @roundf(float)
918918
; CHECK: declare x86_fp80 @roundl(x86_fp80) [[MEMNONE_NOFREE_NOUNWIND_WILLRETURN:#[0-9]+]]
919919
declare x86_fp80 @roundl(x86_fp80)
920920

921+
; CHECK: declare double @roundeven(double) [[MEMNONE_NOFREE_NOUNWIND_WILLRETURN:#[0-9]+]]
922+
declare double @roundeven(double)
923+
924+
; CHECK: declare float @roundevenf(float) [[MEMNONE_NOFREE_NOUNWIND_WILLRETURN:#[0-9]+]]
925+
declare float @roundevenf(float)
926+
927+
; CHECK: declare x86_fp80 @roundevenl(x86_fp80) [[MEMNONE_NOFREE_NOUNWIND_WILLRETURN:#[0-9]+]]
928+
declare x86_fp80 @roundevenl(x86_fp80)
929+
921930
; CHECK: declare double @scalbln(double, i64) [[ERRNOMEMONLY_NOFREE_NOUNWIND_WILLRETURN:#[0-9]+]]
922931
declare double @scalbln(double, i64)
923932

llvm/test/Transforms/InstSimplify/ConstProp/roundeven.ll

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ declare double @llvm.roundeven.f64(double)
99
define float @constant_fold_roundeven_f32_01() #0 {
1010
; CHECK-LABEL: define float @constant_fold_roundeven_f32_01(
1111
; CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
12-
; CHECK-NEXT: [[X:%.*]] = call float @roundevenf(float 1.250000e+00) #[[ATTR0]]
13-
; CHECK-NEXT: ret float [[X]]
12+
; CHECK-NEXT: ret float 1.000000e+00
1413
;
1514
%x = call float @roundevenf(float 1.25) #0
1615
ret float %x
@@ -29,8 +28,7 @@ define float @constant_fold_roundeven_f32_02() #0 {
2928
define float @constant_fold_roundeven_f32_03() #0 {
3029
; CHECK-LABEL: define float @constant_fold_roundeven_f32_03(
3130
; CHECK-SAME: ) #[[ATTR0]] {
32-
; CHECK-NEXT: [[X:%.*]] = call float @roundevenf(float 1.500000e+00) #[[ATTR0]]
33-
; CHECK-NEXT: ret float [[X]]
31+
; CHECK-NEXT: ret float 2.000000e+00
3432
;
3533
%x = call float @roundevenf(float 1.5) #0
3634
ret float %x
@@ -50,8 +48,7 @@ define float @constant_fold_roundeven_f32_04() #0 {
5048
define float @constant_fold_roundeven_f32_05() #0 {
5149
; CHECK-LABEL: define float @constant_fold_roundeven_f32_05(
5250
; CHECK-SAME: ) #[[ATTR0]] {
53-
; CHECK-NEXT: [[X:%.*]] = call float @roundevenf(float 2.500000e+00) #[[ATTR0]]
54-
; CHECK-NEXT: ret float [[X]]
51+
; CHECK-NEXT: ret float 2.000000e+00
5552
;
5653
%x = call float @roundevenf(float 2.5) #0
5754
ret float %x
@@ -70,8 +67,7 @@ define float @constant_fold_roundeven_f32_06() #0 {
7067
define float @constant_fold_roundeven_f32_07() #0 {
7168
; CHECK-LABEL: define float @constant_fold_roundeven_f32_07(
7269
; CHECK-SAME: ) #[[ATTR0]] {
73-
; CHECK-NEXT: [[X:%.*]] = call float @roundevenf(float 2.750000e+00) #[[ATTR0]]
74-
; CHECK-NEXT: ret float [[X]]
70+
; CHECK-NEXT: ret float 3.000000e+00
7571
;
7672
%x = call float @roundevenf(float 2.75) #0
7773
ret float %x
@@ -89,8 +85,7 @@ define float @constant_fold_roundeven_f32_08() #0 {
8985
define double @constant_fold_roundeven_f64_01() #0 {
9086
; CHECK-LABEL: define double @constant_fold_roundeven_f64_01(
9187
; CHECK-SAME: ) #[[ATTR0]] {
92-
; CHECK-NEXT: [[X:%.*]] = call double @roundeven(double 1.300000e+00) #[[ATTR0]]
93-
; CHECK-NEXT: ret double [[X]]
88+
; CHECK-NEXT: ret double 1.000000e+00
9489
;
9590
%x = call double @roundeven(double 1.3) #0
9691
ret double %x
@@ -108,8 +103,7 @@ define double @constant_fold_roundeven_f64_02() #0 {
108103
define double @constant_fold_roundeven_f64_03() #0 {
109104
; CHECK-LABEL: define double @constant_fold_roundeven_f64_03(
110105
; CHECK-SAME: ) #[[ATTR0]] {
111-
; CHECK-NEXT: [[X:%.*]] = call double @roundeven(double 1.500000e+00) #[[ATTR0]]
112-
; CHECK-NEXT: ret double [[X]]
106+
; CHECK-NEXT: ret double 2.000000e+00
113107
;
114108
%x = call double @roundeven(double 1.5) #0
115109
ret double %x
@@ -127,8 +121,7 @@ define double @constant_fold_roundeven_f64_04() #0 {
127121
define double @constant_fold_roundeven_f64_05() #0 {
128122
; CHECK-LABEL: define double @constant_fold_roundeven_f64_05(
129123
; CHECK-SAME: ) #[[ATTR0]] {
130-
; CHECK-NEXT: [[X:%.*]] = call double @roundeven(double 2.500000e+00) #[[ATTR0]]
131-
; CHECK-NEXT: ret double [[X]]
124+
; CHECK-NEXT: ret double 2.000000e+00
132125
;
133126
%x = call double @roundeven(double 2.5) #0
134127
ret double %x
@@ -146,8 +139,7 @@ define double @constant_fold_roundeven_f64_06() #0 {
146139
define double @constant_fold_roundeven_f64_07() #0 {
147140
; CHECK-LABEL: define double @constant_fold_roundeven_f64_07(
148141
; CHECK-SAME: ) #[[ATTR0]] {
149-
; CHECK-NEXT: [[X:%.*]] = call double @roundeven(double 2.700000e+00) #[[ATTR0]]
150-
; CHECK-NEXT: ret double [[X]]
142+
; CHECK-NEXT: ret double 3.000000e+00
151143
;
152144
%x = call double @roundeven(double 2.7) #0
153145
ret double %x

0 commit comments

Comments
 (0)