public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jan Hubicka <hubicka@ucw.cz>
To: Alexander Monakov <amonakov@ispras.ru>
Cc: Jan Hubicka <hubicka@ucw.cz>, Jeff Law <law@redhat.com>,
	Uros Bizjak <ubizjak@gmail.com>,
	"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>,
	Rich Felker <dalias@libc.org>
Subject: Re: [PATCH i386] Extend sibcall peepholes to allow source in %eax
Date: Wed, 13 May 2015 20:04:00 -0000	[thread overview]
Message-ID: <20150513200225.GA20903@kam.mff.cuni.cz> (raw)
In-Reply-To: <alpine.LNX.2.11.1505132122350.22867@monopod.intra.ispras.ru>

> On Mon, 11 May 2015, Jan Hubicka wrote:
> > Yes, to make my original email clear, I think we are safe to remove
> > peep2_reg_dead_p.
> > 
> > I would however introduce a check that the call target is not also among
> > parameters of the function. In this case the peephole would remove the load
> > and make the parameter unefined.
> > 
> > While current mainline don't seem to be able to translate the testcase above
> > that way, perhaps future improvements to LRA/postreload gcse may make it happen
> > and generally RTL patterns are better to be safe by definition not
> > only for the actual RTL we are able to generate. I suppose reg_mentioned_p
> > on call usage is enough.
> 
> Thanks.  I have bootstrapped and regtested the following patch.  OK?
> 
> 	* config/i386/i386.md (sibcall_memory): Check that register with
> 	callee address is not also used as one of the arguments, instead
> 	of checking that it is not live after the sibcall.
> 	(sibcall_pop_memory): Ditto.
> 	(sibcall_value_memory): Ditto.
> 	(sibcall_value_pop_memory): Ditto.
> testsuite:
> 	* gcc.target/i386/sibcall-7.c: New test.

Thank you! This looks fine.  Please add also the testcase that should break if
the new test was wrong andosmeone fixed postreload to allow use of the same register
this check will prevent wrong code?

