https://gcc.gnu.org/g:c9530a0e24e35a6fdce91b2002b798f44b62fd44

commit r15-5465-gc9530a0e24e35a6fdce91b2002b798f44b62fd44
Author: Dimitar Dimitrov <dimi...@dinux.eu>
Date:   Thu Nov 7 20:13:02 2024 +0200

    RISC-V: Tie MUL and DIV masks to the M extension
    
    When configuring GCC for RV32EC with:
      ./configure                                     \
          --target=riscv32-none-elf                   \
          --with-multilib-generator="rv32ec-ilp32e--" \
          --with-abi=ilp32e                           \
          --with-arch=rv32ec
    
    Then the build fails because division is erroneously left enabled:
       cc1: error: '-mdiv' requires '-march' to subsume the 'M' extension
       -fself-test: 8412281 pass(es) in 0.647173 seconds
    
    Fix by disabling MASK_DIV if multiplication is not available and -mdiv
    option has not been explicitly passed.
    
    Tested the above RV32EC-only toolchain using the GNU simulator:
                     === gcc Summary ===
    
     # of expected passes            211635
     # of unexpected failures        3004
     # of expected failures          1061
     # of unresolved testcases       5651
     # of unsupported tests          18958
    
    gcc/ChangeLog:
    
            * config/riscv/riscv.cc (riscv_override_options_internal):
            Set division option's default to disabled if multiplication
            is not available.
    
    Signed-off-by: Dimitar Dimitrov <dimi...@dinux.eu>

Diff:
---
 gcc/config/riscv/riscv.cc | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 03271d893b60..b423344d4d6b 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -10307,9 +10307,13 @@ riscv_override_options_internal (struct gcc_options 
*opts)
   const struct riscv_tune_info *cpu;
 
   /* The presence of the M extension implies that division instructions
-     are present, so include them unless explicitly disabled.  */
+     are present, so include them unless explicitly disabled.
+     Similarly, if the M extension is not available, then disable
+     division instructions, unless they are explicitly enabled.  */
   if (TARGET_MUL_OPTS_P (opts) && (target_flags_explicit & MASK_DIV) == 0)
     opts->x_target_flags |= MASK_DIV;
+  else if (!TARGET_MUL_OPTS_P (opts) && (target_flags_explicit & MASK_DIV) == 
0)
+    opts->x_target_flags &= ~MASK_DIV;
   else if (!TARGET_MUL_OPTS_P (opts) && TARGET_DIV_OPTS_P (opts))
     error ("%<-mdiv%> requires %<-march%> to subsume the %<M%> extension");

Reply via email to