Hi! This patch fixes endless recursion, when we have e.g. (eq (and (mem (mem)) (const_int 0)) (const_int 0)) and one of the MEMs is volatile (side_effects_p is true for it). Due to the side effects, (and ... (const_int 0)) is not folded into 0, and these two hunks then attempt to "simplify" it as (eq (and (not (mem (mem))) (const_int 0)) (const_int 0)) and recurse that way until running out of stack. The patch disables it for const0_rtx, because in that case it is never an optimization.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2015-01-21 Jakub Jelinek <ja...@redhat.com> PR debug/64511 * simplify-rtx.c (simplify_relational_operation_1): Don't try to optimize (eq/ne (and (side_effects) (const_int 0)) (const_int 0)) into (eq/ne (and (not (side_effects)) (const_int 0)) (const_int 0)). * gcc.dg/pr64511.c: New test. --- gcc/simplify-rtx.c.jj 2015-01-19 09:31:25.000000000 +0100 +++ gcc/simplify-rtx.c 2015-01-21 11:31:28.210575916 +0100 @@ -4589,7 +4589,8 @@ simplify_relational_operation_1 (enum rt if ((code == EQ || code == NE) && op0code == AND && rtx_equal_p (XEXP (op0, 0), op1) - && !side_effects_p (op1)) + && !side_effects_p (op1) + && op1 != CONST0_RTX (cmp_mode)) { rtx not_y = simplify_gen_unary (NOT, cmp_mode, XEXP (op0, 1), cmp_mode); rtx lhs = simplify_gen_binary (AND, cmp_mode, not_y, XEXP (op0, 0)); @@ -4602,7 +4603,8 @@ simplify_relational_operation_1 (enum rt if ((code == EQ || code == NE) && op0code == AND && rtx_equal_p (XEXP (op0, 1), op1) - && !side_effects_p (op1)) + && !side_effects_p (op1) + && op1 != CONST0_RTX (cmp_mode)) { rtx not_x = simplify_gen_unary (NOT, cmp_mode, XEXP (op0, 0), cmp_mode); rtx lhs = simplify_gen_binary (AND, cmp_mode, not_x, XEXP (op0, 1)); --- gcc/testsuite/gcc.dg/pr64511.c.jj 2015-01-21 11:36:54.527916771 +0100 +++ gcc/testsuite/gcc.dg/pr64511.c 2015-01-21 11:37:14.388572338 +0100 @@ -0,0 +1,23 @@ +/* PR debug/64511 */ +/* { dg-do compile } */ +/* { dg-options "-O3 -g" } */ + +int a, c; +int *volatile b; + +void +foo (int p) +{ + int d; + int *e = &a; + d = ((p == 0) & *e) != 0; + b = e; + for (; c;) + ; +} + +void +bar (void) +{ + foo (1); +} Jakub