2009-05-26 Richard Guenther <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 26 May 2009 11:38:03 +0000 (11:38 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 26 May 2009 11:38:03 +0000 (11:38 +0000)
PR middle-end/40252
* fold-const.c (fold_binary): Use the correct types for building
rotates.

* gcc.c-torture/compile/pr40252.c: New testcase.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@147867 138bc75d-0d04-0410-961f-82ee72b054a4

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

index c8f9c84..d2b0362 100644 (file)
@@ -1,5 +1,11 @@
 2009-05-26  Richard Guenther  <rguenther@suse.de>
 
+       PR middle-end/40252
+       * fold-const.c (fold_binary): Use the correct types for building
+       rotates.
+
+2009-05-26  Richard Guenther  <rguenther@suse.de>
+
        * tree-vect-data-refs.c (vect_create_data_ref_ptr): Remove
        redundant calls to merge_alias_info.
        (bump_vector_ptr): Likewise.
index e322ecb..03f6805 100644 (file)
@@ -10175,8 +10175,12 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
                && TREE_INT_CST_HIGH (tree11) == 0
                && ((TREE_INT_CST_LOW (tree01) + TREE_INT_CST_LOW (tree11))
                    == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (arg0, 0)))))
-             return build2 (LROTATE_EXPR, type, TREE_OPERAND (arg0, 0),
-                            code0 == LSHIFT_EXPR ? tree01 : tree11);
+             return fold_convert (type,
+                                  build2 (LROTATE_EXPR,
+                                          TREE_TYPE (TREE_OPERAND (arg0, 0)),
+                                          TREE_OPERAND (arg0, 0),
+                                          code0 == LSHIFT_EXPR
+                                          ? tree01 : tree11));
            else if (code11 == MINUS_EXPR)
              {
                tree tree110, tree111;
@@ -10190,10 +10194,12 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
                                              (TREE_TYPE (TREE_OPERAND
                                                          (arg0, 0))))
                    && operand_equal_p (tree01, tree111, 0))
-                 return build2 ((code0 == LSHIFT_EXPR
-                                 ? LROTATE_EXPR
-                                 : RROTATE_EXPR),
-                                type, TREE_OPERAND (arg0, 0), tree01);
+                 return fold_convert (type,
+                                      build2 ((code0 == LSHIFT_EXPR
+                                               ? LROTATE_EXPR
+                                               : RROTATE_EXPR),
+                                              TREE_TYPE (TREE_OPERAND (arg0, 0)),
+                                              TREE_OPERAND (arg0, 0), tree01));
              }
            else if (code01 == MINUS_EXPR)
              {
@@ -10208,10 +10214,12 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
                                              (TREE_TYPE (TREE_OPERAND
                                                          (arg0, 0))))
                    && operand_equal_p (tree11, tree011, 0))
-                 return build2 ((code0 != LSHIFT_EXPR
-                                 ? LROTATE_EXPR
-                                 : RROTATE_EXPR),
-                                type, TREE_OPERAND (arg0, 0), tree11);
+                 return fold_convert (type,
+                                      build2 ((code0 != LSHIFT_EXPR
+                                               ? LROTATE_EXPR
+                                               : RROTATE_EXPR),
+                                              TREE_TYPE (TREE_OPERAND (arg0, 0)),
+                                              TREE_OPERAND (arg0, 0), tree11));
              }
          }
       }
index dd806ec..7e01ad2 100644 (file)
@@ -1,3 +1,8 @@
+2009-05-26  Richard Guenther  <rguenther@suse.de>
+
+       PR middle-end/40252
+       * gcc.c-torture/compile/pr40252.c: New testcase.
+
 2009-05-26  Dodji Seketeli  <dodji@redhat.com>
 
        PR c++/40007
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr40252.c b/gcc/testsuite/gcc.c-torture/compile/pr40252.c
new file mode 100644 (file)
index 0000000..f58e799
--- /dev/null
@@ -0,0 +1,6 @@
+typedef unsigned int uint32_t;
+static void IP(uint32_t v[2])
+{
+    v[0] = ((v[0] << 1) | ((v[0] >> 31) & 1L)) & 0xffffffffL;
+}
+