https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127253

            Bug ID: 127253
           Summary: RISC-V: Multilib matching algorithm selects wrong
                    library due to simple extension counting
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bigmagicreadsun at gmail dot com
  Target Milestone: ---

The RISC-V multilib matching algorithm uses simple extension counting to select
the best matching library, leading to incorrect selection when extensions with
different functional importance are involved.

Problem: When compiling with -march=rv32imac_zfinx_zba_zbb_zbs, the algorithm
selects rv32imac_zaamo_zalrsc_zba_zbb_zbs/ilp32/ instead of
rv32imac_zaamo_zalrsc_zfinx/ilp32/.

Root Cause: The match_score() function in
gcc/common/config/riscv/riscv-common.cc  simply counts matching extensions:

for (s = list->m_head; s != NULL; s = s->next)
  if (this->lookup (s->name.c_str ()) != NULL)
    score++;  // Simply counts matching extensions
  else
    return 0;


Analysis:

rv32imac_zaamo_zalrsc_zba_zbb_zbs matches 9 extensions → selected
rv32imac_zaamo_zalrsc_zfinx matches 8 extensions → not selected
However, zfinx provides hardware floating-point support, which is more
important than bit manipulation extensions (zba/zbb/zbs). Libraries without
zfinx use software floating-point emulation, resulting in ~30% lower Whetstone
benchmark scores.

Impact: Users specifying zfinx get libraries without hardware floating-point
support, causing performance degradation in floating-point intensive
applications.

Reply via email to