Hi Alexey,
Overall any optimizations that don't introduce new false negatives
would be very useful and benefit all existing users.
There was some research on this, but at this point I don't remember
any concrete references (can't do better than you searching papers for
right keywords).
Things besides better escape analysis that come to mind:
Better duplicate check elimination. Currently the pass only removes
very simple duplicates (within the same basic block with no
intervening calls in between). It may be possible to extend this
analysis inter-basic-block based on pre/post-dominance.
It may also be possible to eliminate duplicates across calls if the
calls don't include any synchronization operations (that's what we
really care about).
Even tricker analysis may tolerate some synchronization operations in
between. Namely, for only acquire/release operations we leave only the
check before/after the operation.
We also discussed combining several checks into one, e.g. instead of 2
close 1-byte checks we do 1 2-byte check. However, for tsan
specifically it's more tricky than asan/msan b/c tsan wants checks to
not cross aligned 8-byte granules, so the combined check must be
within an aligned 8-byte region. And another problem with this is
report quality -- the report may contain wrong line number/access size
if we do it. This is pretty nasty, and that's the reason we didn't do
it.
The pass also ignores accesses to global const data, vptr, etc. Maybe
there are some other opportunities here: either identifying more
non-racing locations, or identifying existing types better, e.g. for
pointers returned from functions (say, a function always returns a
pointer to const global).