<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p><span id="docs-internal-guid-f0f5e31c-1af3-3649-fd88-dea2b124a115"></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size: 11pt; font-family: Arial; background-color: transparent; vertical-align: baseline; white-space: pre-wrap;">Thanks for the quick response.</span></p>
<br>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size: 11pt; font-family: Arial; background-color: transparent; vertical-align: baseline; white-space: pre-wrap;">I tried what you’ve suggested, that is making function
 arguments noalias. However the result is still the same.</span></p>
<br>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size: 11pt; font-family: Arial; background-color: transparent; vertical-align: baseline; white-space: pre-wrap;">If it may help here are sample function and its IR:</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left: 36pt;">
<span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">void swap (int* restrict n, int* restrict m)</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left: 36pt;">
<span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">{</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left: 36pt;">
<span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">   int tmp = 9;</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left: 36pt;">
<span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">   *n = tmp;</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left: 36pt;">
<span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">   *m = 5;</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left: 36pt;">
<span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">}</span></p>
<br>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left: 36pt;">
<span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">; Function Attrs: nounwind uwtable</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left: 36pt;">
<span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">define void @swap(i32* noalias %n, i32* noalias %m) #0 {</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left: 36pt;">
<span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">entry:</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left: 36pt;">
<span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;"> %n.addr = alloca i32*, align 8</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left: 36pt;">
<span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;"> %m.addr = alloca i32*, align 8</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left: 36pt;">
<span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;"> %tmp = alloca i32, align 4</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left: 36pt;">
<span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;"> store i32* %n, i32** %n.addr, align 8</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left: 36pt;">
<span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;"> store i32* %m, i32** %m.addr, align 8</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left: 36pt;">
<span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;"> store i32 9, i32* %tmp, align 4</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left: 36pt;">
<span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;"> %0 = load i32, i32* %tmp, align 4</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left: 36pt;">
<span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;"> %1 = load i32*, i32** %n.addr, align 8</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left: 36pt;">
<span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;"> store i32 %0, i32* %1, align 4</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left: 36pt;">
<span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;"> %2 = load i32*, i32** %m.addr, align 8</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left: 36pt;">
<span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;"> store i32 5, i32* %2, align 4</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left: 36pt;">
<span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;"> ret void</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;margin-left: 36pt;">
<span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">}</span></p>
<br>
<br>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size: 11pt; font-family: Arial; background-color: transparent; vertical-align: baseline; white-space: pre-wrap;">In getAnalyisisUsage function of my pass I have</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size: 11pt; font-family: Arial; background-color: transparent; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space:pre;"></span></span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">AU.setPreservesAll();</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">       </span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space:pre;">
</span></span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">AU.addRequired<llvm::TargetLibraryInfoWrapperPass>();</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">       </span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space:pre;">
</span></span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">AU.addRequired<llvm::AssumptionCacheTracker>();</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">       </span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space:pre;">
</span></span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">AU.addRequired<llvm::AAResultsWrapperPass>();</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">       </span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;"><span class="Apple-tab-span" style="white-space:pre;">
</span></span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">llvm::getAAResultsAnalysisUsage(AU)</span><span style="background-color: transparent; font-family: Arial; font-size: 11pt; font-style: italic; white-space: pre-wrap;">;</span></p>
<br>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size: 11pt; font-family: Arial; background-color: transparent; vertical-align: baseline; white-space: pre-wrap;">And I get the AAResults by</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">llvm::AAResults& AAR = getAnalysis<llvm::AAResultsWrapperPass>().getAAResults();</span></p>
<br>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size: 11pt; font-family: Arial; background-color: transparent; vertical-align: baseline; white-space: pre-wrap;">I also tried running just llvm alias analysis and print
 alias sets. The arguments are in the same alias set.</span></p>
<br>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">opt -aa -print-alias-sets simple.bc
 -o out.bc</span></p>
<br>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size: 11pt; font-family: Arial; background-color: transparent; font-style: italic; vertical-align: baseline; white-space: pre-wrap;">Pointers: (i32* %1, 4), (i32* %2,
 4)</span><span style="font-size: 11pt; font-family: Arial; background-color: transparent; vertical-align: baseline; white-space: pre-wrap;"> are in the same set, where %1 is load for n and %2 is load for m.
</span></p>
<br>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><span style="font-size: 11pt; font-family: Arial; background-color: transparent; vertical-align: baseline; white-space: pre-wrap;">Could you please explain why I’m still getting the same
 results or if there is something that I’m doing wrong?</span></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><br>
