Message ID | 20220518073159.78707-1-hongyu.wang@intel.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4DB5B3858016 for <patchwork@sourceware.org>; Wed, 18 May 2022 07:32:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4DB5B3858016 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652859174; bh=9X/PdNeoGgB9ptAETPlqZEwLL++scL/xbjZf3OLHcuA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=CPP7rKQrt3djz5wWjTPQljQtuFQ7Z8WW/eJEulTK6OLgElfwzBpHp98yDDImv6B9d LYSilkcLfnzayi+b/7xGvIs9SR288hsqfqLxMgNNLd54jBgspOUiK9C15bB0bKkC1L a4JMkB6bYSj9H/liFiDBHLV4GbPcDQglH41F/74o= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by sourceware.org (Postfix) with ESMTPS id A47093858C52 for <gcc-patches@gcc.gnu.org>; Wed, 18 May 2022 07:32:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A47093858C52 X-IronPort-AV: E=McAfee;i="6400,9594,10350"; a="251426325" X-IronPort-AV: E=Sophos;i="5.91,234,1647327600"; d="scan'208";a="251426325" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 May 2022 00:32:01 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,234,1647327600"; d="scan'208";a="700469657" Received: from scymds01.sc.intel.com ([10.148.94.138]) by orsmga004.jf.intel.com with ESMTP; 18 May 2022 00:32:01 -0700 Received: from shliclel320.sh.intel.com (shliclel320.sh.intel.com [10.239.236.50]) by scymds01.sc.intel.com with ESMTP id 24I7VxCt025858; Wed, 18 May 2022 00:32:00 -0700 To: ubizjak@gmail.com Subject: [PATCH] i386: Add a constraint for absolute symboilc address [PR 105576] Date: Wed, 18 May 2022 15:31:59 +0800 Message-Id: <20220518073159.78707-1-hongyu.wang@intel.com> X-Mailer: git-send-email 2.18.1 X-Spam-Status: No, score=-10.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_SHORT, KAM_STOCKGEN, SPF_HELO_PASS, SPF_SOFTFAIL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Hongyu Wang via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Hongyu Wang <hongyu.wang@intel.com> Cc: hongtao.liu@intel.com, gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
i386: Add a constraint for absolute symboilc address [PR 105576]
|
|
Commit Message
Hongyu Wang
May 18, 2022, 7:31 a.m. UTC
Hi, This patch adds a constraint "Ws" to allow absolute symbolic address for either function or variable. This also works under -mcmodel=large. Bootstrapped/regtested on x86_64-pc-linux-gnu{-m32,} Ok for master? gcc/ChangeLog: PR target/105576 * config/i386/constraints.md (Ws): New constraint. * config/i386/i386-protos.h (ix86_symbolic_address_p): New proto type. * config/i386/i386.cc (ix86_symbolic_address_p): New function to ensure a rtx is a symbolic address. gcc/testsuite/ChangeLog: PR target/105576 * gcc.target/i386/pr105576.c: New test. --- gcc/config/i386/constraints.md | 4 ++++ gcc/config/i386/i386-protos.h | 1 + gcc/config/i386/i386.cc | 7 +++++++ gcc/testsuite/gcc.target/i386/pr105576.c | 11 +++++++++++ 4 files changed, 23 insertions(+) create mode 100644 gcc/testsuite/gcc.target/i386/pr105576.c
Comments
On Wed, May 18, 2022 at 9:32 AM Hongyu Wang <hongyu.wang@intel.com> wrote: > > Hi, > > This patch adds a constraint "Ws" to allow absolute symbolic address for either > function or variable. This also works under -mcmodel=large. > > Bootstrapped/regtested on x86_64-pc-linux-gnu{-m32,} > > Ok for master? Maybe you should use: asm ("%p0" :: "X"(addr)); asm ("%p0" :: "X"(&var)); instead. Uros. > gcc/ChangeLog: > > PR target/105576 > * config/i386/constraints.md (Ws): New constraint. > * config/i386/i386-protos.h (ix86_symbolic_address_p): > New proto type. > * config/i386/i386.cc (ix86_symbolic_address_p): > New function to ensure a rtx is a symbolic address. > > gcc/testsuite/ChangeLog: > > PR target/105576 > * gcc.target/i386/pr105576.c: New test. > --- > gcc/config/i386/constraints.md | 4 ++++ > gcc/config/i386/i386-protos.h | 1 + > gcc/config/i386/i386.cc | 7 +++++++ > gcc/testsuite/gcc.target/i386/pr105576.c | 11 +++++++++++ > 4 files changed, 23 insertions(+) > create mode 100644 gcc/testsuite/gcc.target/i386/pr105576.c > > diff --git a/gcc/config/i386/constraints.md b/gcc/config/i386/constraints.md > index 7361687632f..ec0702be368 100644 > --- a/gcc/config/i386/constraints.md > +++ b/gcc/config/i386/constraints.md > @@ -348,6 +348,10 @@ (define_constraint "Z" > instructions)." > (match_operand 0 "x86_64_zext_immediate_operand")) > > +(define_constraint "Ws" > + "A constraint that matches an absolute symbolic address." > + (match_test "ix86_symbolic_address_p (op)")) > + > ;; T prefix is used for different address constraints > ;; v - VSIB address > ;; s - address with no segment register > diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h > index 3596ce81ecf..2b8d063850f 100644 > --- a/gcc/config/i386/i386-protos.h > +++ b/gcc/config/i386/i386-protos.h > @@ -337,6 +337,7 @@ extern void x86_output_aligned_bss (FILE *, tree, const char *, > unsigned HOST_WIDE_INT, unsigned); > extern void x86_elf_aligned_decl_common (FILE *, tree, const char *, > unsigned HOST_WIDE_INT, unsigned); > +extern bool ix86_symbolic_address_p (rtx x); > > #ifdef RTX_CODE > extern void ix86_fp_comparison_codes (enum rtx_code code, enum rtx_code *, > diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc > index 86752a6516a..76728d10c8d 100644 > --- a/gcc/config/i386/i386.cc > +++ b/gcc/config/i386/i386.cc > @@ -23956,6 +23956,13 @@ ix86_push_rounding (poly_int64 bytes) > return ROUND_UP (bytes, UNITS_PER_WORD); > } > > +bool ix86_symbolic_address_p (rtx x) > +{ > + poly_int64 offset; > + x = strip_offset (x, &offset); > + return SYMBOL_REF_P (x) || LABEL_REF_P (x); > +} > + > /* Target-specific selftests. */ > > #if CHECKING_P > diff --git a/gcc/testsuite/gcc.target/i386/pr105576.c b/gcc/testsuite/gcc.target/i386/pr105576.c > new file mode 100644 > index 00000000000..06dd860d3f3 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/i386/pr105576.c > @@ -0,0 +1,11 @@ > +/* PR target/105576 */ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -mcmodel=large" } */ > + > +extern int var; > +void *addr(void) { return &var; } > +void addr_via_asm(void) > +{ > + asm (".pushsection .xxx,\"aw\"\n\t .dc.a %0\n\t .popsection" :: "Ws"(addr)); > + asm (".pushsection .xxx,\"aw\"\n\t .dc.a %0\n\t .popsection" :: "Ws"(&var)); > +} > -- > 2.18.1 >
Oh, I just found that asm ("%p0" :: "i"(addr)); also works on -mcmodel=large in this case, please ignore this patch. Thanks. Uros Bizjak via Gcc-patches <gcc-patches@gcc.gnu.org> 于2022年5月18日周三 17:46写道: > > On Wed, May 18, 2022 at 9:32 AM Hongyu Wang <hongyu.wang@intel.com> wrote: > > > > Hi, > > > > This patch adds a constraint "Ws" to allow absolute symbolic address for either > > function or variable. This also works under -mcmodel=large. > > > > Bootstrapped/regtested on x86_64-pc-linux-gnu{-m32,} > > > > Ok for master? > > Maybe you should use: > > asm ("%p0" :: "X"(addr)); > asm ("%p0" :: "X"(&var)); > > instead. > > Uros. > > > gcc/ChangeLog: > > > > PR target/105576 > > * config/i386/constraints.md (Ws): New constraint. > > * config/i386/i386-protos.h (ix86_symbolic_address_p): > > New proto type. > > * config/i386/i386.cc (ix86_symbolic_address_p): > > New function to ensure a rtx is a symbolic address. > > > > gcc/testsuite/ChangeLog: > > > > PR target/105576 > > * gcc.target/i386/pr105576.c: New test. > > --- > > gcc/config/i386/constraints.md | 4 ++++ > > gcc/config/i386/i386-protos.h | 1 + > > gcc/config/i386/i386.cc | 7 +++++++ > > gcc/testsuite/gcc.target/i386/pr105576.c | 11 +++++++++++ > > 4 files changed, 23 insertions(+) > > create mode 100644 gcc/testsuite/gcc.target/i386/pr105576.c > > > > diff --git a/gcc/config/i386/constraints.md b/gcc/config/i386/constraints.md > > index 7361687632f..ec0702be368 100644 > > --- a/gcc/config/i386/constraints.md > > +++ b/gcc/config/i386/constraints.md > > @@ -348,6 +348,10 @@ (define_constraint "Z" > > instructions)." > > (match_operand 0 "x86_64_zext_immediate_operand")) > > > > +(define_constraint "Ws" > > + "A constraint that matches an absolute symbolic address." > > + (match_test "ix86_symbolic_address_p (op)")) > > + > > ;; T prefix is used for different address constraints > > ;; v - VSIB address > > ;; s - address with no segment register > > diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h > > index 3596ce81ecf..2b8d063850f 100644 > > --- a/gcc/config/i386/i386-protos.h > > +++ b/gcc/config/i386/i386-protos.h > > @@ -337,6 +337,7 @@ extern void x86_output_aligned_bss (FILE *, tree, const char *, > > unsigned HOST_WIDE_INT, unsigned); > > extern void x86_elf_aligned_decl_common (FILE *, tree, const char *, > > unsigned HOST_WIDE_INT, unsigned); > > +extern bool ix86_symbolic_address_p (rtx x); > > > > #ifdef RTX_CODE > > extern void ix86_fp_comparison_codes (enum rtx_code code, enum rtx_code *, > > diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc > > index 86752a6516a..76728d10c8d 100644 > > --- a/gcc/config/i386/i386.cc > > +++ b/gcc/config/i386/i386.cc > > @@ -23956,6 +23956,13 @@ ix86_push_rounding (poly_int64 bytes) > > return ROUND_UP (bytes, UNITS_PER_WORD); > > } > > > > +bool ix86_symbolic_address_p (rtx x) > > +{ > > + poly_int64 offset; > > + x = strip_offset (x, &offset); > > + return SYMBOL_REF_P (x) || LABEL_REF_P (x); > > +} > > + > > /* Target-specific selftests. */ > > > > #if CHECKING_P > > diff --git a/gcc/testsuite/gcc.target/i386/pr105576.c b/gcc/testsuite/gcc.target/i386/pr105576.c > > new file mode 100644 > > index 00000000000..06dd860d3f3 > > --- /dev/null > > +++ b/gcc/testsuite/gcc.target/i386/pr105576.c > > @@ -0,0 +1,11 @@ > > +/* PR target/105576 */ > > +/* { dg-do compile } */ > > +/* { dg-options "-O2 -mcmodel=large" } */ > > + > > +extern int var; > > +void *addr(void) { return &var; } > > +void addr_via_asm(void) > > +{ > > + asm (".pushsection .xxx,\"aw\"\n\t .dc.a %0\n\t .popsection" :: "Ws"(addr)); > > + asm (".pushsection .xxx,\"aw\"\n\t .dc.a %0\n\t .popsection" :: "Ws"(&var)); > > +} > > -- > > 2.18.1 > >
On Wed, May 18, 2022 at 12:14 PM Hongyu Wang <wwwhhhyyy333@gmail.com> wrote: > > Oh, I just found that asm ("%p0" :: "i"(addr)); also works on > -mcmodel=large in this case, please ignore this patch. Thanks. -fpic will break compilation with "i" constraint. Uros. > > Uros Bizjak via Gcc-patches <gcc-patches@gcc.gnu.org> 于2022年5月18日周三 17:46写道: > > > > On Wed, May 18, 2022 at 9:32 AM Hongyu Wang <hongyu.wang@intel.com> wrote: > > > > > > Hi, > > > > > > This patch adds a constraint "Ws" to allow absolute symbolic address for either > > > function or variable. This also works under -mcmodel=large. > > > > > > Bootstrapped/regtested on x86_64-pc-linux-gnu{-m32,} > > > > > > Ok for master? > > > > Maybe you should use: > > > > asm ("%p0" :: "X"(addr)); > > asm ("%p0" :: "X"(&var)); > > > > instead. > > > > Uros. > > > > > gcc/ChangeLog: > > > > > > PR target/105576 > > > * config/i386/constraints.md (Ws): New constraint. > > > * config/i386/i386-protos.h (ix86_symbolic_address_p): > > > New proto type. > > > * config/i386/i386.cc (ix86_symbolic_address_p): > > > New function to ensure a rtx is a symbolic address. > > > > > > gcc/testsuite/ChangeLog: > > > > > > PR target/105576 > > > * gcc.target/i386/pr105576.c: New test. > > > --- > > > gcc/config/i386/constraints.md | 4 ++++ > > > gcc/config/i386/i386-protos.h | 1 + > > > gcc/config/i386/i386.cc | 7 +++++++ > > > gcc/testsuite/gcc.target/i386/pr105576.c | 11 +++++++++++ > > > 4 files changed, 23 insertions(+) > > > create mode 100644 gcc/testsuite/gcc.target/i386/pr105576.c > > > > > > diff --git a/gcc/config/i386/constraints.md b/gcc/config/i386/constraints.md > > > index 7361687632f..ec0702be368 100644 > > > --- a/gcc/config/i386/constraints.md > > > +++ b/gcc/config/i386/constraints.md > > > @@ -348,6 +348,10 @@ (define_constraint "Z" > > > instructions)." > > > (match_operand 0 "x86_64_zext_immediate_operand")) > > > > > > +(define_constraint "Ws" > > > + "A constraint that matches an absolute symbolic address." > > > + (match_test "ix86_symbolic_address_p (op)")) > > > + > > > ;; T prefix is used for different address constraints > > > ;; v - VSIB address > > > ;; s - address with no segment register > > > diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h > > > index 3596ce81ecf..2b8d063850f 100644 > > > --- a/gcc/config/i386/i386-protos.h > > > +++ b/gcc/config/i386/i386-protos.h > > > @@ -337,6 +337,7 @@ extern void x86_output_aligned_bss (FILE *, tree, const char *, > > > unsigned HOST_WIDE_INT, unsigned); > > > extern void x86_elf_aligned_decl_common (FILE *, tree, const char *, > > > unsigned HOST_WIDE_INT, unsigned); > > > +extern bool ix86_symbolic_address_p (rtx x); > > > > > > #ifdef RTX_CODE > > > extern void ix86_fp_comparison_codes (enum rtx_code code, enum rtx_code *, > > > diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc > > > index 86752a6516a..76728d10c8d 100644 > > > --- a/gcc/config/i386/i386.cc > > > +++ b/gcc/config/i386/i386.cc > > > @@ -23956,6 +23956,13 @@ ix86_push_rounding (poly_int64 bytes) > > > return ROUND_UP (bytes, UNITS_PER_WORD); > > > } > > > > > > +bool ix86_symbolic_address_p (rtx x) > > > +{ > > > + poly_int64 offset; > > > + x = strip_offset (x, &offset); > > > + return SYMBOL_REF_P (x) || LABEL_REF_P (x); > > > +} > > > + > > > /* Target-specific selftests. */ > > > > > > #if CHECKING_P > > > diff --git a/gcc/testsuite/gcc.target/i386/pr105576.c b/gcc/testsuite/gcc.target/i386/pr105576.c > > > new file mode 100644 > > > index 00000000000..06dd860d3f3 > > > --- /dev/null > > > +++ b/gcc/testsuite/gcc.target/i386/pr105576.c > > > @@ -0,0 +1,11 @@ > > > +/* PR target/105576 */ > > > +/* { dg-do compile } */ > > > +/* { dg-options "-O2 -mcmodel=large" } */ > > > + > > > +extern int var; > > > +void *addr(void) { return &var; } > > > +void addr_via_asm(void) > > > +{ > > > + asm (".pushsection .xxx,\"aw\"\n\t .dc.a %0\n\t .popsection" :: "Ws"(addr)); > > > + asm (".pushsection .xxx,\"aw\"\n\t .dc.a %0\n\t .popsection" :: "Ws"(&var)); > > > +} > > > -- > > > 2.18.1 > > >
> -fpic will break compilation with "i" constraint. Ah, yes. But "X" is like no constraint, shouldn't we provide something similar to "S" in aarch64 and riscv? I think it is better to constrain the operand to constant symbols rather than allowing everything. Uros Bizjak <ubizjak@gmail.com> 于2022年5月18日周三 18:18写道: > > On Wed, May 18, 2022 at 12:14 PM Hongyu Wang <wwwhhhyyy333@gmail.com> wrote: > > > > Oh, I just found that asm ("%p0" :: "i"(addr)); also works on > > -mcmodel=large in this case, please ignore this patch. Thanks. > > -fpic will break compilation with "i" constraint. > > Uros. > > > > > Uros Bizjak via Gcc-patches <gcc-patches@gcc.gnu.org> 于2022年5月18日周三 17:46写道: > > > > > > On Wed, May 18, 2022 at 9:32 AM Hongyu Wang <hongyu.wang@intel.com> wrote: > > > > > > > > Hi, > > > > > > > > This patch adds a constraint "Ws" to allow absolute symbolic address for either > > > > function or variable. This also works under -mcmodel=large. > > > > > > > > Bootstrapped/regtested on x86_64-pc-linux-gnu{-m32,} > > > > > > > > Ok for master? > > > > > > Maybe you should use: > > > > > > asm ("%p0" :: "X"(addr)); > > > asm ("%p0" :: "X"(&var)); > > > > > > instead. > > > > > > Uros. > > > > > > > gcc/ChangeLog: > > > > > > > > PR target/105576 > > > > * config/i386/constraints.md (Ws): New constraint. > > > > * config/i386/i386-protos.h (ix86_symbolic_address_p): > > > > New proto type. > > > > * config/i386/i386.cc (ix86_symbolic_address_p): > > > > New function to ensure a rtx is a symbolic address. > > > > > > > > gcc/testsuite/ChangeLog: > > > > > > > > PR target/105576 > > > > * gcc.target/i386/pr105576.c: New test. > > > > --- > > > > gcc/config/i386/constraints.md | 4 ++++ > > > > gcc/config/i386/i386-protos.h | 1 + > > > > gcc/config/i386/i386.cc | 7 +++++++ > > > > gcc/testsuite/gcc.target/i386/pr105576.c | 11 +++++++++++ > > > > 4 files changed, 23 insertions(+) > > > > create mode 100644 gcc/testsuite/gcc.target/i386/pr105576.c > > > > > > > > diff --git a/gcc/config/i386/constraints.md b/gcc/config/i386/constraints.md > > > > index 7361687632f..ec0702be368 100644 > > > > --- a/gcc/config/i386/constraints.md > > > > +++ b/gcc/config/i386/constraints.md > > > > @@ -348,6 +348,10 @@ (define_constraint "Z" > > > > instructions)." > > > > (match_operand 0 "x86_64_zext_immediate_operand")) > > > > > > > > +(define_constraint "Ws" > > > > + "A constraint that matches an absolute symbolic address." > > > > + (match_test "ix86_symbolic_address_p (op)")) > > > > + > > > > ;; T prefix is used for different address constraints > > > > ;; v - VSIB address > > > > ;; s - address with no segment register > > > > diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h > > > > index 3596ce81ecf..2b8d063850f 100644 > > > > --- a/gcc/config/i386/i386-protos.h > > > > +++ b/gcc/config/i386/i386-protos.h > > > > @@ -337,6 +337,7 @@ extern void x86_output_aligned_bss (FILE *, tree, const char *, > > > > unsigned HOST_WIDE_INT, unsigned); > > > > extern void x86_elf_aligned_decl_common (FILE *, tree, const char *, > > > > unsigned HOST_WIDE_INT, unsigned); > > > > +extern bool ix86_symbolic_address_p (rtx x); > > > > > > > > #ifdef RTX_CODE > > > > extern void ix86_fp_comparison_codes (enum rtx_code code, enum rtx_code *, > > > > diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc > > > > index 86752a6516a..76728d10c8d 100644 > > > > --- a/gcc/config/i386/i386.cc > > > > +++ b/gcc/config/i386/i386.cc > > > > @@ -23956,6 +23956,13 @@ ix86_push_rounding (poly_int64 bytes) > > > > return ROUND_UP (bytes, UNITS_PER_WORD); > > > > } > > > > > > > > +bool ix86_symbolic_address_p (rtx x) > > > > +{ > > > > + poly_int64 offset; > > > > + x = strip_offset (x, &offset); > > > > + return SYMBOL_REF_P (x) || LABEL_REF_P (x); > > > > +} > > > > + > > > > /* Target-specific selftests. */ > > > > > > > > #if CHECKING_P > > > > diff --git a/gcc/testsuite/gcc.target/i386/pr105576.c b/gcc/testsuite/gcc.target/i386/pr105576.c > > > > new file mode 100644 > > > > index 00000000000..06dd860d3f3 > > > > --- /dev/null > > > > +++ b/gcc/testsuite/gcc.target/i386/pr105576.c > > > > @@ -0,0 +1,11 @@ > > > > +/* PR target/105576 */ > > > > +/* { dg-do compile } */ > > > > +/* { dg-options "-O2 -mcmodel=large" } */ > > > > + > > > > +extern int var; > > > > +void *addr(void) { return &var; } > > > > +void addr_via_asm(void) > > > > +{ > > > > + asm (".pushsection .xxx,\"aw\"\n\t .dc.a %0\n\t .popsection" :: "Ws"(addr)); > > > > + asm (".pushsection .xxx,\"aw\"\n\t .dc.a %0\n\t .popsection" :: "Ws"(&var)); > > > > +} > > > > -- > > > > 2.18.1 > > > >
diff --git a/gcc/config/i386/constraints.md b/gcc/config/i386/constraints.md index 7361687632f..ec0702be368 100644 --- a/gcc/config/i386/constraints.md +++ b/gcc/config/i386/constraints.md @@ -348,6 +348,10 @@ (define_constraint "Z" instructions)." (match_operand 0 "x86_64_zext_immediate_operand")) +(define_constraint "Ws" + "A constraint that matches an absolute symbolic address." + (match_test "ix86_symbolic_address_p (op)")) + ;; T prefix is used for different address constraints ;; v - VSIB address ;; s - address with no segment register diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h index 3596ce81ecf..2b8d063850f 100644 --- a/gcc/config/i386/i386-protos.h +++ b/gcc/config/i386/i386-protos.h @@ -337,6 +337,7 @@ extern void x86_output_aligned_bss (FILE *, tree, const char *, unsigned HOST_WIDE_INT, unsigned); extern void x86_elf_aligned_decl_common (FILE *, tree, const char *, unsigned HOST_WIDE_INT, unsigned); +extern bool ix86_symbolic_address_p (rtx x); #ifdef RTX_CODE extern void ix86_fp_comparison_codes (enum rtx_code code, enum rtx_code *, diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index 86752a6516a..76728d10c8d 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -23956,6 +23956,13 @@ ix86_push_rounding (poly_int64 bytes) return ROUND_UP (bytes, UNITS_PER_WORD); } +bool ix86_symbolic_address_p (rtx x) +{ + poly_int64 offset; + x = strip_offset (x, &offset); + return SYMBOL_REF_P (x) || LABEL_REF_P (x); +} + /* Target-specific selftests. */ #if CHECKING_P diff --git a/gcc/testsuite/gcc.target/i386/pr105576.c b/gcc/testsuite/gcc.target/i386/pr105576.c new file mode 100644 index 00000000000..06dd860d3f3 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr105576.c @@ -0,0 +1,11 @@ +/* PR target/105576 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -mcmodel=large" } */ + +extern int var; +void *addr(void) { return &var; } +void addr_via_asm(void) +{ + asm (".pushsection .xxx,\"aw\"\n\t .dc.a %0\n\t .popsection" :: "Ws"(addr)); + asm (".pushsection .xxx,\"aw\"\n\t .dc.a %0\n\t .popsection" :: "Ws"(&var)); +}