On Tue, Mar 08, 2016 at 07:11:45PM +0100, Richard Biener wrote: > I believe the safest fix is to re-instantiate the compatibility check by > refactoring operand_equal_p to perform it on the full ref (but not recursions > where it would be redundant and maybe too conservative). > I've noticed this as well when doing the last operand_equal_p surgery, esp. > The incomplete and bogus half-way type checking done at its top.
I've tried to add types_compatible_p check to operand_equal_p for all toplevel expressions, but that affected 25x more operand_equal_p calls during x86_64 and i686-linux bootstrap/regtest than just doing it for *MEM_REF only - details in the PR; after discussions on IRC with Richard and Honza I've committed reversion of the October change, and we'll need to start with operand_equal_p changes early during stage1 next time, rather than at the end of stage1. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2016-03-09 Jakub Jelinek <ja...@redhat.com> PR tree-optimization/70127 * fold-const.c (operand_equal_p): Revert the 2015-10-28 change. * gcc.c-torture/execute/pr70127.c: New test. --- gcc/fold-const.c.jj 2016-03-09 15:06:21.000000000 +0100 +++ gcc/fold-const.c 2016-03-09 18:25:07.429926750 +0100 @@ -3032,6 +3032,9 @@ operand_equal_p (const_tree arg0, const_ TYPE_SIZE (TREE_TYPE (arg1)), flags))) return 0; + /* Verify that access happens in similar types. */ + if (!types_compatible_p (TREE_TYPE (arg0), TREE_TYPE (arg1))) + return 0; /* Verify that accesses are TBAA compatible. */ if (!alias_ptr_types_compatible_p (TREE_TYPE (TREE_OPERAND (arg0, 1)), --- gcc/testsuite/gcc.c-torture/execute/pr70127.c.jj 2016-03-08 12:11:11.890835632 +0100 +++ gcc/testsuite/gcc.c-torture/execute/pr70127.c 2016-03-08 12:10:58.000000000 +0100 @@ -0,0 +1,23 @@ +/* PR tree-optimization/70127 */ + +struct S { int f; signed int g : 2; } a[1], c = {5, 1}, d; +short b; + +__attribute__((noinline, noclone)) void +foo (int x) +{ + if (x != 1) + __builtin_abort (); +} + +int +main () +{ + while (b++ <= 0) + { + struct S e = {1, 1}; + d = e = a[0] = c; + } + foo (a[0].g); + return 0; +} Jakub