]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR middle-end/32912 (ICE with vector code)
authorJakub Jelinek <jakub@redhat.com>
Fri, 24 Aug 2007 17:23:43 +0000 (19:23 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 24 Aug 2007 17:23:43 +0000 (19:23 +0200)
PR middle-end/32912
* fold-const.c (fold_binary): Only optimize X | ~X and X ^ ~X for
integral types.

* gcc.dg/pr32912-1.c: New test.
* gcc.dg/pr32912-2.c: New test.

From-SVN: r127783

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr32912-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr32912-2.c [new file with mode: 0644]

index a6caeb639e7691edbfcb0cd2ed1fd426a9fe5c6f..32394245cdaced07d8617794301a0f42687dfed4 100644 (file)
@@ -1,3 +1,9 @@
+2007-08-24  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/32912
+       * fold-const.c (fold_binary): Only optimize X | ~X and X ^ ~X for
+       integral types.
+
 2007-08-22  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/33142
index 417231aeb9d60b37a71994d7cc7c69d33c852d15..ec9ab9486e0bd1d82791dc1ed2f06f9a193cd243 100644 (file)
@@ -8075,6 +8075,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
 
       /* ~X | X is -1.  */
       if (TREE_CODE (arg0) == BIT_NOT_EXPR
+         && INTEGRAL_TYPE_P (TREE_TYPE (arg1))
          && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0))
        {
          t1 = build_int_cst (type, -1);
@@ -8084,6 +8085,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
 
       /* X | ~X is -1.  */
       if (TREE_CODE (arg1) == BIT_NOT_EXPR
+         && INTEGRAL_TYPE_P (TREE_TYPE (arg0))
          && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
        {
          t1 = build_int_cst (type, -1);
@@ -8171,6 +8173,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
 
       /* ~X ^ X is -1.  */
       if (TREE_CODE (arg0) == BIT_NOT_EXPR
+         && INTEGRAL_TYPE_P (TREE_TYPE (arg1))
          && operand_equal_p (TREE_OPERAND (arg0, 0), arg1, 0))
        {
          t1 = build_int_cst (type, -1);
@@ -8180,6 +8183,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
 
       /* X ^ ~X is -1.  */
       if (TREE_CODE (arg1) == BIT_NOT_EXPR
+         && INTEGRAL_TYPE_P (TREE_TYPE (arg0))
          && operand_equal_p (arg0, TREE_OPERAND (arg1, 0), 0))
        {
          t1 = build_int_cst (type, -1);
index a9651e69c8b7349e5f2d42d43a40160dccd4728d..a4cbd9728b6a55eae52dc7acfafeaa5c42bec4f0 100644 (file)
@@ -1,5 +1,9 @@
 2007-08-24  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/32912
+       * gcc.dg/pr32912-1.c: New test.
+       * gcc.dg/pr32912-2.c: New test.
+
        PR c++/31941
        * g++.dg/parse/crash37.C: New test.
 
diff --git a/gcc/testsuite/gcc.dg/pr32912-1.c b/gcc/testsuite/gcc.dg/pr32912-1.c
new file mode 100644 (file)
index 0000000..2f9e859
--- /dev/null
@@ -0,0 +1,44 @@
+/* PR middle-end/32912 */
+/* { dg-do run } */
+/* { dg-options "-O2 -w" } */
+
+extern void abort (void);
+
+typedef int __m128i __attribute__ ((__vector_size__ (16)));
+
+__m128i a, b, c, d, e, f;
+
+void
+foo (__m128i x)
+{
+  a = x ^ ~x;
+  b = ~x ^ x;
+  c = x | ~x;
+  d = ~x | x;
+  e = x & ~x;
+  f = ~x & x;
+}
+
+int
+main (void)
+{
+  union { __m128i v; int i[sizeof (__m128i) / sizeof (int)]; } u;
+  int i;
+
+  for (i = 0; i < sizeof (u.i) / sizeof (u.i[0]); i++)
+    u.i[i] = i * 49 - 36;
+  foo (u.v);
+#define check(x, val) \
+  u.v = (x); \
+  for (i = 0; i < sizeof (u.i) / sizeof (u.i[0]); i++) \
+    if (u.i[i] != (val)) \
+      abort ()
+
+  check (a, ~0);
+  check (b, ~0);
+  check (c, ~0);
+  check (d, ~0);
+  check (e, 0);
+  check (f, 0);
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.dg/pr32912-2.c b/gcc/testsuite/gcc.dg/pr32912-2.c
new file mode 100644 (file)
index 0000000..3ea81da
--- /dev/null
@@ -0,0 +1,45 @@
+/* { dg-do run } */
+/* { dg-options "-O2 -w" } */
+
+extern void abort (void);
+
+typedef int __m128i __attribute__ ((__vector_size__ (16)));
+
+__m128i a, b, c, d, e, f;
+
+__m128i
+foo (void)
+{
+  __m128i x = { 0x11111111, 0x22222222, 0x44444444 };
+  return x;
+}
+
+__m128i
+bar (void)
+{
+  __m128i x = { 0x11111111, 0x22222222, 0x44444444 };
+  return ~x;
+}
+
+int
+main (void)
+{
+  union { __m128i v; int i[sizeof (__m128i) / sizeof (int)]; } u, v;
+  int i;
+
+  u.v = foo ();
+  v.v = bar ();
+  for (i = 0; i < sizeof (u.i) / sizeof (u.i[0]); i++)
+    {
+      if (u.i[i] != ~v.i[i])
+       abort ();
+      if (i < 3)
+       {
+         if (u.i[i] != (0x11111111 << i))
+           abort ();
+       }
+      else if (u.i[i])
+       abort ();
+    }
+  return 0;
+}