[PATCH] D88826: [builtins] Work around long double return bug on Solaris/sparcv9

Rainer Orth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 5 05:06:25 PDT 2020


ro created this revision.
ro added reviewers: MaskRay, efriedma, jyknight, jfb, venkatra, jrtc27.
Herald added subscribers: Sanitizers, dexonsmith, fedor.sergeev.
Herald added a project: Sanitizers.
ro requested review of this revision.

As detailed in Bug 47729, several `long double` tests `FAIL` on Solaris/sparcv9, ultimately because `compiler-rt/lib/builtins/fp_lib.h` (`fromRep`) or similar functions returning long double are miscompiled.

I've been using this patch as a workaround by compiling the affected functions without optimization.

Tested on `sparcv9-sun-solaris2.11`.

I don't seriously expect this hack to be accepted, but have several times seen that patches (however hacky) tend to attract more attention then bug reports, ultimately leading to a proper solution.  Unfortunately, codegen bugs are way beyond my abilities to fix myself, so I have to rely on those who can.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D88826

Files:
  compiler-rt/lib/builtins/floattitf.c
  compiler-rt/lib/builtins/floatuntitf.c
  compiler-rt/lib/builtins/fp_extend.h
  compiler-rt/lib/builtins/fp_lib.h


Index: compiler-rt/lib/builtins/fp_lib.h
===================================================================
--- compiler-rt/lib/builtins/fp_lib.h
+++ compiler-rt/lib/builtins/fp_lib.h
@@ -230,6 +230,10 @@
   return rep.i;
 }
 
+// Work around miscompilation on sparcv9 (Bug 47729).
+#if defined(__clang__) && defined(__sparc__)
+#pragma clang optimize off
+#endif
 static __inline fp_t fromRep(rep_t x) {
   const union {
     fp_t f;
@@ -237,6 +241,9 @@
   } rep = {.i = x};
   return rep.f;
 }
+#if defined(__clang__) && defined(__sparc__)
+#pragma clang optimize on
+#endif
 
 static __inline int normalize(rep_t *significand) {
   const int shift = rep_clz(*significand) - rep_clz(implicitBit);
Index: compiler-rt/lib/builtins/fp_extend.h
===================================================================
--- compiler-rt/lib/builtins/fp_extend.h
+++ compiler-rt/lib/builtins/fp_extend.h
@@ -83,6 +83,9 @@
   return rep.i;
 }
 
+#if defined(__clang__) && defined(__sparc__)
+#pragma clang optimize off
+#endif
 static __inline dst_t dstFromRep(dst_rep_t x) {
   const union {
     dst_t f;
@@ -90,6 +93,9 @@
   } rep = {.i = x};
   return rep.f;
 }
+#if defined(__clang__) && defined(__sparc__)
+#pragma clang optimize on
+#endif
 // End helper routines.  Conversion implementation follows.
 
 #endif // FP_EXTEND_HEADER
Index: compiler-rt/lib/builtins/floatuntitf.c
===================================================================
--- compiler-rt/lib/builtins/floatuntitf.c
+++ compiler-rt/lib/builtins/floatuntitf.c
@@ -26,6 +26,9 @@
 // mmmm mmmm mmmm
 
 #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(__clang__) && defined(__sparc__)
+#pragma clang optimize off
+#endif
 COMPILER_RT_ABI fp_t __floatuntitf(tu_int a) {
   if (a == 0)
     return 0.0;
@@ -71,5 +74,8 @@
   fb.u.low.all = (du_int)(a);
   return fb.f;
 }
+#if defined(__clang__) && defined(__sparc__)
+#pragma clang optimize on
+#endif
 
 #endif
Index: compiler-rt/lib/builtins/floattitf.c
===================================================================
--- compiler-rt/lib/builtins/floattitf.c
+++ compiler-rt/lib/builtins/floattitf.c
@@ -26,6 +26,9 @@
 // mmmm mmmm mmmm
 
 #if defined(CRT_HAS_128BIT) && defined(CRT_LDBL_128BIT)
+#if defined(__clang__) && defined(__sparc__)
+#pragma clang optimize off
+#endif
 COMPILER_RT_ABI fp_t __floattitf(ti_int a) {
   if (a == 0)
     return 0.0;
@@ -74,5 +77,8 @@
   fb.u.low.all = (du_int)(a);
   return fb.f;
 }
+#if defined(__clang__) && defined(__sparc__)
+#pragma clang optimize on
+#endif
 
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D88826.296156.patch
Type: text/x-patch
Size: 2553 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201005/5ea91510/attachment.bin>


More information about the llvm-commits mailing list