Bug 54494

Summary: [4.7 Regression] Missing store to volatile
Product: gcc Reporter: Andrew Pinski <pinskia>
Component: tree-optimizationAssignee: Andrew Pinski <pinskia>
Status: RESOLVED FIXED    
Severity: normal CC: daney, hp, ralf
Priority: P3 Keywords: patch, wrong-code
Version: 4.7.0   
Target Milestone: 4.7.2   
URL: http://gcc.gnu.org/ml/gcc-patches/2012-09/msg00350.html
Host: Target:
Build: Known to work: 4.6.1, 4.8.0
Known to fail: 4.7.0, 4.7.1 Last reconfirmed: 2012-09-05 00:00:00
Attachments: Patch which fixes the problem

Description Andrew Pinski 2012-09-05 17:47:12 UTC
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.
Comment 1 Andrew Pinski 2012-09-05 17:48:42 UTC
I am going to fix this.
Note this is causing the mips linux kernel to become unstable.
Comment 2 Andrew Pinski 2012-09-05 18:23:56 UTC
Created attachment 28134 [details]
Patch which fixes the problem

Here is the fix.
Comment 3 Ralf Baechle 2012-09-05 20:06:47 UTC
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.
Comment 4 Andrew Pinski 2012-09-06 04:12:03 UTC
Updated patch:
http://gcc.gnu.org/ml/gcc-patches/2012-09/msg00350.html
Comment 5 Andrew Pinski 2012-09-06 08:08:21 UTC
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
Comment 6 Andrew Pinski 2012-09-06 08:09:13 UTC
Fixed on the trunk so far.
Comment 7 Andrew Pinski 2012-09-06 13:51:45 UTC
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)
Comment 8 Andrew Pinski 2012-09-06 13:53:57 UTC
Fixed.
Comment 9 Andrew Pinski 2012-09-06 13:53:57 UTC
Fixed.