This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR44545
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 16 Nov 2010 14:37:45 +0100 (CET)
- Subject: [PATCH] Fix PR44545
This fixes PR44545, we shouldn't re-associate possibly trapping
operations. On trunk the issue has gone latent with disabling
re-association for signed types completely, I'm still going to
apply the patch there though.
Bootstrapped and tested on x86_64-unknown-linux-gnu on the branch,
trunk still testing.
Richard.
2010-11-16 Richard Guenther <rguenther@suse.de>
PR tree-optimization/44545
* tree-ssa-reassoc.c (linearize_expr_tree): Possibly throwing
statements are not reassociatable.
(reassociate_bb): Likewise.
* gcc.dg/pr44545.c: New testcase.
Index: gcc/tree-ssa-reassoc.c
===================================================================
*** gcc/tree-ssa-reassoc.c (revision 166793)
--- gcc/tree-ssa-reassoc.c (working copy)
*************** linearize_expr_tree (VEC(operand_entry_t
*** 1620,1632 ****
if (TREE_CODE (binlhs) == SSA_NAME)
{
binlhsdef = SSA_NAME_DEF_STMT (binlhs);
! binlhsisreassoc = is_reassociable_op (binlhsdef, rhscode, loop);
}
if (TREE_CODE (binrhs) == SSA_NAME)
{
binrhsdef = SSA_NAME_DEF_STMT (binrhs);
! binrhsisreassoc = is_reassociable_op (binrhsdef, rhscode, loop);
}
/* If the LHS is not reassociable, but the RHS is, we need to swap
--- 1620,1634 ----
if (TREE_CODE (binlhs) == SSA_NAME)
{
binlhsdef = SSA_NAME_DEF_STMT (binlhs);
! binlhsisreassoc = (is_reassociable_op (binlhsdef, rhscode, loop)
! && !stmt_could_throw_p (binlhsdef));
}
if (TREE_CODE (binrhs) == SSA_NAME)
{
binrhsdef = SSA_NAME_DEF_STMT (binrhs);
! binrhsisreassoc = (is_reassociable_op (binrhsdef, rhscode, loop)
! && !stmt_could_throw_p (binrhsdef));
}
/* If the LHS is not reassociable, but the RHS is, we need to swap
*************** reassociate_bb (basic_block bb)
*** 1815,1821 ****
{
gimple stmt = gsi_stmt (gsi);
! if (is_gimple_assign (stmt))
{
tree lhs, rhs1, rhs2;
enum tree_code rhs_code = gimple_assign_rhs_code (stmt);
--- 1817,1824 ----
{
gimple stmt = gsi_stmt (gsi);
! if (is_gimple_assign (stmt)
! && !stmt_could_throw_p (stmt))
{
tree lhs, rhs1, rhs2;
enum tree_code rhs_code = gimple_assign_rhs_code (stmt);
Index: gcc/testsuite/gcc.dg/pr44545.c
===================================================================
*** gcc/testsuite/gcc.dg/pr44545.c (revision 0)
--- gcc/testsuite/gcc.dg/pr44545.c (revision 0)
***************
*** 0 ****
--- 1,13 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O2 -fnon-call-exceptions -ftrapv -fexceptions" } */
+ int
+ DrawChunk(int *tabSize, int x)
+ {
+ const int numEnds = 10;
+ int ends[numEnds + 2];
+ if (*tabSize > 0) {
+ x -= 5;
+ x = (x + *tabSize) / *tabSize;
+ }
+ }
+