Consider: extern const unsigned long base; static inline void wreg(unsigned char val, unsigned long addr) { *((volatile unsigned char *) (base + addr)) = val; } void wreg_twice(void) { wreg(0, 42); wreg(0, 42); } ---- CUT --- At -O2 the second store to the volatile char is removed by the strlen pass.
I am going to fix this. Note this is causing the mips linux kernel to become unstable.
Created attachment 28134 [details] Patch which fixes the problem Here is the fix.
I've tested your proposed fix with the kernel configuration that I extracted the test case from and I'm happy to report that the patch is working for me.
Updated patch: http://gcc.gnu.org/ml/gcc-patches/2012-09/msg00350.html
Author: pinskia Date: Thu Sep 6 08:08:09 2012 New Revision: 191014 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=191014 Log: 2012-09-06 Andrew Pinski <apinski@cavium.com> PR tree-opt/54494 * tree-inline.c (remap_gimple_op_r): Copy TREE_SIDE_EFFECTS also. 2012-09-06 Andrew Pinski <apinski@cavium.com> PR tree-opt/54494 * gcc.dg/tree-ssa/strlen-1.c: New testcase. Added: trunk/gcc/testsuite/gcc.dg/tree-ssa/strlen-1.c Modified: trunk/gcc/ChangeLog trunk/gcc/testsuite/ChangeLog trunk/gcc/tree-inline.c
Fixed on the trunk so far.
Author: pinskia Date: Thu Sep 6 13:51:37 2012 New Revision: 191025 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=191025 Log: 2012-09-06 Andrew Pinski <apinski@cavium.com> PR tree-opt/54494 * tree-inline.c (remap_gimple_op_r): Copy TREE_SIDE_EFFECTS also. 2012-09-06 Andrew Pinski <apinski@cavium.com> PR tree-opt/54494 * gcc.dg/tree-ssa/strlen-1.c: New testcase. Added: branches/gcc-4_7-branch/gcc/testsuite/gcc.dg/tree-ssa/strlen-1.c - copied unchanged from r191014, trunk/gcc/testsuite/gcc.dg/tree-ssa/strlen-1.c Modified: branches/gcc-4_7-branch/ (props changed) branches/gcc-4_7-branch/gcc/ChangeLog branches/gcc-4_7-branch/gcc/testsuite/ChangeLog branches/gcc-4_7-branch/gcc/tree-inline.c Propchange: branches/gcc-4_7-branch/ ('svn:mergeinfo' modified)
Fixed.