struct A { int* x[2]; A() { for (int** p=x; p<x+2; ++p) *p = 0; } }; struct B { char c; A a0, a1, a2, a3, *p; B() {} B(const B& b) : c(), a0(b.a0), p(b.p) {} ~B() { delete p; } }; inline void foo(const B& b) { new B(b); } void bar() { foo(B()); foo(B()); } After cfg_cleanup after loop header copying we end up with unfolded &D.2114.a0D.2019.xD.1986[2] > &D.2114.a0D.2019.xD.1986[0] because in fold_binary where we handle this kind of stuff we have if (!offset0 || !offset1 || TREE_TYPE (offset0) == TREE_TYPE (offset1)) { ... and unfortunately the constants 2 and 0 have distinct types: (gdb) call debug_tree(offset0) <integer_cst 0x4026e888 type <integer_type 0x402474ac> constant invariant 8> (gdb) call debug_tree(offset1) <integer_cst 0x4018d180 type <integer_type 0x4019f000 unsigned int> constant invariant 0>
Confirmed, this testcase is from PR 26197.
Note that the reason mentioned was fixed recently, but we still have (in .optimized): <L18>:; p = &D.2217->a2.x[0]; D.2237 = &D.2217->a2.x[2]; if (p < D.2237) goto <L19>; else goto <L21>; ... <L21>:; p = &D.2217->a3.x[0]; D.2243 = &D.2217->a3.x[2]; if (p < D.2243) goto <L22>; else goto <L24>;
And note that before TER we have p_108 = &this_91->a3.x[0]; D.3632_327 = p_108 + 15B; if (p_108 <= D.3632_327) goto <L203>; else goto <L47>; it sucks that we don't tree-combine COND_EXPRs. Testcase: int foo(int p) { int q = p + 5; return q < p; } void bar(int p) { int q = p + 5; if (q < p) link_error (); }
Depends on (and is partly fixed by) PR30965.
The original issue seems to no longer trigger with the testcase, the missed combining is fixed with a patch I have.
Also because in fold_binary where we handle this kind of stuff we have if (!offset0 || !offset1 || TREE_TYPE (offset0) == TREE_TYPE (offset1)) { ... is no longer true, we compare offsets in signed sizetype.
Subject: Bug 26198 Author: rguenth Date: Fri Oct 12 08:42:13 2007 New Revision: 129256 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=129256 Log: 2007-10-12 Richard Guenther <rguenther@suse.de> PR middle-end/26198 * tree-ssa-forwprop.c (can_propagate_from): Do not propagate from a rhs with side-effects or which is a load. (forward_propagate_into_cond): Also try combining both operands. * gcc.dg/tree-ssa/forwprop-3.c: New testcase. * gcc.c-torture/execute/20071011-1.c: Likewise. * gcc.dg/tree-ssa/ssa-pre-9.c: Adjust. Added: trunk/gcc/testsuite/gcc.c-torture/execute/20071011-1.c trunk/gcc/testsuite/gcc.dg/tree-ssa/forwprop-3.c Modified: trunk/gcc/ChangeLog trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-9.c trunk/gcc/tree-ssa-forwprop.c
Fixed.