This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, i386]: Fix PR target/32389


Hello!

The problem here is invalid stack slot sharing through assign_i386_stack_local. When first function (__builtin_ia32_stmxcsr) requested its SImode slot in SLOT_TEMP (during expand, before vregs pass), it got the slot, referenced with virtual-stack-regs. assing_i386_stack_local saved this RTX into its ix86_stack_local array.

The second request for SImode SLOT_TEMP come during split1 pass, and was requested by the splitter for *fix_trunc<mode>_i386_1. The returned RTX from i386_stack_local, was RTX for the slot that was saved before vregs pass, still referencing stack slot through virtual-stack-regs, and thus invalid after vregs pass.

The fix is to introduce SLOT_VIRTUAL stack slot, that is valid only before vregs pass (and is invalid after this pass). All users of i386_stack_local were reviewed due to this new constraint, and few invalid uses were fixed.

Attached patch was bootstrapped and regression tested on x86_64-pc-linux-gnu. Patch is committed to SVN.

2007-06-18 Uros Bizjak <ubizjak@gmail.com>

       PR target/32389
       * config/i386/i386.h (enum ix86_stack_slot): Add SLOT_VIRTUAL.
       * config/i386/i386.c (assign_386_stack_local): Assert that
       SLOT_VIRTUAL is valid only before virtual regs are instantiated.
       (ix86_expand_builtin) [IX86_BUILTIN_LDMXCSR, IX86_BUILTIN_STMXCSR]:
       Use SLOT_VIRTUAL stack slot instead of SLOT_TEMP.
       * config/i386/i386.md (truncdfsf2, truncxf<mode>2): Ditto.

testsuite/ChangeLog:

2007-06-18 Uros Bizjak <ubizjak@gmail.com>

       PR target/32389
       * gcc.target/i386/pr32389.c New test.

Uros.
Index: testsuite/gcc.target/i386/pr32389.c
===================================================================
--- testsuite/gcc.target/i386/pr32389.c	(revision 0)
+++ testsuite/gcc.target/i386/pr32389.c	(revision 0)
@@ -0,0 +1,10 @@
+/* Testcase by Mike Frysinger <vapier@gentoo.org>  */
+
+/* { dg-do compile { target { { i?86-*-* x86_64-*-* } && ilp32 } } } */
+/* { dg-options "-msse" } */
+
+double f1();
+int f2() {
+  __builtin_ia32_stmxcsr();
+  return f1();
+}
Index: config/i386/i386.h
===================================================================
--- config/i386/i386.h	(revision 125823)
+++ config/i386/i386.h	(working copy)
@@ -2334,7 +2334,8 @@ enum ix86_entity
 
 enum ix86_stack_slot
 {
-  SLOT_TEMP = 0,
+  SLOT_VIRTUAL = 0,
+  SLOT_TEMP,
   SLOT_CW_STORED,
   SLOT_CW_TRUNC,
   SLOT_CW_FLOOR,
Index: config/i386/i386.md
===================================================================
--- config/i386/i386.md	(revision 125823)
+++ config/i386/i386.md	(working copy)
@@ -3855,7 +3855,7 @@
     ;
   else
     {
-      rtx temp = assign_386_stack_local (SFmode, SLOT_TEMP);
+      rtx temp = assign_386_stack_local (SFmode, SLOT_VIRTUAL);
       emit_insn (gen_truncdfsf2_with_temp (operands[0], operands[1], temp));
       DONE;
     }
@@ -3994,7 +3994,7 @@
       DONE;
     }
   else
-    operands[2] = assign_386_stack_local (<MODE>mode, SLOT_TEMP);
+    operands[2] = assign_386_stack_local (<MODE>mode, SLOT_VIRTUAL);
 })
 
 (define_insn "*truncxfsf2_mixed"
Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c	(revision 125823)
+++ config/i386/i386.c	(working copy)
@@ -15614,6 +15614,9 @@ assign_386_stack_local (enum machine_mod
 
   gcc_assert (n < MAX_386_STACK_LOCALS);
 
+  /* Virtual slot is valid only before vregs are instantiated.  */
+  gcc_assert ((n == SLOT_VIRTUAL) == !virtuals_instantiated);
+
   for (s = ix86_stack_locals; s; s = s->next)
     if (s->mode == mode && s->n == n)
       return copy_rtx (s->rtl);
@@ -19209,13 +19212,13 @@ ix86_expand_builtin (tree exp, rtx targe
 
     case IX86_BUILTIN_LDMXCSR:
       op0 = expand_normal (CALL_EXPR_ARG (exp, 0));
-      target = assign_386_stack_local (SImode, SLOT_TEMP);
+      target = assign_386_stack_local (SImode, SLOT_VIRTUAL);
       emit_move_insn (target, op0);
       emit_insn (gen_sse_ldmxcsr (target));
       return 0;
 
     case IX86_BUILTIN_STMXCSR:
-      target = assign_386_stack_local (SImode, SLOT_TEMP);
+      target = assign_386_stack_local (SImode, SLOT_VIRTUAL);
       emit_insn (gen_sse_stmxcsr (target));
       return copy_to_mode_reg (SImode, target);
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]