[compiler-rt] 58f6b16 - [compiler-rt][builtins][RISCV] Always include __mul[sd]i3 builtin definitions

Luís Marques via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 21 01:49:48 PDT 2020


Author: Luís Marques
Date: 2020-10-21T09:49:03+01:00
New Revision: 58f6b16c4981f91c49f6878ac342562a7a29d385

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

LOG: [compiler-rt][builtins][RISCV] Always include __mul[sd]i3 builtin definitions

The RISC-V implementations of the `__mulsi3`, `__muldi3` builtins were
conditionally compiling the actual function definitions depending on whether
the M extension was present or not. This caused Compiler-RT testing failures
for RISC-V targets with the M extension, as when these sources were included
the `librt_has_mul*i3` features were still being defined. These `librt_has_*`
definitions are used to conditionally run the respective tests. Since the
actual functions were not being compiled-in, the generic test for `__muldi3`
would fail. This patch makes these implementations follow the normal
Compiler-RT convention of always including the definition, and conditionally
running the respective tests by using the lit conditional
`REQUIRES: librt_has_*`.

Since the `mulsi3_test.c` wasn't actually RISC-V-specific, this patch also
moves it out of the `riscv` directory. It now only depends on
`librt_has_mulsi3` to run.

Differential Revision: https://reviews.llvm.org/D86457

Added: 
    compiler-rt/test/builtins/Unit/mulsi3_test.c

Modified: 
    compiler-rt/lib/builtins/riscv/int_mul_impl.inc
    compiler-rt/test/builtins/Unit/muldi3_test.c

Removed: 
    compiler-rt/test/builtins/Unit/riscv/mulsi3_test.c


################################################################################
diff  --git a/compiler-rt/lib/builtins/riscv/int_mul_impl.inc b/compiler-rt/lib/builtins/riscv/int_mul_impl.inc
index 50951d5f4195..53699b356f6a 100644
--- a/compiler-rt/lib/builtins/riscv/int_mul_impl.inc
+++ b/compiler-rt/lib/builtins/riscv/int_mul_impl.inc
@@ -10,7 +10,10 @@
 //
 //===----------------------------------------------------------------------===//
 
-#if !defined(__riscv_mul)
+#ifndef __mulxi3
+#error "__mulxi3 must be defined to use this generic implementation"
+#endif
+
 	.text
 	.align 2
 
@@ -28,4 +31,3 @@ __mulxi3:
 	slli   a2, a2, 1
 	bnez   a1, .L1
 	ret
-#endif

diff  --git a/compiler-rt/test/builtins/Unit/muldi3_test.c b/compiler-rt/test/builtins/Unit/muldi3_test.c
index 74530cbfb09a..c03570f02980 100644
--- a/compiler-rt/test/builtins/Unit/muldi3_test.c
+++ b/compiler-rt/test/builtins/Unit/muldi3_test.c
@@ -11,7 +11,7 @@ int test__muldi3(di_int a, di_int b, di_int expected)
     di_int x = __muldi3(a, b);
     if (x != expected)
         printf("error in __muldi3: %lld * %lld = %lld, expected %lld\n",
-               a, b, __muldi3(a, b), expected);
+               a, b, x, expected);
     return x != expected;
 }
 

diff  --git a/compiler-rt/test/builtins/Unit/riscv/mulsi3_test.c b/compiler-rt/test/builtins/Unit/mulsi3_test.c
similarity index 90%
rename from compiler-rt/test/builtins/Unit/riscv/mulsi3_test.c
rename to compiler-rt/test/builtins/Unit/mulsi3_test.c
index d4621acbbbb5..0b0c14204efd 100644
--- a/compiler-rt/test/builtins/Unit/riscv/mulsi3_test.c
+++ b/compiler-rt/test/builtins/Unit/mulsi3_test.c
@@ -1,13 +1,10 @@
-// REQUIRES: riscv32-target-arch
 // RUN: %clang_builtins %s %librt -o %t && %run %t
+// REQUIRES: librt_has_mulsi3
 
 #include "int_lib.h"
 #include <stdio.h>
 #include <limits.h>
 
-#if !defined(__riscv_mul) && __riscv_xlen == 32
-// Based on mulsi3_test.c
-
 COMPILER_RT_ABI si_int __mulsi3(si_int a, si_int b);
 
 int test__mulsi3(si_int a, si_int b, si_int expected)
@@ -15,14 +12,12 @@ int test__mulsi3(si_int a, si_int b, si_int expected)
     si_int x = __mulsi3(a, b);
     if (x != expected)
         printf("error in __mulsi3: %d * %d = %d, expected %d\n",
-               a, b, __mulsi3(a, b), expected);
+               a, b, x, expected);
     return x != expected;
 }
-#endif
 
 int main()
 {
-#if !defined(__riscv_mul) && __riscv_xlen == 32
     if (test__mulsi3(0, 0, 0))
         return 1;
     if (test__mulsi3(0, 1, 0))
@@ -99,9 +94,6 @@ int main()
         return 1;
     if (test__mulsi3(-8192, -4194303, 34359730176))
         return 1;
-#else
-    printf("skipped\n");
-#endif
 
     return 0;
 }


        


More information about the llvm-commits mailing list