<div dir="ltr">It was on mac. I've attached the exact diff on top of my previous patch.</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 27, 2015 at 3:14 PM, Daniel Berlin <span dir="ltr"><<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I cannot get it to crash on the testcase you have provided with the change I suggested.<div><br></div><div>What platform did you try this on?</div><div><div class="h5"><div><br><br><div class="gmail_quote">On Mon, Apr 27, 2015 at 2:56 PM Sean Silva <<a href="mailto:chisophugis@gmail.com" target="_blank">chisophugis@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Apr 27, 2015 at 2:24 PM, Daniel Berlin <span dir="ltr"><<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</a>></span> wrote:<br><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"><div dir="ltr"><br><br><div class="gmail_quote"><span>On Mon, Apr 27, 2015 at 1:58 PM Sean Silva <<a href="mailto:chisophugis@gmail.com" target="_blank">chisophugis@gmail.com</a>> wrote:<br><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"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Apr 27, 2015 at 1:34 PM, Daniel Berlin <span dir="ltr"><<a href="mailto:dberlin@dberlin.org" target="_blank">dberlin@dberlin.org</a>></span> wrote:<br><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"><div dir="ltr">Refactoring should be easy.<br><br>The whole set of blocks can be replaced with:<br><div><div>  // Scan the function bodies for explicit loads or stores.</div><div>    for (unsigned i = 0, e = SCC.size(); i != e && FunctionEffect != ModRef;++i)</div><div>      for (inst_iterator II = inst_begin(SCC[i]->getFunction()),</div><div>             E = inst_end(SCC[i]->getFunction());</div><div>           II != E && FunctionEffect != ModRef; ++II)</div><div>{</div><div>FunctionEffect |= getModRefInfo(&*II);</div><div>}</div><div><br></div></div><div><br>This should fix your bug too (your code misses FenceInst, VAArgInst, and a few others) ;)</div><div><br></div><div>The only one i'm not 100% positive this covers is isAllocationFn and isFreeFn, but we should get the right answer here anyway if i'm following call chains right.</div></div></blockquote><div><br></div><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Any idea about the best way to test this? We could extend the testing in the original patch to cover other instructions, but I feel like having the list of instructions in the test is as fragile as open-coding the list of instructions in the code.</div></div></div></div></blockquote><div><br></div></span><div>If people add instructions, we always have this problem.</div><div><br></div><div>I would actually start by adding the tests it was performing before to unittests/Analysis/AliasAnalysisTest (which now exists)  to make sure getModRefInfo returns the results it was expecting.</div><div><br></div><div>That will test this path make sure the code path is still getting the same answers.</div><div><br></div><div>Then I would add whatever tests for globalsmodref to make sure that is getting turned into right mod/ref results for your volatile cases.</div><div><div><div><br></div></div></div></div></div></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>It sounds like you have a pretty clear idea of the path forward, would you mind comandeering the patch from me? While I'd love to dig into this as a learning experience for this part of the codebase, right now I'm currently neck-deep in running some performance tests.</div><div><br></div><div>FWIW I tried your suggested modification and it is dying with:</div><div><br></div><div>* thread #1: tid = 0xaf3005, 0x0000000100874297 opt`llvm::GetUnderlyingObject(llvm::Value*, llvm::DataLayout const&, unsigned int) [inlined] llvm::Value::getType(this=0x0000000000000000) const at Value.h:207, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x8)</div><div>  * frame #0: 0x0000000100874297 opt`llvm::GetUnderlyingObject(llvm::Value*, llvm::DataLayout const&, unsigned int) [inlined] llvm::Value::getType(this=0x0000000000000000) const at Value.h:207</div><div>    frame #1: 0x0000000100874297 opt`llvm::GetUnderlyingObject(V=0x0000000000000000, DL=0x0000000102414398, MaxLookup=6) + 23 at ValueTracking.cpp:2769</div><div>    frame #2: 0x0000000100c1ced5 opt`(anonymous namespace)::GlobalsModRef::alias(llvm::AliasAnalysis::Location const&, llvm::AliasAnalysis::Location const&) [inlined] llvm::GetUnderlyingObject(MaxLookup=6) + 5 at ValueTracking.h:177</div><div>    frame #3: 0x0000000100c1ced0 opt`(anonymous namespace)::GlobalsModRef::alias(this=0x0000000102416520, LocA=0x00007fff5fbfefd8, LocB=0x00007fff5fbff1c0) + 64 at GlobalsModRef.cpp:492</div><div>    frame #4: 0x0000000100724889 opt`llvm::AliasAnalysis::getModRefInfo(this=0x0000000102416540, CX=<unavailable>, Loc=0x00007fff5fbff1c0) + 169 at AliasAnalysis.cpp:403</div><div>    frame #5: 0x0000000100c1cade opt`(anonymous namespace)::GlobalsModRef::runOnModule(llvm::Module&) [inlined] llvm::AliasAnalysis::getModRefInfo(this=0x0000000102416540, I=<unavailable>) + 5118 at AliasAnalysis.h:383</div><div>    frame #6: 0x0000000100c1ca5b opt`(anonymous namespace)::GlobalsModRef::runOnModule(llvm::Module&) + 40 at GlobalsModRef.cpp:443</div><div>    frame #7: 0x0000000100c1ca33 opt`(anonymous namespace)::GlobalsModRef::runOnModule(this=0x0000000102416520, M=<unavailable>) + 4947 at GlobalsModRef.cpp:105</div><div>    frame #8: 0x0000000100bbc3f1 opt`llvm::legacy::PassManagerImpl::run(llvm::Module&) + 111 at LegacyPassManager.cpp:1616</div><div>    frame #9: 0x0000000100bbc382 opt`llvm::legacy::PassManagerImpl::run(this=0x0000000102413ed0, M=0x00000001024142b0) + 738 at LegacyPassManager.cpp:1723</div><div>    frame #10: 0x000000010000ff7c opt`main(argc=<unavailable>, argv=0x00007fff5fbff830) + 7676 at opt.cpp:611</div><div>    frame #11: 0x00007fff95dcc5c9 libdyld.dylib`start + 1</div><div><br></div><div>on the test case in my original patch.</div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>-- Sean Silva</div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div> </div><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"><div dir="ltr"><div class="gmail_quote"><div><div><div></div><div><br></div><div> <br></div><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"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>-- Sean Silva</div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><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"><div dir="ltr"><div><div><div><br></div><div class="gmail_quote">On Mon, Apr 27, 2015 at 1:16 PM Sean Silva <<a href="mailto:chisophugis@gmail.com" target="_blank">chisophugis@gmail.com</a>> wrote:<br><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"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sat, Apr 25, 2015 at 2:21 AM, Hal Finkel <span dir="ltr"><<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>></span> wrote:<br><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"><div><div>----- Original Message -----<br>
> From: "Sean Silva" <<a href="mailto:chisophugis@gmail.com" target="_blank">chisophugis@gmail.com</a>><br>
> To: <a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
> Cc: "Hal Finkel" <<a href="mailto:hfinkel@anl.gov" target="_blank">hfinkel@anl.gov</a>>, "Nick Lewycky" <<a href="mailto:nlewycky@google.com" target="_blank">nlewycky@google.com</a>>, "Philip Reames" <<a href="mailto:listmail@philipreames.com" target="_blank">listmail@philipreames.com</a>><br>
> Sent: Friday, April 24, 2015 10:56:58 PM<br>
> Subject: [PATCH] [globalsmodref-aa] Atomics *DO* touch memory...<br>
><br>
><br>
> GlobalsModRef was giving a spurious alias analysis result because it<br>
> failed to consider that atomics access memory. The attached patch<br>
> fixes that (PR23345).<br>
><br>
><br>
> I reduced this from a "compare and swap" loop that looked funny in<br>
> the machine code: the "compare and swap" had in fact been hoisted<br>
> out of the loop. I only ran into this when I tried `-flto -O2<br>
> -fno-inline`.<br>
><br>
><br>
> The structure of the test is pretty closely copied from one of the<br>
> others in the directory. Any better ideas for testing this (or ways<br>
> to make the testing more thorough) would be appreciated.<br>
><br>
><br>
> If somebody can doublecheck that these are the only missing cases,<br>
> that would be appreciated. This loop been touched since 2012 and I'm<br>
> relatively clueless about AA. Hopefully this patch also suggests a<br>
> couple other places to audit for similar bugs to those with a better<br>
> "big picture" of the IR analysis and transforms than myself.<br>
<br>
</div></div>Hi Sean,<br>
<br>
The list is also missing VAArgInst, although maybe that's on purpose (although, in that case, a comment would be nice).<br>
<br>
While we're looking at this, other things I don't understand about this loop are 1) Why is is special casing alloc/free functions and 2) why is it treating all volatile accesses as read/write?<br></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>I know at least for volatile accesses it is because it might be a hardware register that has some arbitrary effect on other memory. A simple example is ARM's "bit-banding".</div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div> </div><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">
<br>
It might be nice to refactor this code to call<br>
  ModRefResult getModRefInfo(const Instruction *I)<br>
from AliasAnalysis. That way we could reduce the number of places that replicate this kind of logic.<br></blockquote><div><br></div><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Hal, others: I'm really not an expert in AA or even really have that much experience at the IR level. Would one of you be willing to comandeer this patch from me? I'm afraid that I'm mostly going to be slowing things down here.</div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>-- Sean Silva</div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><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">
<br>
 -Hal<br>
<br>
><br>
><br>
> -- Sean Silva<br>
<span><font color="#888888"><br>
--<br>
Hal Finkel<br>
Assistant Computational Scientist<br>
Leadership Computing Facility<br>
Argonne National Laboratory<br>
</font></span></blockquote></div></div></div></blockquote></div></div></div></div>
</blockquote></div></div></div></blockquote></div></div></div></div>
</blockquote></div></div></div></blockquote></div></div></div></div></div>
</blockquote></div><br></div>