public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Fix ICE in ia64 speculation support
@ 2007-09-13 17:42 Maxim Kuvyrkov
  2007-09-20 20:47 ` Vladimir Makarov
  0 siblings, 1 reply; 13+ messages in thread
From: Maxim Kuvyrkov @ 2007-09-13 17:42 UTC (permalink / raw)
  To: Vladimir Makarov; +Cc: Andrey Belevantsev, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 917 bytes --]

Hi,

This patch fixes minor bug in ia64 speculation support.

The issue is that may_trap_p () can return different results given 
normal instruction and its speculative version.  E.g., this occurs for 
(set (reg:DF) (mem:DF)) and (set (reg:DF) (unspec:DF [(mem:DF)] 
DATA_SPEC)).  The latter is a speculative variant of the former and 
may_trap_p () always returns 'true' for the speculative version because 
unspec:DF is considered a random floating point operation that might trap.

This causes an assert, that checks that a speculative insn can stay 
speculative, fail.  The fix is to use original pattern when calling 
may_trap_p ().

The bug was reported by Andrey and implicates itself only with '-O2 
-funroll-loops' (the options tested by default do not include this 
combination).  The testcase is a copy of 
gcc.c-torture/execute/20040709-1.c but with forced -funroll-loops.

OK for trunk?


Thanks,

Maxim

[-- Attachment #2: bonzo.ChangeLog --]
[-- Type: text/plain, Size: 290 bytes --]

2007-09-13  Maxim Kuvyrkov  <maxim@codesourcery.com>

	* haifa-sched.c (sched_insn_is_legitimate_for_speculation): Use
	original pattern of changed instructions to stabilize analysis.

2007-09-13  Maxim Kuvyrkov  <maxim@codesourcery.com>

	* gcc.c-torture/compile/20040709-2.c: New test.
	

[-- Attachment #3: bonzo.patch --]
[-- Type: text/plain, Size: 5339 bytes --]

Index: haifa-sched.c
===================================================================
--- haifa-sched.c	(revision 181504)
+++ haifa-sched.c	(working copy)
@@ -4034,9 +4034,21 @@ sched_insn_is_legitimate_for_speculation
   if (side_effects_p (PATTERN (insn)))
     return false;
 
-  if ((ds & BE_IN_SPEC)
-      && may_trap_p (PATTERN (insn)))
-    return false;
+  if (ds & BE_IN_SPEC)
+    {
+      rtx pat;
+
+      if (ORIG_PAT (insn) != NULL_RTX)
+	/* Use original pattern of instruction as current [speculative]
+	   pattern might be identified as trap risky even when it is,
+	   in fact, not.  */
+	pat = ORIG_PAT (insn);
+      else
+	pat = PATTERN (insn);
+
+      if (may_trap_p (pat))
+	return false;
+    }
 
   return true;
 }
Index: testsuite/gcc.c-torture/compile/20040709-2.c
===================================================================
--- testsuite/gcc.c-torture/compile/20040709-2.c	(revision 0)
+++ testsuite/gcc.c-torture/compile/20040709-2.c	(revision 0)
@@ -0,0 +1,149 @@
+/* { dg-options "-funroll-loops" { target ia64-*-* } } */
+
+/* Check for ia64 data speculation failure with '-O2 -funroll-loops'.  */
+
+extern void abort (void);
+extern void exit (int);
+
+unsigned int
+myrnd (void)
+{
+  static unsigned int s = 1388815473;
+  s *= 1103515245;
+  s += 12345;
+  return (s / 65536) % 2048;
+}
+
+#define T(S)					\
+struct S s##S;					\
+struct S retme##S (struct S x)			\
+{						\
+  return x;					\
+}						\
+						\
+unsigned int fn1##S (unsigned int x)		\
+{						\
+  struct S y = s##S;				\
+  y.k += x;					\
+  y = retme##S (y);				\
+  return y.k;					\
+}						\
+						\
+unsigned int fn2##S (unsigned int x)		\
+{						\
+  struct S y = s##S;				\
+  y.k += x;					\
+  y.k %= 15;					\
+  return y.k;					\
+}						\
+						\
+unsigned int retit##S (void)			\
+{						\
+  return s##S.k;				\
+}						\
+						\
+unsigned int fn3##S (unsigned int x)		\
+{						\
+  s##S.k += x;					\
+  return retit##S ();				\
+}						\
+						\
+void test##S (void)				\
+{						\
+  int i;					\
+  unsigned int mask, v, a, r;			\
+  struct S x;					\
+  char *p = (char *) &s##S;			\
+  for (i = 0; i < sizeof (s##S); ++i)		\
+    *p++ = myrnd ();				\
+  if (__builtin_classify_type (s##S.l) == 8)	\
+    s##S.l = 5.25;				\
+  s##S.k = -1;					\
+  mask = s##S.k;				\
+  v = myrnd ();					\
+  a = myrnd ();					\
+  s##S.k = v;					\
+  x = s##S;					\
+  r = fn1##S (a);				\
+  if (x.i != s##S.i || x.j != s##S.j		\
+      || x.k != s##S.k || x.l != s##S.l		\
+      || ((v + a) & mask) != r)			\
+    abort ();					\
+  v = myrnd ();					\
+  a = myrnd ();					\
+  s##S.k = v;					\
+  x = s##S;					\
+  r = fn2##S (a);				\
+  if (x.i != s##S.i || x.j != s##S.j		\
+      || x.k != s##S.k || x.l != s##S.l		\
+      || ((((v + a) & mask) % 15) & mask) != r)	\
+    abort ();					\
+  v = myrnd ();					\
+  a = myrnd ();					\
+  s##S.k = v;					\
+  x = s##S;					\
+  r = fn3##S (a);				\
+  if (x.i != s##S.i || x.j != s##S.j		\
+      || s##S.k != r || x.l != s##S.l		\
+      || ((v + a) & mask) != r)			\
+    abort ();					\
+}
+
+struct A { unsigned int i : 6, l : 1, j : 10, k : 15; }; T(A)
+struct B { unsigned int i : 6, j : 11, k : 15; unsigned int l; }; T(B)
+struct C { unsigned int l; unsigned int i : 6, j : 11, k : 15; }; T(C)
+struct D { unsigned long long l : 6, i : 6, j : 23, k : 29; }; T(D)
+struct E { unsigned long long l, i : 12, j : 23, k : 29; }; T(E)
+struct F { unsigned long long i : 12, j : 23, k : 29, l; }; T(F)
+struct G { unsigned int i : 12, j : 13, k : 7; unsigned long long l; }; T(G)
+struct H { unsigned int i : 12, j : 11, k : 9; unsigned long long l; }; T(H)
+struct I { unsigned short i : 1, j : 6, k : 9; unsigned long long l; }; T(I)
+struct J { unsigned short i : 1, j : 8, k : 7; unsigned short l; }; T(J)
+struct K { unsigned int k : 6, l : 1, j : 10, i : 15; }; T(K)
+struct L { unsigned int k : 6, j : 11, i : 15; unsigned int l; }; T(L)
+struct M { unsigned int l; unsigned int k : 6, j : 11, i : 15; }; T(M)
+struct N { unsigned long long l : 6, k : 6, j : 23, i : 29; }; T(N)
+struct O { unsigned long long l, k : 12, j : 23, i : 29; }; T(O)
+struct P { unsigned long long k : 12, j : 23, i : 29, l; }; T(P)
+struct Q { unsigned int k : 12, j : 13, i : 7; unsigned long long l; }; T(Q)
+struct R { unsigned int k : 12, j : 11, i : 9; unsigned long long l; }; T(R)
+struct S { unsigned short k : 1, j : 6, i : 9; unsigned long long l; }; T(S)
+struct T { unsigned short k : 1, j : 8, i : 7; unsigned short l; }; T(T)
+struct U { unsigned short j : 6, k : 1, i : 9; unsigned long long l; }; T(U)
+struct V { unsigned short j : 8, k : 1, i : 7; unsigned short l; }; T(V)
+struct W { long double l; unsigned int k : 12, j : 13, i : 7; }; T(W)
+struct X { unsigned int k : 12, j : 13, i : 7; long double l; }; T(X)
+struct Y { unsigned int k : 12, j : 11, i : 9; long double l; }; T(Y)
+struct Z { long double l; unsigned int j : 13, i : 7, k : 12; }; T(Z)
+
+int
+main (void)
+{
+  testA ();
+  testB ();
+  testC ();
+  testD ();
+  testE ();
+  testF ();
+  testG ();
+  testH ();
+  testI ();
+  testJ ();
+  testK ();
+  testL ();
+  testM ();
+  testN ();
+  testO ();
+  testP ();
+  testQ ();
+  testR ();
+  testS ();
+  testT ();
+  testU ();
+  testV ();
+  testW ();
+  testX ();
+  testY ();
+  testZ ();
+  exit (0);
+}

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2007-10-16  9:15 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-13 17:42 [PATCH] Fix ICE in ia64 speculation support Maxim Kuvyrkov
2007-09-20 20:47 ` Vladimir Makarov
2007-09-20 21:51   ` Vladimir Makarov
2007-09-21  9:18     ` Maxim Kuvyrkov
2007-09-21  9:38       ` Paolo Bonzini
2007-09-21  9:53         ` Maxim Kuvyrkov
2007-09-21 10:43           ` Paolo Bonzini
2007-10-14 18:04             ` Maxim Kuvyrkov
2007-10-15  8:06               ` Paolo Bonzini
2007-10-15  8:17               ` Eric Botcazou
2007-10-15 10:52                 ` Maxim Kuvyrkov
2007-10-15 21:57                   ` Jim Wilson
2007-10-16  9:51                     ` Maxim Kuvyrkov

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