</p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><font face="Arial"><span style="font-size: 14.6667px; white-space: pre-wrap;">Thanks,</span></font></p>
<p dir="ltr" style="line-height:1.38;margin-top:0pt;margin-bottom:0pt;"><font face="Arial"><span style="font-size: 14.6667px; white-space: pre-wrap;">Anahit.</span></font></p>
</span>
<p></p>
<div style="color: rgb(0, 0, 0);">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Hal Finkel <hfinkel@anl.gov><br>
<b>Sent:</b> Tuesday, March 28, 2017 11:29 PM<br>
<b>To:</b> Hayrapetyan, Anahit; llvm-dev@lists.llvm.org<br>
<b>Subject:</b> Re: [llvm-dev] llvm 3.9 Alias Analysis result for function's by-ref arguments</font>
<div> </div>
</div>
<div>
<p><br>
</p>
<div class="moz-cite-prefix">On 03/28/2017 04:32 AM, Hayrapetyan, Anahit via llvm-dev wrote:<br>
</div>
<blockquote type="cite">
<div id="divtagdefaultwrapper" style="font-size:12pt; color:#000000; font-family:Calibri,Arial,Helvetica,sans-serif">
<div id="divtagdefaultwrapper" style="font-size:12pt; color:#000000; font-family:Calibri,Arial,Helvetica,sans-serif">
<p><span id="docs-internal-guid-a663f343-143d-ef81-9e99-9c08bb7392cd">Hi, </span>
</p>
<p><br>
</p>
<p dir="ltr" style="line-height:1.38; margin-top:0pt; margin-bottom:0pt"><span style="font-size:11pt; font-family:Arial; background-color:transparent; vertical-align:baseline; white-space:pre-wrap">I’m writing an analysis pass which is supposed to find instructions
 in a function that modify function’s by-ref arguments. For that I’m using llvm AliasAnalysis pass, particularly querying for ModRef info for instructions and function arguments, to see if a given instruction modifies a given argument. However, for functions
 with more than one by-ref argument, I get strange results. Instructions, which modify one of the arguments, are reported as modifying the others too - saying, ModRef info of those instructions is Mod for all arguments.</span></p>
<p dir="ltr" style="line-height:1.38; margin-top:0pt; margin-bottom:0pt"><span style="font-size:11pt; font-family:Arial; background-color:transparent; vertical-align:baseline; white-space:pre-wrap">For this example</span></p>
</div>
<blockquote style="margin:0 0 0 40px; border:none; padding:0px">
<div style="font-size:12pt; color:#000000; font-family:Calibri,Arial,Helvetica,sans-serif">
<p dir="ltr" style="line-height:1.38; margin-top:0pt; margin-bottom:0pt"><span style="font-size:11pt; font-family:Arial; background-color:transparent; vertical-align:baseline; white-space:pre-wrap"><i>void function(int& n, int& m)</i></span></p>
</div>
<div style="font-size:12pt; color:#000000; font-family:Calibri,Arial,Helvetica,sans-serif">
<p dir="ltr" style="line-height:1.38; margin-top:0pt; margin-bottom:0pt"><span style="font-size:11pt; font-family:Arial; background-color:transparent; vertical-align:baseline; white-space:pre-wrap"><i>{</i></span></p>
</div>
<div style="font-size:12pt; color:#000000; font-family:Calibri,Arial,Helvetica,sans-serif">
<p dir="ltr" style="line-height:1.38; margin-top:0pt; margin-bottom:0pt"><span style="font-size:11pt; font-family:Arial; background-color:transparent; vertical-align:baseline; white-space:pre-wrap"><i>int tmp = m;</i></span></p>
</div>
<div style="font-size:12pt; color:#000000; font-family:Calibri,Arial,Helvetica,sans-serif">
<p dir="ltr" style="line-height:1.38; margin-top:0pt; margin-bottom:0pt"><span style="font-size:11pt; font-family:Arial; background-color:transparent; vertical-align:baseline; white-space:pre-wrap"><i>n = tmp;</i></span></p>
</div>
<div style="font-size:12pt; color:#000000; font-family:Calibri,Arial,Helvetica,sans-serif">
<p dir="ltr" style="line-height:1.38; margin-top:0pt; margin-bottom:0pt"><span style="font-size:11pt; font-family:Arial; background-color:transparent; vertical-align:baseline; white-space:pre-wrap"><i>}</i></span></p>
</div>
</blockquote>
<div style="font-size:12pt; color:#000000; font-family:Calibri,Arial,Helvetica,sans-serif">
<p dir="ltr" style="line-height:1.38; margin-top:0pt; margin-bottom:0pt"><span style="font-size:11pt; font-family:Arial; background-color:transparent; vertical-align:baseline; white-space:pre-wrap"></span></p>
<p dir="ltr" style="line-height:1.38; margin-top:0pt; margin-bottom:0pt"><span style="font-size:11pt; font-family:Arial; background-color:transparent; vertical-align:baseline; white-space:pre-wrap">Arguments
<i>n</i> and <i>m</i> are marked as MayAlias, and storing <i>tmp</i> into <i>n</i> is reported to modify
<i>m</i> too.</span></p>
</div>
</div>
</blockquote>
<blockquote type="cite">
<div id="divtagdefaultwrapper" style="font-size:12pt; color:#000000; font-family:Calibri,Arial,Helvetica,sans-serif">
<div style="font-size:12pt; color:#000000; font-family:Calibri,Arial,Helvetica,sans-serif">
<br>
<p dir="ltr" style="line-height:1.38; margin-top:0pt; margin-bottom:0pt"><span style="font-size:11pt; font-family:Arial; background-color:transparent; vertical-align:baseline; white-space:pre-wrap">I found a few discussions about this problem. In one of them,
 it was suggested to use cfl-aa, I tried it and it did not solve the problem.</span></p>
