Skip to content

Commit e6c84d7

Browse files
Mark libc math shims with always_inline attribute (#6956)
* Mark libc math shims with always_inline attribute We want these to always be inlined, so mark them with ... always_inline. The compiler happened to do the right thing with them previously, but we shouldn't depend on that. <rdar://problem/30043258> master-next: IRGen/builtin_math.swift failing because sqrt(4) is not constant folded
1 parent f154b6a commit e6c84d7

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

stdlib/public/SwiftShims/LibcShims.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,30 +91,36 @@ __swift_uint32_t
9191
_swift_stdlib_cxx11_mt19937_uniform(__swift_uint32_t upper_bound);
9292

9393
// Math library functions
94-
static inline float _swift_stdlib_remainderf(float _self, float _other) {
94+
static inline __attribute__((always_inline))
95+
float _swift_stdlib_remainderf(float _self, float _other) {
9596
return __builtin_remainderf(_self, _other);
9697
}
9798

98-
static inline float _swift_stdlib_squareRootf(float _self) {
99-
return __builtin_sqrtf(_self);
99+
static inline __attribute__((always_inline))
100+
float _swift_stdlib_squareRootf(float _self) {
101+
return __builtin_sqrt(_self);
100102
}
101103

102-
static inline double _swift_stdlib_remainder(double _self, double _other) {
104+
static inline __attribute__((always_inline))
105+
double _swift_stdlib_remainder(double _self, double _other) {
103106
return __builtin_remainder(_self, _other);
104107
}
105108

106-
static inline double _swift_stdlib_squareRoot(double _self) {
109+
static inline __attribute__((always_inline))
110+
double _swift_stdlib_squareRoot(double _self) {
107111
return __builtin_sqrt(_self);
108112
}
109113

110114
// TODO: Remove horrible workaround when importer does Float80 <-> long double.
111115
#if (defined __i386__ || defined __x86_64__) && !defined _MSC_VER
112-
static inline void _swift_stdlib_remainderl(void *_self, const void *_other) {
116+
static inline __attribute__((always_inline))
117+
void _swift_stdlib_remainderl(void *_self, const void *_other) {
113118
long double *_f80self = (long double *)_self;
114119
*_f80self = __builtin_remainderl(*_f80self, *(const long double *)_other);
115120
}
116121

117-
static inline void _swift_stdlib_squareRootl(void *_self) {
122+
static inline __attribute__((always_inline))
123+
void _swift_stdlib_squareRootl(void *_self) {
118124
long double *_f80self = (long double *)_self;
119125
*_f80self = __builtin_sqrtl(*_f80self);
120126
}

test/IRGen/builtin_math.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil -emit-ir -O %s | %FileCheck %s
22

3-
// REQUIRES: 30043258
43
// XFAIL: linux
54

65
import Darwin
@@ -39,6 +38,20 @@ public func test4(f : Float) -> Float {
3938
return sqrt(f)
4039
}
4140

41+
// CHECK-LABEL: define {{.*}}test3a
42+
// CHECK: call double @remainder
43+
44+
public func test3a(d : Double) -> Double {
45+
return remainder(1,d)
46+
}
47+
48+
// CHECK-LABEL: define {{.*}}test4a
49+
// CHECK: call float @remainder
50+
51+
public func test4a(f : Float) -> Float {
52+
return remainder(1,f)
53+
}
54+
4255
// CHECK-LABEL: define {{.*}}test5
4356
// CHECK: ret float 2
4457

0 commit comments

Comments
 (0)