From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by sourceware.org (Postfix) with ESMTPS id 8C8483853819 for ; Sun, 11 Jul 2021 13:06:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8C8483853819 Received: by mail-pl1-x631.google.com with SMTP id z2so4684718plg.8 for ; Sun, 11 Jul 2021 06:06:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=IkaU0kzAaeZvyZycOsB8o0DPVjTSDiqIH0Etf0JupIA=; b=kvJfaGT6YEbz9oz8fv7hKsvGIK3otPli3otgJQWuDzxBOOfnhPp/iOV36twbWQ8a3R YYa8KR8HmDrzJ1lXYJZkwxoisGeJ1gO9do0o5FZG9kqD6ZgrLJnEHTRymoT73p0iGhEY Vq3Df3QrYI4gnyE9IQg8Q2WH/IiULnRhVclXF81+WgMFzzp3zB8/IExeq5DfRMrL5Z/G MJb4/PufvSyuQmjTmiZSKp3Vw8N6LZIEAroNIoE+JNQgpd32/Z+ZmigH8lapwTq0MmSX yjpfeug1gbIP9x51nGI0qdXhRpum3UVkIhNOuV8SuY8aCLloAxz6CdMiEMvN7rWb8wlv QhZw== X-Gm-Message-State: AOAM530AWpINCg5bfKuaunCwFjE3gzJf7hk64fby4Jal83drmLzqWezM 3hpjD2LgyxY3Ke/XuIyemlKX3zdWEHk= X-Google-Smtp-Source: ABdhPJzBolJfkVuCN7qn0xOKqAPJ3cKhH/ECdcVoOWWd22mhwxVtL0ffLjVTxZckuhxUjDSzyaOZvw== X-Received: by 2002:a17:902:7b93:b029:127:8c1b:ea76 with SMTP id w19-20020a1709027b93b02901278c1bea76mr40116561pll.52.1626008804449; Sun, 11 Jul 2021 06:06:44 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([172.56.39.115]) by smtp.gmail.com with ESMTPSA id t10sm13617649pgv.52.2021.07.11.06.06.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jul 2021 06:06:44 -0700 (PDT) Received: from gnu-cfl-2.. (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id E483AC032A; Sun, 11 Jul 2021 06:06:42 -0700 (PDT) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: Uros Bizjak , Hongyu Wang Subject: [PATCH] x86: Don't enable UINTR in 32-bit mode Date: Sun, 11 Jul 2021 06:06:42 -0700 Message-Id: <20210711130642.21266-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3032.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 11 Jul 2021 13:06:47 -0000 UINTR is available only in 64-bit mode. Since the codegen target is unknown when the the gcc driver is processing -march=native, to properly handle UINTR for -march=native: 1. Add an undocumented option, -muintr-native. 2. Update the gcc driver to pass -muintr-native with -march=native if UINTR is available. 3. Change ix86_option_override_internal to a. Turn on UINTR in 64-bit mode for -muintr-native. b. Enable UINTR only in 64-bit mode for -march=CPU when PTA_CPU includes PTA_UINTR. gcc/ PR target/101395 * config/i386/driver-i386.c (host_detect_local_cpu): Add -muintr-native for FEATURE_UINTR. * config/i386/i386-options.c (ix86_option_override_internal): Move -muintr check after -march processing and turn on UINTR in 64-bit mode for -muintr-native if it has not been disabled explicitly. (DEF_PTA): Skip PTA_UINTR if not in 64-bit mode. * config/i386/i386.opt (muintr-native): New. Undocumented to enable -muintr only in 64-bit mode with -march=native. gcc/testsuite/ PR target/101395 * gcc.target/i386/pr101395-1.c: New test. * gcc.target/i386/pr101395-2.c: Likewise. * gcc.target/i386/pr101395-3.c: Likewise. --- gcc/config/i386/driver-i386.c | 10 ++++++++-- gcc/config/i386/i386-options.c | 14 +++++++++++--- gcc/config/i386/i386.opt | 4 ++++ gcc/testsuite/gcc.target/i386/pr101395-1.c | 12 ++++++++++++ gcc/testsuite/gcc.target/i386/pr101395-2.c | 22 ++++++++++++++++++++++ gcc/testsuite/gcc.target/i386/pr101395-3.c | 6 ++++++ 6 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr101395-1.c create mode 100644 gcc/testsuite/gcc.target/i386/pr101395-2.c create mode 100644 gcc/testsuite/gcc.target/i386/pr101395-3.c diff --git a/gcc/config/i386/driver-i386.c b/gcc/config/i386/driver-i386.c index dd9236616b4..7ade90a088d 100644 --- a/gcc/config/i386/driver-i386.c +++ b/gcc/config/i386/driver-i386.c @@ -804,8 +804,14 @@ const char *host_detect_local_cpu (int argc, const char **argv) if (isa_names_table[i].option) { if (has_feature (isa_names_table[i].feature)) - options = concat (options, " ", - isa_names_table[i].option, NULL); + { + const char *option; + if (isa_names_table[i].feature == FEATURE_UINTR) + option = "-muintr-native"; + else + option = isa_names_table[i].option; + options = concat (options, " ", option, NULL); + } else options = concat (options, neg_option, isa_names_table[i].option + 2, NULL); diff --git a/gcc/config/i386/i386-options.c b/gcc/config/i386/i386-options.c index 7a35c468da3..6b12f030f0c 100644 --- a/gcc/config/i386/i386-options.c +++ b/gcc/config/i386/i386-options.c @@ -1920,9 +1920,6 @@ ix86_option_override_internal (bool main_args_p, opts->x_ix86_stringop_alg = no_stringop; } - if (TARGET_UINTR && !TARGET_64BIT) - error ("%<-muintr%> not supported for 32-bit code"); - if (!opts->x_ix86_arch_string) opts->x_ix86_arch_string = TARGET_64BIT_P (opts->x_ix86_isa_flags) @@ -2109,6 +2106,7 @@ ix86_option_override_internal (bool main_args_p, #define DEF_PTA(NAME) \ if (((processor_alias_table[i].flags & PTA_ ## NAME) != 0) \ && PTA_ ## NAME != PTA_64BIT \ + && (TARGET_64BIT || PTA_ ## NAME != PTA_UINTR) \ && !TARGET_EXPLICIT_ ## NAME ## _P (opts)) \ SET_TARGET_ ## NAME (opts); #include "i386-isa.def" @@ -2184,6 +2182,16 @@ ix86_option_override_internal (bool main_args_p, XDELETEVEC (s); } + if (TARGET_64BIT) + { + /* Turn on UINTR in 64-bit mode for -muintr-native if it has not + been set explicitly. */ + if (ix86_uintr_native && !TARGET_EXPLICIT_UINTR_P (opts)) + SET_TARGET_UINTR (opts); + } + else if (TARGET_UINTR) + error ("%<-muintr%> not supported for 32-bit code"); + ix86_arch_mask = HOST_WIDE_INT_1U << ix86_arch; for (i = 0; i < X86_ARCH_LAST; ++i) ix86_arch_features[i] = !!(initial_ix86_arch_features[i] & ix86_arch_mask); diff --git a/gcc/config/i386/i386.opt b/gcc/config/i386/i386.opt index 7b8547bb1c3..5923bbfb40e 100644 --- a/gcc/config/i386/i386.opt +++ b/gcc/config/i386/i386.opt @@ -802,6 +802,10 @@ muintr Target Mask(ISA2_UINTR) Var(ix86_isa_flags2) Save Support UINTR built-in functions and code generation. +; Used to enable -muintr only in 64-bit mode with -march=native. +muintr-native +Target Undocumented RejectNegative Var(ix86_uintr_native) + msgx Target Mask(ISA2_SGX) Var(ix86_isa_flags2) Save Support SGX built-in functions and code generation. diff --git a/gcc/testsuite/gcc.target/i386/pr101395-1.c b/gcc/testsuite/gcc.target/i386/pr101395-1.c new file mode 100644 index 00000000000..74c8bfe891a --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr101395-1.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=sapphirerapids" } */ + +#ifdef __x86_64__ +# ifndef __UINTR__ +# error UINTR is not enabled for Sapphirerapids +# endif +#else +# ifdef __UINTR__ +# error UINTR is not usable in 32-bit mode +# endif +#endif diff --git a/gcc/testsuite/gcc.target/i386/pr101395-2.c b/gcc/testsuite/gcc.target/i386/pr101395-2.c new file mode 100644 index 00000000000..f2b677f8c80 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr101395-2.c @@ -0,0 +1,22 @@ +/* { dg-do run } */ +/* { dg-options "-O2 -march=native" } */ + +int +main () +{ + if (__builtin_cpu_supports ("uintr")) + { +#ifdef __x86_64__ +# ifndef __UINTR__ + __builtin_abort (); +# endif +#else +# ifdef __UINTR__ + __builtin_abort (); +# endif +#endif + return 0; + } + + return 0; +} diff --git a/gcc/testsuite/gcc.target/i386/pr101395-3.c b/gcc/testsuite/gcc.target/i386/pr101395-3.c new file mode 100644 index 00000000000..bc6ab423c93 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr101395-3.c @@ -0,0 +1,6 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=native -mno-uintr" } */ + +#ifdef __UINTR__ +# error UINTR should be disabled +#endif -- 2.31.1