Another one - this time with the testcase from the other PR. Bootstrapped / tested on x86_64-unknown-linux-gnu, applied.
Richard. 2016-09-29 Richard Biener <rguent...@suse.de> PR tree-optimization/77768 * tree-ssa-pre.c (eliminate_dom_walker::before_dom_children): Handle stores to readonly memory when removing redundant stores. * gcc.dg/torture/pr77768.c: New testcase. Index: gcc/tree-ssa-pre.c =================================================================== --- gcc/tree-ssa-pre.c (revision 240609) +++ gcc/tree-ssa-pre.c (working copy) @@ -4443,9 +4443,11 @@ eliminate_dom_walker::before_dom_childre && operand_equal_p (val, rhs, 0)) { /* We can only remove the later store if the former aliases - at least all accesses the later one does. */ + at least all accesses the later one does or if the store + was to readonly memory storing the same value. */ alias_set_type set = get_alias_set (lhs); - if (vnresult->set == set + if (! vnresult + || vnresult->set == set || alias_set_subset_of (set, vnresult->set)) { if (dump_file && (dump_flags & TDF_DETAILS)) Index: gcc/testsuite/gcc.dg/torture/pr77768.c =================================================================== --- gcc/testsuite/gcc.dg/torture/pr77768.c (revision 0) +++ gcc/testsuite/gcc.dg/torture/pr77768.c (working copy) @@ -0,0 +1,13 @@ +/* { dg-do run } */ + +static const int a; +int b; +int *c, *d; +int main() +{ + c = (int *)&a; + c == d ?: __builtin_exit(0); + for (; b; b++ >= (*d = a)) + ; + return 0; +}