public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix ICE with -mforce-indirect-call (PR target/84564)
@ 2018-02-26 20:49 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2018-02-26 20:49 UTC (permalink / raw)
  To: Uros Bizjak, H.J.Lu; +Cc: gcc-patches

Hi!

While this isn't a regression, it is ICE in newly added feature and
so should be fixed too.  The problem is that with -mforce-indirect-call
even direct calls are emitted as indirect, and if we have in 32-bit
mode a direct call to a regparm(3) function or a direct call to a function
we've optimized using regparm(3) convention internally, we can't really
tail call it, as there aren't any registers left for the address of the
function in the indirect call, eax/ecx/edx are used to pass arguments, esp
has fixed role and the rest needs to be already restored.

The following patch refuses to tail call in that case, similarly how we
reject to tail call an indirect call to a regparm(3) function.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2018-02-26  Jakub Jelinek  <jakub@redhat.com>

	PR target/84564
	* config/i386/i386.c (ix86_function_ok_for_sibcall): Check for
	regparm >= 3 with no arg reg available also for calls with
	flag_force_indirect_call.  Pass decl to ix86_function_regparm.

	* gcc.target/i386/pr84564.c: New test.

--- gcc/config/i386/i386.c.jj	2018-02-22 22:25:57.109993153 +0100
+++ gcc/config/i386/i386.c	2018-02-26 15:14:11.786294313 +0100
@@ -6411,7 +6411,8 @@ ix86_function_ok_for_sibcall (tree decl,
 	 function via GOT slot are indirect.  */
       if (!decl
 	  || (bind_global && flag_pic && !flag_plt)
-	  || (TARGET_DLLIMPORT_DECL_ATTRIBUTES && DECL_DLLIMPORT_P (decl)))
+	  || (TARGET_DLLIMPORT_DECL_ATTRIBUTES && DECL_DLLIMPORT_P (decl))
+	  || flag_force_indirect_call)
 	{
 	  /* Check if regparm >= 3 since arg_reg_available is set to
 	     false if regparm == 0.  If regparm is 1 or 2, there is
@@ -6420,7 +6421,7 @@ ix86_function_ok_for_sibcall (tree decl,
 	     ??? The symbol indirect call doesn't need a call-clobbered
 	     register.  But we don't know if this is a symbol indirect
 	     call or not here.  */
-	  if (ix86_function_regparm (type, NULL) >= 3
+	  if (ix86_function_regparm (type, decl) >= 3
 	      && !cfun->machine->arg_reg_available)
 	    return false;
 	}
--- gcc/testsuite/gcc.target/i386/pr84564.c.jj	2018-02-26 15:10:02.981296789 +0100
+++ gcc/testsuite/gcc.target/i386/pr84564.c	2018-02-26 14:57:38.287304183 +0100
@@ -0,0 +1,21 @@
+/* PR target/84564 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mforce-indirect-call" } */
+
+int a, b, c, d;
+int foo (void);
+
+static int
+bar (int x, int y, int z)
+{
+  while (a)
+    if (foo ())
+      bar (x, y, z);
+  return 0;
+}
+
+int
+baz (void)
+{
+  return bar (b, c, d);
+}

	Jakub

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-02-26 20:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-26 20:49 [PATCH] Fix ICE with -mforce-indirect-call (PR target/84564) Jakub Jelinek

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).