OK with that change.
Honza
> 
> diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
> index 0959aef..9c1aa7d 100644
> --- a/gcc/config/i386/i386.md
> +++ b/gcc/config/i386/i386.md
> @@ -11673,7 +11673,8 @@
>     (call (mem:QI (match_dup 0))
>          (match_operand 3))]
>    "!TARGET_X32 && SIBLING_CALL_P (peep2_next_insn (1))
> -   && peep2_reg_dead_p (2, operands[0])"
> +   && !reg_mentioned_p (operands[0],
> +                       CALL_INSN_FUNCTION_USAGE (peep2_next_insn (1)))"
>    [(parallel [(call (mem:QI (match_dup 1))
>                     (match_dup 3))
>               (unspec [(const_int 0)] UNSPEC_PEEPSIB)])])
> @@ -11685,7 +11686,8 @@
>     (call (mem:QI (match_dup 0))
>          (match_operand 3))]
>    "!TARGET_X32 && SIBLING_CALL_P (peep2_next_insn (2))
> -   && peep2_reg_dead_p (3, operands[0])"
> +   && !reg_mentioned_p (operands[0],
> +                       CALL_INSN_FUNCTION_USAGE (peep2_next_insn (2)))"
>    [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
>     (parallel [(call (mem:QI (match_dup 1))
>                     (match_dup 3))
> @@ -11744,7 +11746,8 @@
>                    (plus:SI (reg:SI SP_REG)
>                             (match_operand:SI 4 "immediate_operand")))])]
>    "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (1))
> -   && peep2_reg_dead_p (2, operands[0])"
> +   && !reg_mentioned_p (operands[0],
> +                       CALL_INSN_FUNCTION_USAGE (peep2_next_insn (1)))"
>    [(parallel [(call (mem:QI (match_dup 1))
>                     (match_dup 3))
>               (set (reg:SI SP_REG)
> @@ -11762,7 +11765,8 @@
>                    (plus:SI (reg:SI SP_REG)
>                             (match_operand:SI 4 "immediate_operand")))])]
>    "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (2))
> -   && peep2_reg_dead_p (3, operands[0])"
> +   && !reg_mentioned_p (operands[0],
> +                       CALL_INSN_FUNCTION_USAGE (peep2_next_insn (2)))"
>    [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
>     (parallel [(call (mem:QI (match_dup 1))
>                     (match_dup 3))
> @@ -11838,7 +11842,8 @@
>     (call (mem:QI (match_dup 0))
>                  (match_operand 3)))]
>    "!TARGET_X32 && SIBLING_CALL_P (peep2_next_insn (1))
> -   && peep2_reg_dead_p (2, operands[0])"
> +   && !reg_mentioned_p (operands[0],
> +                       CALL_INSN_FUNCTION_USAGE (peep2_next_insn (1)))"
>    [(parallel [(set (match_dup 2)
>                    (call (mem:QI (match_dup 1))
>                          (match_dup 3)))
> @@ -11852,7 +11857,8 @@
>        (call (mem:QI (match_dup 0))
>               (match_operand 3)))]
>    "!TARGET_X32 && SIBLING_CALL_P (peep2_next_insn (2))
> -   && peep2_reg_dead_p (3, operands[0])"
> +   && !reg_mentioned_p (operands[0],
> +                       CALL_INSN_FUNCTION_USAGE (peep2_next_insn (2)))"
>    [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
>     (parallel [(set (match_dup 2)
>                    (call (mem:QI (match_dup 1))
> @@ -11917,7 +11923,8 @@
>                    (plus:SI (reg:SI SP_REG)
>                             (match_operand:SI 4 "immediate_operand")))])]
>    "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (1))
> -   && peep2_reg_dead_p (2, operands[0])"
> +   && !reg_mentioned_p (operands[0],
> +                       CALL_INSN_FUNCTION_USAGE (peep2_next_insn (1)))"
>    [(parallel [(set (match_dup 2)
>                    (call (mem:QI (match_dup 1))
>                          (match_dup 3)))
> @@ -11937,7 +11944,8 @@
>                    (plus:SI (reg:SI SP_REG)
>                             (match_operand:SI 4 "immediate_operand")))])]
>    "!TARGET_64BIT && SIBLING_CALL_P (peep2_next_insn (2))
> -   && peep2_reg_dead_p (3, operands[0])"
> +   && !reg_mentioned_p (operands[0],
> +                       CALL_INSN_FUNCTION_USAGE (peep2_next_insn (2)))"
>    [(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)
>     (parallel [(set (match_dup 2)
>                    (call (mem:QI (match_dup 1))
> diff --git a/gcc/testsuite/gcc.target/i386/sibcall-7.c b/gcc/testsuite/gcc.target/i386/sibcall-7.c
> index e69de29..72fdaff 100644
> --- a/gcc/testsuite/gcc.target/i386/sibcall-7.c
> +++ b/gcc/testsuite/gcc.target/i386/sibcall-7.c
> @@ -0,0 +1,11 @@
> +/* { dg-do compile { target { { ! x32 } } } } */
> +/* { dg-options "-O2" } */
> +
> +int foo()
> +{
> +  int (**bar)(void);
> +  asm("":"=a"(bar));
> +  return (*bar)();
> +}
> +
> +/* { dg-final { scan-assembler-not "mov" } } */

  reply	other threads:[~2015-05-13 20:02 UTC|newest]

Thread overview: 106+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-04 16:38 PIC calls without PLT, generic implementation Alexander Monakov
2015-05-04 16:38 ` [PATCH i386] Move CLOBBERED_REGS earlier in register class list Alexander Monakov
2015-05-10 16:44   ` Jan Hubicka
2015-05-10 17:51     ` Uros Bizjak
2015-05-10 18:09       ` Uros Bizjak
2015-05-11 16:26         ` Alexander Monakov
2015-05-11 16:30           ` Uros Bizjak
2015-05-04 16:38 ` [PATCH i386] Extend sibcall peepholes to allow source in %eax Alexander Monakov
2015-05-10 16:54   ` Jan Hubicka
2015-05-11 17:50     ` Alexander Monakov
2015-05-11 18:00       ` Jan Hubicka
2015-05-11 19:46         ` Uros Bizjak
2015-05-11 19:48           ` Jeff Law
2015-05-11 20:16             ` Jan Hubicka
2015-05-13 19:05               ` Alexander Monakov
2015-05-13 20:04                 ` Jan Hubicka [this message]
2015-05-14 17:36                   ` Alexander Monakov
2015-05-04 16:38 ` [RFC PATCH] ira: accept loads via argp rtx in validate_equiv_mem Alexander Monakov
2015-05-04 17:37   ` Jeff Law
2015-05-04 16:38 ` [PATCH i386] PR65753: allow PIC tail calls via function pointers Alexander Monakov
2015-05-10 16:37   ` Jan Hubicka
2015-05-11 16:11     ` Alexander Monakov
2015-05-04 16:38 ` [PATCH i386] Allow sibcalls in no-PLT PIC Alexander Monakov
2015-05-15 16:37   ` Alexander Monakov
2015-05-15 16:48     ` H.J. Lu
2015-05-15 20:08       ` Jan Hubicka
2015-05-15 20:23         ` H.J. Lu
2015-05-15 20:35           ` Rich Felker
2015-05-15 20:37             ` H.J. Lu
2015-05-15 20:45               ` Rich Felker
2015-05-15 22:16                 ` H.J. Lu
2015-05-15 23:14                   ` Jan Hubicka
2015-05-15 23:30                     ` H.J. Lu
2015-05-15 23:35                       ` H.J. Lu
2015-05-15 23:44                         ` H.J. Lu
2015-05-16  0:18                           ` Rich Felker
2015-05-16 14:33                             ` H.J. Lu
2015-05-16 19:03                               ` H.J. Lu
2015-05-16 19:32                                 ` Rich Felker
2015-05-16 23:23                                   ` H.J. Lu
2015-05-15 23:49                       ` Rich Felker
2015-05-19 14:48                         ` Michael Matz
2015-05-19 15:11                           ` Jeff Law
2015-05-19 16:03                             ` Michael Matz
2015-05-19 19:11                               ` Rich Felker
2015-05-19 18:08                           ` Rich Felker
2015-05-19 19:03                             ` Richard Henderson
2015-05-19 19:10                               ` H.J. Lu
2015-05-19 19:17                                 ` Richard Henderson
2015-05-19 19:20                                   ` H.J. Lu
2015-05-19 19:54                                     ` Richard Henderson
2015-05-19 20:27                                     ` Rich Felker
2015-05-19 20:44                                       ` H.J. Lu
2015-05-19 21:28                                         ` Rich Felker
2015-05-20  0:52                                           ` H.J. Lu
2015-05-20  1:09                                             ` Rich Felker
2015-05-22 19:32                                               ` Richard Henderson
2015-05-19 19:48                               ` Rich Felker
2015-05-19 20:16                                 ` Richard Henderson
2015-05-20 12:13                               ` Michael Matz
2015-05-20 12:40                                 ` H.J. Lu
2015-05-20 14:17                                 ` Rich Felker
2015-05-20 14:33                                   ` Michael Matz
2015-05-18 18:25         ` Alexander Monakov
2015-05-18 19:03           ` Jan Hubicka
2015-05-04 16:38 ` [PATCH] Expand PIC calls without PLT with -fno-plt Alexander Monakov
2015-05-04 17:34   ` Jeff Law
2015-05-04 17:40     ` Jakub Jelinek
2015-05-04 17:42       ` Jeff Law
2015-05-06  3:08         ` Rich Felker
2015-05-10 17:07           ` Jan Hubicka
2015-05-06 15:25         ` Alexander Monakov
2015-05-06 15:46           ` Jakub Jelinek
2015-05-06 15:55             ` Jeff Law
2015-05-06 16:44             ` Alexander Monakov
2015-05-06 17:35               ` Rich Felker
2015-05-06 18:26                 ` H.J. Lu
2015-05-06 18:37                   ` Rich Felker
2015-05-06 18:45                     ` H.J. Lu
2015-05-06 19:01                       ` Rich Felker
2015-05-06 19:05                         ` H.J. Lu
2015-05-06 19:18                           ` Rich Felker
2015-05-06 19:24                             ` H.J. Lu
2015-05-11 11:48                             ` Michael Matz
2015-05-11 14:20                               ` Rich Felker
2015-05-07 18:22           ` Jeff Law
2015-05-07 19:13             ` H.J. Lu
2015-05-10 16:59   ` Jan Hubicka
2015-05-11 20:36     ` Jeff Law
2015-05-11 20:55       ` H.J. Lu
2015-05-11 22:13         ` Jan Hubicka
2015-06-22 15:52   ` Jiong Wang
2015-06-22 18:18     ` Alexander Monakov
2015-06-23  8:41       ` Ramana Radhakrishnan
2015-06-23 10:43         ` Alexander Monakov
2015-06-23 13:28         ` Jeff Law
2015-07-16 10:37           ` [AArch64] Tighten direct call pattern to repair -fno-plt Jiong Wang
2015-07-16 10:47             ` Alexander Monakov
2015-07-16 10:48               ` Jiong Wang
2015-07-21 12:52                 ` [AArch64][sibcall]Tighten " Jiong Wang
2015-08-04  9:50                   ` James Greenhalgh
2015-08-06 16:18                     ` [COMMITTED][AArch64][sibcall]Tighten " Jiong Wang
2015-08-07  8:22                       ` James Greenhalgh
2015-08-07 13:28                         ` Jiong Wang
2015-08-04  9:50             ` [AArch64] Tighten " James Greenhalgh
2015-08-06 16:16               ` [COMMITTED][AArch64] " Jiong Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150513200225.GA20903@kam.mff.cuni.cz \
    --to=hubicka@ucw.cz \
    --cc=amonakov@ispras.ru \
    --cc=dalias@libc.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.com \
    --cc=ubizjak@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).