[clang] f02d6dd - Fix floating point builtins to not promote float->double

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 16 07:20:47 PST 2019


Author: Erich Keane
Date: 2019-12-16T07:20:29-08:00
New Revision: f02d6dd6c7afc08f871a623c0411f2d77ed6acf8

URL: https://github.com/llvm/llvm-project/commit/f02d6dd6c7afc08f871a623c0411f2d77ed6acf8
DIFF: https://github.com/llvm/llvm-project/commit/f02d6dd6c7afc08f871a623c0411f2d77ed6acf8.diff

LOG: Fix floating point builtins to not promote float->double

As brought up in D71467, a group of floating point builtins
automatically promoted floats to doubles because they used the variadic
builtin tag to support an overload set. The result is that the
parameters were treated as a variadic pack, which always promots
float->double.

This resulted in the wrong answer being given in cases with certain
values of NaN.

Added: 
    clang/test/CodeGen/builtin_float.c

Modified: 
    clang/include/clang/Basic/Builtins.def
    clang/test/CodeGen/arm-float-helpers.c

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/Builtins.def b/clang/include/clang/Basic/Builtins.def
index 8a102744700f..29dec78e4b96 100644
--- a/clang/include/clang/Basic/Builtins.def
+++ b/clang/include/clang/Basic/Builtins.def
@@ -391,12 +391,12 @@ BUILTIN(__builtin_ctanhf, "XfXf", "Fne")
 BUILTIN(__builtin_ctanhl, "XLdXLd", "Fne")
 
 // FP Comparisons.
-BUILTIN(__builtin_isgreater     , "i.", "Fnc")
-BUILTIN(__builtin_isgreaterequal, "i.", "Fnc")
-BUILTIN(__builtin_isless        , "i.", "Fnc")
-BUILTIN(__builtin_islessequal   , "i.", "Fnc")
-BUILTIN(__builtin_islessgreater , "i.", "Fnc")
-BUILTIN(__builtin_isunordered   , "i.", "Fnc")
+BUILTIN(__builtin_isgreater     , "i.", "Fnct")
+BUILTIN(__builtin_isgreaterequal, "i.", "Fnct")
+BUILTIN(__builtin_isless        , "i.", "Fnct")
+BUILTIN(__builtin_islessequal   , "i.", "Fnct")
+BUILTIN(__builtin_islessgreater , "i.", "Fnct")
+BUILTIN(__builtin_isunordered   , "i.", "Fnct")
 
 // Unary FP classification
 BUILTIN(__builtin_fpclassify, "iiiiii.", "Fnc")

diff  --git a/clang/test/CodeGen/arm-float-helpers.c b/clang/test/CodeGen/arm-float-helpers.c
index 30363304bcf9..b2e65805cc7c 100644
--- a/clang/test/CodeGen/arm-float-helpers.c
+++ b/clang/test/CodeGen/arm-float-helpers.c
@@ -79,7 +79,7 @@ int fcmpgt(float a, float b) { return a > b; }
 int fcmpun(float a, float b) { return __builtin_isunordered(a, b); }
 // CHECK-LABEL: define i32 @fcmpun(float %a, float %b)
 // CHECK-NOT: __aeabi_fcmpun
-// CHECK: %cmp = fcmp uno double %conv, %conv1
+// CHECK: %cmp = fcmp uno float {{.*}}, {{.*}}
 
 double dadd(double a, double b) { return a + b; }
 // CHECK-LABEL: define double @dadd(double %a, double %b)

diff  --git a/clang/test/CodeGen/builtin_float.c b/clang/test/CodeGen/builtin_float.c
new file mode 100644
index 000000000000..b97cf1be348f
--- /dev/null
+++ b/clang/test/CodeGen/builtin_float.c
@@ -0,0 +1,71 @@
+// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
+
+// test to ensure that these builtins don't do the variadic promotion of float->double.
+void test_floats(float f1, float f2) {
+  (void)__builtin_isgreater(f1, f2);
+  // CHECK: fcmp ogt float
+  // CHECK-NEXT: zext i1
+  (void)__builtin_isgreaterequal(f1, f2);
+  // CHECK: fcmp oge float
+  // CHECK-NEXT: zext i1
+  (void)__builtin_isless(f1, f2);
+  // CHECK: fcmp olt float
+  // CHECK-NEXT: zext i1
+  (void)__builtin_islessequal(f1, f2);
+  // CHECK: fcmp ole float
+  // CHECK-NEXT: zext i1
+  (void)__builtin_islessgreater(f1, f2);
+  // CHECK: fcmp one float
+  // CHECK-NEXT: zext i1
+  (void)__builtin_isunordered(f1, f2);
+  // CHECK: fcmp uno float
+  // CHECK-NEXT: zext i1
+}
+
+void test_doubles(double d1, double f2) {
+  (void)__builtin_isgreater(d1, f2);
+  // CHECK: fcmp ogt double
+  // CHECK-NEXT: zext i1
+  (void)__builtin_isgreaterequal(d1, f2);
+  // CHECK: fcmp oge double
+  // CHECK-NEXT: zext i1
+  (void)__builtin_isless(d1, f2);
+  // CHECK: fcmp olt double
+  // CHECK-NEXT: zext i1
+  (void)__builtin_islessequal(d1, f2);
+  // CHECK: fcmp ole double
+  // CHECK-NEXT: zext i1
+  (void)__builtin_islessgreater(d1, f2);
+  // CHECK: fcmp one double
+  // CHECK-NEXT: zext i1
+  (void)__builtin_isunordered(d1, f2);
+  // CHECK: fcmp uno double
+  // CHECK-NEXT: zext i1
+}
+
+void test_mixed(double d1, float f2) {
+  (void)__builtin_isgreater(d1, f2);
+  // CHECK: fpext float {{.*}} to double
+  // CHECK-NEXT: fcmp ogt double
+  // CHECK-NEXT: zext i1
+  (void)__builtin_isgreaterequal(d1, f2);
+  // CHECK: fpext float {{.*}} to double
+  // CHECK-NEXT: fcmp oge double
+  // CHECK-NEXT: zext i1
+  (void)__builtin_isless(d1, f2);
+  // CHECK: fpext float {{.*}} to double
+  // CHECK-NEXT: fcmp olt double
+  // CHECK-NEXT: zext i1
+  (void)__builtin_islessequal(d1, f2);
+  // CHECK: fpext float {{.*}} to double
+  // CHECK-NEXT: fcmp ole double
+  // CHECK-NEXT: zext i1
+  (void)__builtin_islessgreater(d1, f2);
+  // CHECK: fpext float {{.*}} to double
+  // CHECK-NEXT: fcmp one double
+  // CHECK-NEXT: zext i1
+  (void)__builtin_isunordered(d1, f2);
+  // CHECK: fpext float {{.*}} to double
+  // CHECK-NEXT: fcmp uno double
+  // CHECK-NEXT: zext i1
+}


        


More information about the cfe-commits mailing list