[compiler-rt] Relax muldc3 test to avoid precision issue (PR #151663)

via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 1 01:03:41 PDT 2025


https://github.com/jinge90 updated https://github.com/llvm/llvm-project/pull/151663

>From 8aa64693e98f5e209df6869ea17562aa4964a618 Mon Sep 17 00:00:00 2001
From: jinge90 <ge.jin at intel.com>
Date: Fri, 1 Aug 2025 16:06:28 +0800
Subject: [PATCH 1/2] Relax muldc3 test

Signed-off-by: jinge90 <ge.jin at intel.com>
---
 compiler-rt/test/builtins/Unit/muldc3_test.c | 22 ++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/compiler-rt/test/builtins/Unit/muldc3_test.c b/compiler-rt/test/builtins/Unit/muldc3_test.c
index 4941078e99b06..fb72e50181f06 100644
--- a/compiler-rt/test/builtins/Unit/muldc3_test.c
+++ b/compiler-rt/test/builtins/Unit/muldc3_test.c
@@ -7,6 +7,7 @@
 #include <complex.h>
 #include <stdio.h>
 
+#define RELATIVE_TOLERANCE 1e-4
 
 // Returns: the product of a + ib and c + id
 
@@ -15,6 +16,19 @@ __muldc3(double __a, double __b, double __c, double __d);
 
 enum {zero, non_zero, inf, NaN, non_zero_nan};
 
+int check_complex_equal(double _Complex r1, double _Complex r2)
+{
+    double max_magnitude = fmax(cabs(r1), cabs(r2));
+    double real_diff = fabs(creal(r1) - creal(r2));
+    double imag_diff = fabs(cimag(r1) - cimag(r2));
+    if (real_diff >= max_magnitude * RELATIVE_TOLERANCE)
+      return 0;
+    if (imag_diff >= max_magnitude * RELATIVE_TOLERANCE)
+      return 0;
+
+    return 1;
+}
+
 int
 classify(double _Complex x)
 {
@@ -46,11 +60,15 @@ int test__muldc3(double a, double b, double c, double d)
 //             a, b, c, d, creal(r), cimag(r));
 	double _Complex dividend;
 	double _Complex divisor;
-	
+  double _Complex temp;	
+
 	__real__ dividend = a;
 	__imag__ dividend = b;
 	__real__ divisor = c;
 	__imag__ divisor = d;
+
+  __real__ temp = a * c - b * d;
+  __imag__ temp = a * d + b * c;
 	
     switch (classify(dividend))
     {
@@ -89,7 +107,7 @@ int test__muldc3(double a, double b, double c, double d)
         case non_zero:
             if (classify(r) != non_zero)
                 return 1;
-            if (r != a * c - b * d + _Complex_I*(a * d + b * c))
+            if (!check_complex_equal(r, temp))
                 return 1;
             break;
         case inf:

>From ecce9daa58286cb5631174c5e3c02e339ffb5376 Mon Sep 17 00:00:00 2001
From: jinge90 <ge.jin at intel.com>
Date: Fri, 1 Aug 2025 16:31:40 +0800
Subject: [PATCH 2/2] make relative tolerance smaller

Signed-off-by: jinge90 <ge.jin at intel.com>
---
 compiler-rt/test/builtins/Unit/muldc3_test.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compiler-rt/test/builtins/Unit/muldc3_test.c b/compiler-rt/test/builtins/Unit/muldc3_test.c
index fb72e50181f06..1787b83f771b3 100644
--- a/compiler-rt/test/builtins/Unit/muldc3_test.c
+++ b/compiler-rt/test/builtins/Unit/muldc3_test.c
@@ -7,7 +7,7 @@
 #include <complex.h>
 #include <stdio.h>
 
-#define RELATIVE_TOLERANCE 1e-4
+#define RELATIVE_TOLERANCE 1e-9
 
 // Returns: the product of a + ib and c + id
 



More information about the llvm-commits mailing list