https://gcc.gnu.org/g:6c5937991bd744a4916e9cf65eb5d9c9b5706120

commit r15-7058-g6c5937991bd744a4916e9cf65eb5d9c9b5706120
Author: Thomas Schwinge <tschwi...@baylibre.com>
Date:   Fri Jan 17 21:45:42 2025 +0100

    nvptx: Gracefully handle '-mptx=3.1' if neither sm_30 nor sm_35 multilib 
variant is built
    
    For example, for GCC/nvptx built with '--with-arch=sm_52' (current default)
    and '--without-multilib-list', neither a sm_30 nor a sm_35 multilib variant
    is built, and thus no '-mptx=3.1' sub-variant either.  Such a configuration
    is possible as of commit 86b3a7532d56f74fcd1c362f2da7f95e8cc4e4a6
    "nvptx: Support '--with-multilib-list'", but currently results in the
    following bogus behavior:
    
        [...]/xgcc -print-multi-directory -mgomp -march=sm_52
        mgomp
        [...]/xgcc -print-multi-directory -mgomp -march=sm_35
        mgomp
        [...]/xgcc -print-multi-directory -mgomp -march=sm_30
        mgomp
        [...]/xgcc -print-multi-directory -mgomp -march=sm_35 -mptx=3.1
        .
        [...]/xgcc -print-multi-directory -mgomp -march=sm_30 -mptx=3.1
        .
    
    The latter two '.' are unexpected; linking OpenMP/nvptx offloading code
    like this fails with: 'unresolved symbol __nvptx_uni', for example.
    Instead of '.', the latter two should print 'mgomp', too.  To achieve that,
    we must not set up the '-mptx=3.1' multilib axis if no '-mptx=3.1'
    sub-variant is built.
    
            gcc/
            * config/nvptx/t-nvptx (MULTILIB_OPTIONS): Don't add 'mptx=3.1' if
            neither sm_30 nor sm_35 multilib variant is built.

Diff:
---
 gcc/config/nvptx/t-nvptx | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/gcc/config/nvptx/t-nvptx b/gcc/config/nvptx/t-nvptx
index 563c7b30dab2..b77f63bde8ff 100644
--- a/gcc/config/nvptx/t-nvptx
+++ b/gcc/config/nvptx/t-nvptx
@@ -66,11 +66,14 @@ MULTILIB_MATCHES += $(multilib_matches)
 # ..., and don't actually build what's the default '-misa':
 MULTILIB_EXCEPTIONS += *misa=$(multilib_options_isa_default)*
 
+# Build '-mptx=3.1' sub-variants, if applicable.  Per 'nvptx-sm.def',
+# 'nvptx.opt:ptx_version', 'nvptx.cc:first_ptx_version_supporting_sm':
+# only for sm_30, sm_35.
+ifneq ($(filter sm_30 sm_35,$(multilib_options_isa_list)),)
 MULTILIB_OPTIONS += mptx=3.1
-# Filter out invalid '-misa'/'-mptx=3.1' combinations; per 'nvptx-sm.def',
-# 'nvptx.opt:ptx_version', 'nvptx.cc:first_ptx_version_supporting_sm'
-# (that is, '-mptx=3.1' only for sm_30, sm_35 variants):
+# Filter out invalid '-misa'/'-mptx=3.1' combinations:
 MULTILIB_EXCEPTIONS += $(foreach misa,$(filter-out %=sm_30 
%=sm_35,$(multilib_options_misa_list)),*$(misa)/mptx=3.1)
 # ..., and special care has to be taken if '-mptx=3.1' is invalid for the
 # default variant:
 MULTILIB_EXCEPTIONS += $(if $(filter-out sm_30 
sm_35,$(multilib_options_isa_default)),mgomp/mptx=3.1 mptx=3.1)
+endif

Reply via email to