<p dir="ltr" style="line-height:1.38; margin-top:0pt; margin-bottom:0pt"><span style="font-size:11pt; font-family:Arial; background-color:transparent; vertical-align:baseline; white-space:pre-wrap">In another one they said that this happens on purpose. llvm
 Alias Analysis marks function’s by-ref arguments MayAlias, as function may be called with arguments referencing the same variable.</span></p>
<p dir="ltr" style="line-height:1.38; margin-top:0pt; margin-bottom:0pt"><span style="font-size:11pt; font-family:Arial; background-color:transparent; vertical-align:baseline; white-space:pre-wrap"></span></p>
<p dir="ltr" style="line-height:1.38; margin-top:0pt; margin-bottom:0pt"><span style="font-size:11pt; font-family:Arial; background-color:transparent; vertical-align:baseline; white-space:pre-wrap">So I would like to ask whether this is the case.</span></p>
</div>
</div>
</blockquote>
<br>
Yes, this is the case. <br>
It is legal to call the function as:<br>
<br>
  int a = ...;<br>
  function(a, a);<br>
<br>
And so we need to make a conservative assumption.<br>
<br>
<blockquote type="cite">
<div id="divtagdefaultwrapper" style="font-size:12pt; color:#000000; font-family:Calibri,Arial,Helvetica,sans-serif">
<div style="font-size:12pt; color:#000000; font-family:Calibri,Arial,Helvetica,sans-serif">
<p dir="ltr" style="line-height:1.38; margin-top:0pt; margin-bottom:0pt"><span style="font-size:11pt; font-family:Arial; background-color:transparent; vertical-align:baseline; white-space:pre-wrap">And if it is, is there a way to make llvm ignore this consideration?</span></p>
</div>
</div>
</blockquote>
<br>
Yes, if you add __restrict__ (noalias as the IR level), then we'll assume they don't alias.<br>
<br>
 -Hal<br>
<br>
<blockquote type="cite">
<div id="divtagdefaultwrapper" style="font-size:12pt; color:#000000; font-family:Calibri,Arial,Helvetica,sans-serif">
<div style="font-size:12pt; color:#000000; font-family:Calibri,Arial,Helvetica,sans-serif">
<p dir="ltr" style="line-height:1.38; margin-top:0pt; margin-bottom:0pt"><span style="font-size:11pt; font-family:Arial; background-color:transparent; vertical-align:baseline; white-space:pre-wrap"></span></p>
<p dir="ltr" style="line-height:1.38; margin-top:0pt; margin-bottom:0pt"><span style="font-size:11pt; font-family:Arial; background-color:transparent; vertical-align:baseline; white-space:pre-wrap">Thanks,</span></p>
<p dir="ltr" style="line-height:1.38; margin-top:0pt; margin-bottom:0pt"><span style="font-size:11pt; font-family:Arial; background-color:transparent; vertical-align:baseline; white-space:pre-wrap">Anahit.</span></p>
<br>
<br>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset> <br>
<pre>_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory</pre>
</div>
</div>
</div>
</body>
</html>