This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR40252, wrong types with folding rotates
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 26 May 2009 13:36:23 +0200 (CEST)
- Subject: [PATCH] Fix PR40252, wrong types with folding rotates
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
Richard.
2009-05-26 Richard Guenther <rguenther@suse.de>
PR middle-end/40252
* fold-const.c (fold_binary): Use the correct types for building
rotates.
* gcc.c-torture/compile/pr40252.c: New testcase.
Index: gcc/fold-const.c
===================================================================
*** gcc/fold-const.c (revision 147862)
--- gcc/fold-const.c (working copy)
*************** fold_binary (enum tree_code code, tree t
*** 10175,10182 ****
&& 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);
else if (code11 == MINUS_EXPR)
{
tree tree110, tree111;
--- 10175,10186 ----
&& 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 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;
*************** fold_binary (enum tree_code code, tree t
*** 10190,10199 ****
(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);
}
else if (code01 == MINUS_EXPR)
{
--- 10194,10205 ----
(TREE_TYPE (TREE_OPERAND
(arg0, 0))))
&& operand_equal_p (tree01, tree111, 0))
! 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)
{
*************** fold_binary (enum tree_code code, tree t
*** 10208,10217 ****
(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);
}
}
}
--- 10214,10225 ----
(TREE_TYPE (TREE_OPERAND
(arg0, 0))))
&& operand_equal_p (tree11, tree011, 0))
! return fold_convert (type,
! build2 ((code0 != LSHIFT_EXPR
! ? LROTATE_EXPR
! : RROTATE_EXPR),
! TREE_TYPE (TREE_OPERAND (arg0, 0)),
! TREE_OPERAND (arg0, 0), tree11));
}
}
}
Index: gcc/testsuite/gcc.c-torture/compile/pr40252.c
===================================================================
*** gcc/testsuite/gcc.c-torture/compile/pr40252.c (revision 0)
--- gcc/testsuite/gcc.c-torture/compile/pr40252.c (revision 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;
+ }
+