[PATCH] Fix ICE with -mforce-indirect-call (PR target/84564)

Jakub Jelinek jakub@redhat.com
Mon Feb 26 20:49:00 GMT 2018


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



More information about the Gcc-patches mailing list