<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jul 29, 2015, at 4:56 PM, Alexey Samsonov <<a href="mailto:vonosmas@gmail.com" class="">vonosmas@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Do relaxed atomics actually introduce that much of slowdown?</div></div></blockquote><div><br class=""></div>I would definitely want to see some data showing that they do not slow things down before we decide to do this unconditionally. We’ve discussed this issue several times in the past. My recollection is those discussions ended with an acknowledgement there is a tradeoff between speed and accuracy and that we don’t all agree on where we want to be on that spectrum. Adding options to let people choose would be one solution. Good data, on a variety of platforms, showing that it doesn’t make much difference would be another way to resolve it.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class=""><br class=""></div><div class="">You're intentionally introducing a data race, this doesn't look good to me at all. However, I'm not confident about</div><div class="">what's allowed in LLVM IR - it's not C++ where any source-level data race is UB, but not an x86 assembly either.</div></div><div class="gmail_extra" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""><div class="gmail_quote">On Wed, Jul 29, 2015 at 4:43 PM, Justin Bogner<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:mail@justinbogner.com" target="_blank" class="">mail@justinbogner.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><span class="">Alexey Samsonov <<a href="mailto:vonosmas@gmail.com" class="">vonosmas@gmail.com</a>> writes:<br class="">> samsonov created this revision.<br class="">> samsonov added reviewers: dnovillo, bogner.<br class="">> samsonov added a subscriber: llvm-commits.<br class="">><br class="">> Since we introduced counters for functions in COMDAT sections (e.g.<br class="">> inline functions from STL headers), these headers can easily be<br class="">> incremented concurrently by multiple threads. Replace load-add-store<br class="">> with a single "atomicrmw add" with monotonic memory ordering.<br class=""><br class=""></span>This significantly changes the performance characteristics of this code,<br class="">pessimizing single-threaded users and potentially making the<br class="">multithreaded performance issues even worse.<br class=""><br class="">It's fine to add an option to lower these to atomics, since this does<br class="">guarantee accuracy, but I think we need a switch to choose which kind of<br class="">lowering we're interested in in that case.<br class=""><div class="HOEnZb"><div class="h5"><br class="">><span class="Apple-converted-space"> </span><a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D11579&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=lDx1rX-3B32oZTA_vCe21kRN0Y14ujW2ePnnU3JiUX4&s=tiiUXsu0al8aXyrPKSc28tcPx4YG5wxgSglC63-ASTQ&e=" rel="noreferrer" target="_blank" class="">http://reviews.llvm.org/D11579</a><br class="">><br class="">> Files:<br class="">>   lib/Transforms/Instrumentation/InstrProfiling.cpp<br class="">><br class="">> Index: lib/Transforms/Instrumentation/InstrProfiling.cpp<br class="">> ===================================================================<br class="">> --- lib/Transforms/Instrumentation/InstrProfiling.cpp<br class="">> +++ lib/Transforms/Instrumentation/InstrProfiling.cpp<br class="">> @@ -147,9 +147,9 @@<br class="">>    IRBuilder<> Builder(Inc->getParent(), *Inc);<br class="">>    uint64_t Index = Inc->getIndex()->getZExtValue();<br class="">>    Value *Addr = Builder.CreateConstInBoundsGEP2_64(Counters, 0, Index);<br class="">> -  Value *Count = Builder.CreateLoad(Addr, "pgocount");<br class="">> -  Count = Builder.CreateAdd(Count, Builder.getInt64(1));<br class="">> -  Inc->replaceAllUsesWith(Builder.CreateStore(Count, Addr));<br class="">> +  Builder.CreateAtomicRMW(AtomicRMWInst::Add, Addr, Builder.getInt64(1),<br class="">> +                          llvm::Monotonic);<br class="">> +  assert(Inc->use_empty() && "InstrProfIncrementInst has uses!");<br class="">>    Inc->eraseFromParent();<br class="">>  }<br class=""><br class=""></div></div></blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div>--<span class="Apple-converted-space"> </span><br class=""><div class="gmail_signature"><div dir="ltr" class="">Alexey Samsonov<br class=""><a href="mailto:vonosmas@gmail.com" target="_blank" class="">vonosmas@gmail.com</a></div></div></div><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">llvm-commits mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:llvm-commits@cs.uiuc.edu" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">llvm-commits@cs.uiuc.edu</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a></div></blockquote></div><br class=""></body></html>