re PR middle-end/19858 (ICE on simple SSE code)
authorJakub Jelinek <jakub@redhat.com>
Fri, 11 Feb 2005 21:08:44 +0000 (22:08 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 11 Feb 2005 21:08:44 +0000 (22:08 +0100)
PR middle-end/19858
* fold-const.c (make_bit_field_ref): If bitpos == 0 and bitsize
is number of inner's bits, avoid creating a BIT_FIELD_REF.

* gcc.c-torture/compile/20050210-1.c: New test.

From-SVN: r94892

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/20050210-1.c [new file with mode: 0644]

index b88ef126485f664dce1a001112b88cd990acf2c1..a8535170c44e84902a332d17d190c182031392d2 100644 (file)
@@ -1,5 +1,9 @@
 2005-02-11  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/19858
+       * fold-const.c (make_bit_field_ref): If bitpos == 0 and bitsize
+       is number of inner's bits, avoid creating a BIT_FIELD_REF.
+
        * config/rs6000/sysv4.h (ENDFILE_LINUX_SPEC): Use crtendS.o instead of
        crtend.o if -pie.  Use %{x:a;:b} spec syntax.
 
index de54258c2a476c10f656dc0919c421d3dfcc823a..0d732730426a4c22d5acce94ffea0fb6ae0b7f9a 100644 (file)
@@ -3076,8 +3076,20 @@ static tree
 make_bit_field_ref (tree inner, tree type, int bitsize, int bitpos,
                    int unsignedp)
 {
-  tree result = build3 (BIT_FIELD_REF, type, inner,
-                       size_int (bitsize), bitsize_int (bitpos));
+  tree result;
+
+  if (bitpos == 0)
+    {
+      tree size = TYPE_SIZE (TREE_TYPE (inner));
+      if ((INTEGRAL_TYPE_P (TREE_TYPE (inner))
+          || POINTER_TYPE_P (TREE_TYPE (inner)))
+         && host_integerp (size, 0) 
+         && tree_low_cst (size, 0) == bitsize)
+       return fold_convert (type, inner);
+    }
+
+  result = build3 (BIT_FIELD_REF, type, inner,
+                  size_int (bitsize), bitsize_int (bitpos));
 
   BIT_FIELD_REF_UNSIGNED (result) = unsignedp;
 
index 1064f44346ecb835cf09653729f953d1a00dfc7e..97a1b12b4507cf8d90228d28209ce62ebb40b921 100644 (file)
@@ -1,3 +1,8 @@
+2005-02-11  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/19858
+       * gcc.c-torture/compile/20050210-1.c: New test.
+
 2005-02-11  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/19755
diff --git a/gcc/testsuite/gcc.c-torture/compile/20050210-1.c b/gcc/testsuite/gcc.c-torture/compile/20050210-1.c
new file mode 100644 (file)
index 0000000..c9e3326
--- /dev/null
@@ -0,0 +1,8 @@
+/* PR middle-end/19858 */
+
+typedef __SIZE_TYPE__ size_t;
+union U { int c; } foo;
+int bar (void)
+{
+  return !(((size_t) &foo & 3) == 0 && !((size_t) &foo & 1));
+}