Bug 344382

Summary: Memcheck has high false error rates on MSVC2013 compiled, optimised, code
Product: valgrind Reporter: Julian Seward <jseward>
Component: memcheckAssignee: Julian Seward <jseward>
Status: REPORTED ---    
Severity: normal CC: austinenglish, cpigat242, mitchwharper
Priority: NOR    
Version: 3.10 SVN   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Attachments: WIP patch, believed to be correct

Description Julian Seward 2015-02-20 12:38:42 UTC
MSVC  2013 and possibly earlier generate optimised code for bitfield assignments
which confuses Memcheck.  This is at -O1 and -O2.  Doesn't happen at -Od.

The basic problem is:
to create a new word W, which consists of bits from A where a
mask M has a 0 bit and bits of B where M has a 1 bit, MSVC generates

   A ^ ((A ^ B) & M)

whereas gcc generates

  (A ^ ~M) | (B & M)

Memcheck has no problem with gcc's code, but MSVC's code causes a lot
of complaining.  This is because Memcheck doesn't have a way to know that
xoring an undefined value with itself produces a defined zero, since that
requires tracking the actual identity of the value, which Memcheck can't do.

Proposal is to transform the MSVC version into the GCC version in the
IR optimiser (ir_opt.c).  This seems to be pretty effective in initial trials.


Reproducible: Always
Comment 1 Julian Seward 2015-02-23 00:02:29 UTC
Created attachment 91228 [details]
WIP patch, believed to be correct

Reduces false positive rate for me by about 2/3 on MSVC optimised code.

* CSE cleanups
* enable CSEing on loads
* the core XOR-AND-XOR transformation
Comment 2 Julian Seward 2015-02-27 13:34:49 UTC
(In reply to Julian Seward from comment #1)
> WIP patch, believed to be correct

Committed, r3097, but disabled.  To enable, change if (0) to if (1) at
line 6651.