This is an archive of the discontinued LLVM Phabricator instance.

[InstrProf] Use atomic profile counter updates for TSan
ClosedPublic

Authored by vsk on Aug 16 2018, 2:40 PM.

Details

Summary

Thread sanitizer instrumentation fails to skip all loads and stores to
profile counters. This can happen if profile counter updates are merged:

%.sink = phi i64* ...
%pgocount5 = load i64, i64* %.sink
%27 = add i64 %pgocount5, 1
%28 = bitcast i64* %.sink to i8*
call void @__tsan_write8(i8* %28)
store i64 %27, i64* %.sink

To suppress TSan diagnostics about racy counter updates, make the
counter updates atomic when TSan is enabled. If there's general interest
in this mode it can be surfaced as a clang/swift driver option.

rdar://40477803

Diff Detail

Repository
rL LLVM

Event Timeline

vsk created this revision.Aug 16 2018, 2:40 PM
jfb added inline comments.Aug 16 2018, 2:42 PM
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
608 ↗(On Diff #161113)

Counters could just be relaxed, no need to use seq_cst.

vsk updated this revision to Diff 161118.Aug 16 2018, 2:53 PM
vsk marked an inline comment as done.
vsk added inline comments.
llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
608 ↗(On Diff #161113)

Thanks for calling this out.

davidxl accepted this revision.Aug 16 2018, 3:22 PM

lgtm

This revision is now accepted and ready to land.Aug 16 2018, 3:22 PM
This revision was automatically updated to reflect the committed changes.