xref: /OK3568_Linux_fs/buildroot/package/llvm/0002-No-longer-generate-calls-to-_finite.patch (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1From d21be6954379970f7019bf2eacfbf0ff259e1ddd Mon Sep 17 00:00:00 2001
2From: serge-sans-paille <sguelton@redhat.com>
3Date: Fri, 21 Feb 2020 15:51:19 +0100
4Subject: [PATCH 2/2] No longer generate calls to *_finite
5
6According to Joseph Myers, a libm maintainer
7
8> They were only ever an ABI (selected by use of -ffinite-math-only or
9> options implying it, which resulted in the headers using "asm" to redirect
10> calls to some libm functions), not an API. The change means that ABI has
11> turned into compat symbols (only available for existing binaries, not for
12> anything newly linked, not included in static libm at all, not included in
13> shared libm for future glibc ports such as RV32), so, yes, in any case
14> where tools generate direct calls to those functions (rather than just
15> following the "asm" annotations on function declarations in the headers),
16> they need to stop doing so.
17
18As a consequence, we should no longer assume these symbols are available on the
19target system.
20
21Still keep the TargetLibraryInfo for constant folding.
22
23Differential Revision: https://reviews.llvm.org/D74712
24
25(cherry picked from commit 6d15c4deab51498b70825fb6cefbbfe8f3d9bdcf)
26
27For https://bugs.llvm.org/show_bug.cgi?id=45034
28
29(cherry picked from commit cd0926d087a85c5ee1222ca80980b4440214a822)
30
31Conflicts:
32	llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
33
34Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
35---
36 lib/Analysis/TargetLibraryInfo.cpp        |  3 +
37 lib/CodeGen/SelectionDAG/LegalizeDAG.cpp  | 79 ++++++-----------------
38 test/CodeGen/AArch64/illegal-float-ops.ll | 24 +++----
39 test/CodeGen/X86/finite-libcalls.ll       | 36 +++++------
40 4 files changed, 51 insertions(+), 91 deletions(-)
41
42diff --git a/lib/Analysis/TargetLibraryInfo.cpp b/lib/Analysis/TargetLibraryInfo.cpp
43index ef139d325..37b030b18 100644
44--- a/lib/Analysis/TargetLibraryInfo.cpp
45+++ b/lib/Analysis/TargetLibraryInfo.cpp
46@@ -479,6 +479,9 @@ static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T,
47     TLI.setUnavailable(LibFunc_tmpfile64);
48
49     // Relaxed math functions are included in math-finite.h on Linux (GLIBC).
50+    // Note that math-finite.h is no longer supported by top-of-tree GLIBC,
51+    // so we keep these functions around just so that they're recognized by
52+    // the ConstantFolder.
53     TLI.setUnavailable(LibFunc_acos_finite);
54     TLI.setUnavailable(LibFunc_acosf_finite);
55     TLI.setUnavailable(LibFunc_acosl_finite);
56diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
57index bf817f00f..97648fbb4 100644
58--- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
59+++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
60@@ -3731,7 +3731,6 @@ void SelectionDAGLegalize::ConvertNodeToLibcall(SDNode *Node) {
61   SmallVector<SDValue, 8> Results;
62   SDLoc dl(Node);
63   // FIXME: Check flags on the node to see if we can use a finite call.
64-  bool CanUseFiniteLibCall = TM.Options.NoInfsFPMath && TM.Options.NoNaNsFPMath;
65   unsigned Opc = Node->getOpcode();
66   switch (Opc) {
67   case ISD::ATOMIC_FENCE: {
68@@ -3834,68 +3833,33 @@ void SelectionDAGLegalize::ConvertNodeToLibcall(SDNode *Node) {
69     break;
70   case ISD::FLOG:
71   case ISD::STRICT_FLOG:
72-    if (CanUseFiniteLibCall && DAG.getLibInfo().has(LibFunc_log_finite))
73-      Results.push_back(ExpandFPLibCall(Node, RTLIB::LOG_FINITE_F32,
74-                                        RTLIB::LOG_FINITE_F64,
75-                                        RTLIB::LOG_FINITE_F80,
76-                                        RTLIB::LOG_FINITE_F128,
77-                                        RTLIB::LOG_FINITE_PPCF128));
78-    else
79-      Results.push_back(ExpandFPLibCall(Node, RTLIB::LOG_F32, RTLIB::LOG_F64,
80-                                        RTLIB::LOG_F80, RTLIB::LOG_F128,
81-                                        RTLIB::LOG_PPCF128));
82+    Results.push_back(ExpandFPLibCall(Node, RTLIB::LOG_F32, RTLIB::LOG_F64,
83+                                      RTLIB::LOG_F80, RTLIB::LOG_F128,
84+                                      RTLIB::LOG_PPCF128));
85     break;
86   case ISD::FLOG2:
87   case ISD::STRICT_FLOG2:
88-    if (CanUseFiniteLibCall && DAG.getLibInfo().has(LibFunc_log2_finite))
89-      Results.push_back(ExpandFPLibCall(Node, RTLIB::LOG2_FINITE_F32,
90-                                        RTLIB::LOG2_FINITE_F64,
91-                                        RTLIB::LOG2_FINITE_F80,
92-                                        RTLIB::LOG2_FINITE_F128,
93-                                        RTLIB::LOG2_FINITE_PPCF128));
94-    else
95-      Results.push_back(ExpandFPLibCall(Node, RTLIB::LOG2_F32, RTLIB::LOG2_F64,
96-                                        RTLIB::LOG2_F80, RTLIB::LOG2_F128,
97-                                        RTLIB::LOG2_PPCF128));
98+    Results.push_back(ExpandFPLibCall(Node, RTLIB::LOG2_F32, RTLIB::LOG2_F64,
99+                                      RTLIB::LOG2_F80, RTLIB::LOG2_F128,
100+                                      RTLIB::LOG2_PPCF128));
101     break;
102   case ISD::FLOG10:
103   case ISD::STRICT_FLOG10:
104-    if (CanUseFiniteLibCall && DAG.getLibInfo().has(LibFunc_log10_finite))
105-      Results.push_back(ExpandFPLibCall(Node, RTLIB::LOG10_FINITE_F32,
106-                                        RTLIB::LOG10_FINITE_F64,
107-                                        RTLIB::LOG10_FINITE_F80,
108-                                        RTLIB::LOG10_FINITE_F128,
109-                                        RTLIB::LOG10_FINITE_PPCF128));
110-    else
111-      Results.push_back(ExpandFPLibCall(Node, RTLIB::LOG10_F32, RTLIB::LOG10_F64,
112-                                        RTLIB::LOG10_F80, RTLIB::LOG10_F128,
113-                                        RTLIB::LOG10_PPCF128));
114+    Results.push_back(ExpandFPLibCall(Node, RTLIB::LOG10_F32, RTLIB::LOG10_F64,
115+                                      RTLIB::LOG10_F80, RTLIB::LOG10_F128,
116+                                      RTLIB::LOG10_PPCF128));
117     break;
118   case ISD::FEXP:
119   case ISD::STRICT_FEXP:
120-    if (CanUseFiniteLibCall && DAG.getLibInfo().has(LibFunc_exp_finite))
121-      Results.push_back(ExpandFPLibCall(Node, RTLIB::EXP_FINITE_F32,
122-                                        RTLIB::EXP_FINITE_F64,
123-                                        RTLIB::EXP_FINITE_F80,
124-                                        RTLIB::EXP_FINITE_F128,
125-                                        RTLIB::EXP_FINITE_PPCF128));
126-    else
127-      Results.push_back(ExpandFPLibCall(Node, RTLIB::EXP_F32, RTLIB::EXP_F64,
128-                                        RTLIB::EXP_F80, RTLIB::EXP_F128,
129-                                        RTLIB::EXP_PPCF128));
130+    Results.push_back(ExpandFPLibCall(Node, RTLIB::EXP_F32, RTLIB::EXP_F64,
131+                                      RTLIB::EXP_F80, RTLIB::EXP_F128,
132+                                      RTLIB::EXP_PPCF128));
133     break;
134   case ISD::FEXP2:
135   case ISD::STRICT_FEXP2:
136-    if (CanUseFiniteLibCall && DAG.getLibInfo().has(LibFunc_exp2_finite))
137-      Results.push_back(ExpandFPLibCall(Node, RTLIB::EXP2_FINITE_F32,
138-                                        RTLIB::EXP2_FINITE_F64,
139-                                        RTLIB::EXP2_FINITE_F80,
140-                                        RTLIB::EXP2_FINITE_F128,
141-                                        RTLIB::EXP2_FINITE_PPCF128));
142-    else
143-      Results.push_back(ExpandFPLibCall(Node, RTLIB::EXP2_F32, RTLIB::EXP2_F64,
144-                                        RTLIB::EXP2_F80, RTLIB::EXP2_F128,
145-                                        RTLIB::EXP2_PPCF128));
146+    Results.push_back(ExpandFPLibCall(Node, RTLIB::EXP2_F32, RTLIB::EXP2_F64,
147+                                      RTLIB::EXP2_F80, RTLIB::EXP2_F128,
148+                                      RTLIB::EXP2_PPCF128));
149     break;
150   case ISD::FTRUNC:
151   case ISD::STRICT_FTRUNC:
152@@ -3945,16 +3909,9 @@ void SelectionDAGLegalize::ConvertNodeToLibcall(SDNode *Node) {
153     break;
154   case ISD::FPOW:
155   case ISD::STRICT_FPOW:
156-    if (CanUseFiniteLibCall && DAG.getLibInfo().has(LibFunc_pow_finite))
157-      Results.push_back(ExpandFPLibCall(Node, RTLIB::POW_FINITE_F32,
158-                                        RTLIB::POW_FINITE_F64,
159-                                        RTLIB::POW_FINITE_F80,
160-                                        RTLIB::POW_FINITE_F128,
161-                                        RTLIB::POW_FINITE_PPCF128));
162-    else
163-      Results.push_back(ExpandFPLibCall(Node, RTLIB::POW_F32, RTLIB::POW_F64,
164-                                        RTLIB::POW_F80, RTLIB::POW_F128,
165-                                        RTLIB::POW_PPCF128));
166+    Results.push_back(ExpandFPLibCall(Node, RTLIB::POW_F32, RTLIB::POW_F64,
167+                                      RTLIB::POW_F80, RTLIB::POW_F128,
168+                                      RTLIB::POW_PPCF128));
169     break;
170   case ISD::FDIV:
171     Results.push_back(ExpandFPLibCall(Node, RTLIB::DIV_F32, RTLIB::DIV_F64,
172diff --git a/test/CodeGen/AArch64/illegal-float-ops.ll b/test/CodeGen/AArch64/illegal-float-ops.ll
173index 8bee4437f..f55663664 100644
174--- a/test/CodeGen/AArch64/illegal-float-ops.ll
175+++ b/test/CodeGen/AArch64/illegal-float-ops.ll
176@@ -1,5 +1,5 @@
177 ; RUN: llc -mtriple=aarch64-none-linux-gnu -verify-machineinstrs -o - %s | FileCheck %s
178-; RUN: llc -mtriple=aarch64-linux-android -verify-machineinstrs -o - %s | FileCheck --check-prefix=ANDROID-AARCH64 %s
179+; RUN: llc -mtriple=aarch64-linux-android -verify-machineinstrs -o - %s | FileCheck %s
180
181 @varfloat = global float 0.0
182 @vardouble = global double 0.0
183@@ -251,7 +251,7 @@ define void @test_exp_finite(double %double) #0 {
184   %expdouble = call double @llvm.exp.f64(double %double)
185   store double %expdouble, double* @vardouble
186   ; ANDROID-AARCH64-NOT: bl __exp_finite
187-  ; CHECK: bl __exp_finite
188+  ; CHECK: bl exp
189
190   ret void
191 }
192@@ -259,8 +259,8 @@ define void @test_exp_finite(double %double) #0 {
193 define void @test_exp2_finite(double %double) #0 {
194   %expdouble = call double @llvm.exp2.f64(double %double)
195   store double %expdouble, double* @vardouble
196-  ; ANDROID-AARCH64-NOT: bl __exp2_finite
197-  ; CHECK: bl __exp2_finite
198+  ; CHECK-NOT: bl __exp2_finite
199+  ; CHECK: bl exp2
200
201   ret void
202 }
203@@ -268,32 +268,32 @@ define void @test_exp2_finite(double %double) #0 {
204 define void @test_log_finite(double %double) #0 {
205   %logdouble = call double @llvm.log.f64(double %double)
206   store double %logdouble, double* @vardouble
207-  ; ANDROID-AARCH64-NOT: bl __log_finite
208-  ; CHECK: bl __log_finite
209+  ; CHECK-NOT: bl __log_finite
210+  ; CHECK: bl log
211   ret void
212 }
213
214 define void @test_log2_finite(double %double) #0 {
215   %log2double = call double @llvm.log2.f64(double %double)
216   store double %log2double, double* @vardouble
217-  ; ANDROID-AARCH64-NOT: bl __log2_finite
218-  ; CHECK: bl __log2_finite
219+  ; CHECK-NOT: bl __log2_finite
220+  ; CHECK: bl log2
221   ret void
222 }
223
224 define void @test_log10_finite(double %double) #0 {
225   %log10double = call double @llvm.log10.f64(double %double)
226   store double %log10double, double* @vardouble
227-  ; ANDROID-AARCH64-NOT: bl __log10_finite
228-  ; CHECK: bl __log10_finite
229+  ; CHECK-NOT: bl __log10_finite
230+  ; CHECK: bl log10
231   ret void
232 }
233
234 define void @test_pow_finite(double %double) #0 {
235   %powdouble = call double @llvm.pow.f64(double %double, double %double)
236   store double %powdouble, double* @vardouble
237-  ; ANDROID-AARCH64-NOT: bl __pow_finite
238-  ; CHECK: bl __pow_finite
239+  ; CHECK-NOT: bl __pow_finite
240+  ; CHECK: bl pow
241   ret void
242 }
243
244diff --git a/test/CodeGen/X86/finite-libcalls.ll b/test/CodeGen/X86/finite-libcalls.ll
245index d54ee48ea..31fadfb0a 100644
246--- a/test/CodeGen/X86/finite-libcalls.ll
247+++ b/test/CodeGen/X86/finite-libcalls.ll
248@@ -9,7 +9,7 @@
249 define float @exp_f32(float %x) #0 {
250 ; GNU-LABEL: exp_f32:
251 ; GNU:       # %bb.0:
252-; GNU-NEXT:    jmp __expf_finite # TAILCALL
253+; GNU-NEXT:    jmp expf # TAILCALL
254 ;
255 ; WIN-LABEL: exp_f32:
256 ; WIN:       # %bb.0:
257@@ -25,7 +25,7 @@ define float @exp_f32(float %x) #0 {
258 define double @exp_f64(double %x) #0 {
259 ; GNU-LABEL: exp_f64:
260 ; GNU:       # %bb.0:
261-; GNU-NEXT:    jmp __exp_finite # TAILCALL
262+; GNU-NEXT:    jmp exp # TAILCALL
263 ;
264 ; WIN-LABEL: exp_f64:
265 ; WIN:       # %bb.0:
266@@ -44,7 +44,7 @@ define x86_fp80 @exp_f80(x86_fp80 %x) #0 {
267 ; GNU-NEXT:    subq $24, %rsp
268 ; GNU-NEXT:    fldt {{[0-9]+}}(%rsp)
269 ; GNU-NEXT:    fstpt (%rsp)
270-; GNU-NEXT:    callq __expl_finite
271+; GNU-NEXT:    callq expl
272 ; GNU-NEXT:    addq $24, %rsp
273 ; GNU-NEXT:    retq
274 ;
275@@ -80,7 +80,7 @@ define x86_fp80 @exp_f80(x86_fp80 %x) #0 {
276 define float @exp2_f32(float %x) #0 {
277 ; GNU-LABEL: exp2_f32:
278 ; GNU:       # %bb.0:
279-; GNU-NEXT:    jmp __exp2f_finite # TAILCALL
280+; GNU-NEXT:    jmp exp2f # TAILCALL
281 ;
282 ; WIN-LABEL: exp2_f32:
283 ; WIN:       # %bb.0:
284@@ -96,7 +96,7 @@ define float @exp2_f32(float %x) #0 {
285 define double @exp2_f64(double %x) #0 {
286 ; GNU-LABEL: exp2_f64:
287 ; GNU:       # %bb.0:
288-; GNU-NEXT:    jmp __exp2_finite # TAILCALL
289+; GNU-NEXT:    jmp exp2 # TAILCALL
290 ;
291 ; WIN-LABEL: exp2_f64:
292 ; WIN:       # %bb.0:
293@@ -115,7 +115,7 @@ define x86_fp80 @exp2_f80(x86_fp80 %x) #0 {
294 ; GNU-NEXT:    subq $24, %rsp
295 ; GNU-NEXT:    fldt {{[0-9]+}}(%rsp)
296 ; GNU-NEXT:    fstpt (%rsp)
297-; GNU-NEXT:    callq __exp2l_finite
298+; GNU-NEXT:    callq exp2l
299 ; GNU-NEXT:    addq $24, %rsp
300 ; GNU-NEXT:    retq
301 ;
302@@ -151,7 +151,7 @@ define x86_fp80 @exp2_f80(x86_fp80 %x) #0 {
303 define float @log_f32(float %x) #0 {
304 ; GNU-LABEL: log_f32:
305 ; GNU:       # %bb.0:
306-; GNU-NEXT:    jmp __logf_finite # TAILCALL
307+; GNU-NEXT:    jmp logf # TAILCALL
308 ;
309 ; WIN-LABEL: log_f32:
310 ; WIN:       # %bb.0:
311@@ -167,7 +167,7 @@ define float @log_f32(float %x) #0 {
312 define double @log_f64(double %x) #0 {
313 ; GNU-LABEL: log_f64:
314 ; GNU:       # %bb.0:
315-; GNU-NEXT:    jmp __log_finite # TAILCALL
316+; GNU-NEXT:    jmp log # TAILCALL
317 ;
318 ; WIN-LABEL: log_f64:
319 ; WIN:       # %bb.0:
320@@ -186,7 +186,7 @@ define x86_fp80 @log_f80(x86_fp80 %x) #0 {
321 ; GNU-NEXT:    subq $24, %rsp
322 ; GNU-NEXT:    fldt {{[0-9]+}}(%rsp)
323 ; GNU-NEXT:    fstpt (%rsp)
324-; GNU-NEXT:    callq __logl_finite
325+; GNU-NEXT:    callq logl
326 ; GNU-NEXT:    addq $24, %rsp
327 ; GNU-NEXT:    retq
328 ;
329@@ -222,7 +222,7 @@ define x86_fp80 @log_f80(x86_fp80 %x) #0 {
330 define float @log2_f32(float %x) #0 {
331 ; GNU-LABEL: log2_f32:
332 ; GNU:       # %bb.0:
333-; GNU-NEXT:    jmp __log2f_finite # TAILCALL
334+; GNU-NEXT:    jmp log2f # TAILCALL
335 ;
336 ; WIN-LABEL: log2_f32:
337 ; WIN:       # %bb.0:
338@@ -238,7 +238,7 @@ define float @log2_f32(float %x) #0 {
339 define double @log2_f64(double %x) #0 {
340 ; GNU-LABEL: log2_f64:
341 ; GNU:       # %bb.0:
342-; GNU-NEXT:    jmp __log2_finite # TAILCALL
343+; GNU-NEXT:    jmp log2 # TAILCALL
344 ;
345 ; WIN-LABEL: log2_f64:
346 ; WIN:       # %bb.0:
347@@ -257,7 +257,7 @@ define x86_fp80 @log2_f80(x86_fp80 %x) #0 {
348 ; GNU-NEXT:    subq $24, %rsp
349 ; GNU-NEXT:    fldt {{[0-9]+}}(%rsp)
350 ; GNU-NEXT:    fstpt (%rsp)
351-; GNU-NEXT:    callq __log2l_finite
352+; GNU-NEXT:    callq log2l
353 ; GNU-NEXT:    addq $24, %rsp
354 ; GNU-NEXT:    retq
355 ;
356@@ -293,7 +293,7 @@ define x86_fp80 @log2_f80(x86_fp80 %x) #0 {
357 define float @log10_f32(float %x) #0 {
358 ; GNU-LABEL: log10_f32:
359 ; GNU:       # %bb.0:
360-; GNU-NEXT:    jmp __log10f_finite # TAILCALL
361+; GNU-NEXT:    jmp log10f # TAILCALL
362 ;
363 ; WIN-LABEL: log10_f32:
364 ; WIN:       # %bb.0:
365@@ -309,7 +309,7 @@ define float @log10_f32(float %x) #0 {
366 define double @log10_f64(double %x) #0 {
367 ; GNU-LABEL: log10_f64:
368 ; GNU:       # %bb.0:
369-; GNU-NEXT:    jmp __log10_finite # TAILCALL
370+; GNU-NEXT:    jmp log10 # TAILCALL
371 ;
372 ; WIN-LABEL: log10_f64:
373 ; WIN:       # %bb.0:
374@@ -328,7 +328,7 @@ define x86_fp80 @log10_f80(x86_fp80 %x) #0 {
375 ; GNU-NEXT:    subq $24, %rsp
376 ; GNU-NEXT:    fldt {{[0-9]+}}(%rsp)
377 ; GNU-NEXT:    fstpt (%rsp)
378-; GNU-NEXT:    callq __log10l_finite
379+; GNU-NEXT:    callq log10l
380 ; GNU-NEXT:    addq $24, %rsp
381 ; GNU-NEXT:    retq
382 ;
383@@ -365,7 +365,7 @@ define float @pow_f32(float %x) #0 {
384 ; GNU-LABEL: pow_f32:
385 ; GNU:       # %bb.0:
386 ; GNU-NEXT:    movaps %xmm0, %xmm1
387-; GNU-NEXT:    jmp __powf_finite # TAILCALL
388+; GNU-NEXT:    jmp powf # TAILCALL
389 ;
390 ; WIN-LABEL: pow_f32:
391 ; WIN:       # %bb.0:
392@@ -384,7 +384,7 @@ define double @pow_f64(double %x) #0 {
393 ; GNU-LABEL: pow_f64:
394 ; GNU:       # %bb.0:
395 ; GNU-NEXT:    movaps %xmm0, %xmm1
396-; GNU-NEXT:    jmp __pow_finite # TAILCALL
397+; GNU-NEXT:    jmp pow # TAILCALL
398 ;
399 ; WIN-LABEL: pow_f64:
400 ; WIN:       # %bb.0:
401@@ -407,7 +407,7 @@ define x86_fp80 @pow_f80(x86_fp80 %x) #0 {
402 ; GNU-NEXT:    fld %st(0)
403 ; GNU-NEXT:    fstpt {{[0-9]+}}(%rsp)
404 ; GNU-NEXT:    fstpt (%rsp)
405-; GNU-NEXT:    callq __powl_finite
406+; GNU-NEXT:    callq powl
407 ; GNU-NEXT:    addq $40, %rsp
408 ; GNU-NEXT:    retq
409 ;
410--
4112.20.1
412
413