This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix PR28935, infinite loop folding due to fold_stmt deficiency
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 2 Sep 2006 22:59:44 +0200 (CEST)
- Subject: [PATCH] Fix PR28935, infinite loop folding due to fold_stmt deficiency
We end up calling fold on 0 != 0 ? 1 : 0 from VRP through the propagator
engine. fold_stmt fails to recursively fold 0 != 0, so the unfolded
expression is passed to fold which is a bug as fold expects subexpressions
that are properly folded.
Fixed by teaching fold_stmt_r how to fold the condition of a COND_EXPR.
Bootstrapped and tested on x86_64-unknown-linux-gnu.
Ok for mainline?
Thanks,
Richard.
:ADDPATCH middle-end:
2006-09-02 Richard Guenther <rguenther@suse.de>
PR middle-end/28935
* tree-ssa-ccp.c (fold_stmt_r): Make sure to fold the condition
of a COND_EXPR.
* gcc.dg/pr28935.c: New testcase.
Index: tree-ssa-ccp.c
===================================================================
*** tree-ssa-ccp.c (revision 116660)
--- tree-ssa-ccp.c (working copy)
*************** fold_stmt_r (tree *expr_p, int *walk_sub
*** 2043,2048 ****
--- 2043,2060 ----
t = maybe_fold_tmr (expr);
break;
+ case COND_EXPR:
+ if (COMPARISON_CLASS_P (TREE_OPERAND (expr, 0)))
+ {
+ tree op0 = TREE_OPERAND (expr, 0);
+ tree tem = fold_binary (TREE_CODE (op0), TREE_TYPE (op0),
+ TREE_OPERAND (op0, 0), TREE_OPERAND (op0, 1));
+ if (tem && is_gimple_condexpr (tem))
+ TREE_OPERAND (expr, 0) = tem;
+ t = expr;
+ break;
+ }
+
default:
return NULL_TREE;
}
Index: testsuite/gcc.dg/pr28935.c
===================================================================
*** testsuite/gcc.dg/pr28935.c (revision 0)
--- testsuite/gcc.dg/pr28935.c (revision 0)
***************
*** 0 ****
--- 1,15 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O3 -ftree-vectorize" } */
+
+ int col[8];
+ int extend_options(int w, int h, int *map, int x, int y, int index)
+ {
+ int dx, dy;
+ for (dx = -1; dx <= +1; dx++)
+ {
+ int index = (dy < 0 ? 6-dx : dy > 0 ? 2+dx : 2*(1+dx));
+ if (x+dx >= 0 && x+dx < w && y+dy >= 0 && y+dy < h)
+ col[index] = map[(y+dy)*w+(x+dx)];
+ col[index] = -1;
+ }
+ }