<p dir="ltr">> MemoryUses can reach back past the nearest def, so that doesn't affect uses</p>
<p dir="ltr">Ahh, I see. I did not know this. Thanks for the clarification.</p>
<p dir="ltr">I now believe I had passed insufficient AA information when I was trying to use memorySSA. </p>
<p dir="ltr">Can I add a detailed explanation that explains this to the memorySSA docs, or the "analysis passes" list? </p>
<p dir="ltr">Thanks,<br>
Siddharth</p>
<br><div class="gmail_quote"><div dir="ltr">On Tue 19 Dec, 2017, 21:26 Daniel Berlin, <<a href="mailto:dberlin@dberlin.org">dberlin@dberlin.org</a>> wrote:<br></div><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 Tue, Dec 19, 2017 at 9:10 AM, Siddharth Bhat via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">I could be entirely wrong, but from my understanding of memorySSA, each def defines an "abstract heap state" which has the coarsest possible definition - any write will be modelled as a "new heap state".</p></blockquote><div><br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>This is true for def-def relationships, but doesn't;'t matter here. <br></div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr"> </p></blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr"> So in that sense, from what I understand, it does not actually model the heap in a fine grained way. </p></blockquote><div><br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">Any write to any part of the heap will create a new memorydef node. </p>
<p dir="ltr"></p></blockquote></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>Yes, but MemoryUses can reach back past the nearest def, so that doesn't affect uses.<br></div><div> </div><div>The limitation here is deliberately done to keep it only requiring a single phi.</div><div><br></div><div>All data from building this for years in GCC (which also moved from "precise" to "imprecise" for the same reason) told us that the massive amount of def-use chains you end up with from trying to model def-def relationships precisely was not worth it by far.</div><div><br></div><div>(It degrades into putting N^2 variables into SSA, and attaching N variables to each def/use).</div></div></div></div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">With respect to that model, memorySSA is right. The value of A could depend on the abstract heap state of the definition of array "e". </p>
<p dir="ltr">I'm on my phone, so this may not make much sense, but I hope this helps,<br>
Siddharth. </p>
<br><div class="gmail_quote"><div><div class="m_8594822884922690211h5"><div dir="ltr">On Tue 19 Dec, 2017, 15:13 Venugopal Raghavan via llvm-dev, <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_8594822884922690211h5"><div dir="ltr"><div>Hi,</div><div><br></div>I am new to MemorySSA and wanted to understand its capabilities. Hence I wrote the following program (test.c):<div><br></div><div><div>int N;</div><div><br></div><div>void test(int *restrict a, int *restrict b, int *restrict c, int *restrict d, int *restrict e) {</div><div>  int i;</div><div>  for (i = 0; i < N; i = i + 5) {</div><div>     a[i] = b[i] + c[i];</div><div>  }</div><div><br></div><div>  for (i = 0; i < N - 5; i = i + 5) {</div><div>     e[i] = a[i] * d[i];</div><div>  }</div><div>}</div></div><div><br></div><div>I compiled this program using the following commands:</div><div><br></div><div>clang -c -o test_clang_out.ll -emit-llvm -O3 test.c<br></div><div>opt -o test_opt_out.ll -O3 -passes='print<memoryssa>' -disable-output test_clang_out.ll > out 2>&1<br></div><div><br></div><div>The relevant parts of the file "out" are shown below:</div><div>                                 .</div><div>                                 .</div><div>                                 .</div><div><br></div><div><div>for.body:                                         ; preds = %<a href="http://for.body.lr.ph" target="_blank">for.body.lr.ph</a>, %for.body</div><div>; 3 = MemoryPhi({<a href="http://for.body.lr.ph" target="_blank">for.body.lr.ph</a>,liveOnEntry},{for.body,1})</div><div>  %indvars.iv35 = phi i64 [ 0, %<a href="http://for.body.lr.ph" target="_blank">for.body.lr.ph</a> ], [ %indvars.iv.next36, %for.body ]</div><div>  %arrayidx = getelementptr inbounds i32, i32* %b, i64 %indvars.iv35</div><div>; MemoryUse(3)</div><div>  %2 = load i32, i32* %arrayidx, align 4, !tbaa !2</div><div>  %arrayidx2 = getelementptr inbounds i32, i32* %c, i64 %indvars.iv35</div><div>; MemoryUse(3)</div><div>  %3 = load i32, i32* %arrayidx2, align 4, !tbaa !2</div><div>  %add = add nsw i32 %3, %2</div><div>  %arrayidx4 = getelementptr inbounds i32, i32* %a, i64 %indvars.iv35</div><div><b>; 1 = MemoryDef(3)</b></div><div>  store i32 %add, i32* %arrayidx4, align 4, !tbaa !2</div><div>  %indvars.iv.next36 = add nuw nsw i64 %indvars.iv35, 5</div><div>  %cmp = icmp slt i64 %indvars.iv.next36, %1</div><div>  br i1 %cmp, label %for.body, label %for.end</div></div><div><br></div><div> for.end:                                          ; preds = %for.body</div><div>  %cmp729 = icmp sgt i32 %0, 5</div><div>  br i1 %cmp729, label %<a href="http://for.body8.lr.ph" target="_blank">for.body8.lr.ph</a>, label %for.end17</div><div><br></div><div><a href="http://for.body8.lr.ph" target="_blank">for.body8.lr.ph</a>:                                  ; preds = %for.end</div><div>  %sub = add nsw i32 %0, -5</div><div>  %4 = sext i32 %sub to i64</div><div>  br label %for.body8</div><div><br></div><div>  for.body8:                                        ; preds = %<a href="http://for.body8.lr.ph" target="_blank">for.body8.lr.ph</a>, %for.body8</div><div><b>; 4 = MemoryPhi({<a href="http://for.body8.lr.ph" target="_blank">for.body8.lr.ph</a>,1},{for.body8,2})</b></div><div>  %indvars.iv = phi i64 [ 0, %<a href="http://for.body8.lr.ph" target="_blank">for.body8.lr.ph</a> ], [ %indvars.iv.next, %for.body8 ]</div><div>  %arrayidx10 = getelementptr inbounds i32, i32* %a, i64 %indvars.iv</div><div><b>; MemoryUse(4)</b></div><div>  %5 = load i32, i32* %arrayidx10, align 4, !tbaa !2</div><div>  %arrayidx12 = getelementptr inbounds i32, i32* %d, i64 %indvars.iv</div><div>; MemoryUse(4)</div><div>  %6 = load i32, i32* %arrayidx12, align 4, !tbaa !2</div><div>  %mul = mul nsw i32 %6, %5</div><div>  %arrayidx14 = getelementptr inbounds i32, i32* %e, i64 %indvars.iv</div><div><b>; 2 = MemoryDef(4)</b></div><div>  store i32 %mul, i32* %arrayidx14, align 4, !tbaa !2</div><div>  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 5</div><div>  %cmp7 = icmp slt i64 %indvars.iv.next, %4</div><div>  br i1 %cmp7, label %for.body8, label %for.end17                                 </div><div><br></div><div><br></div><div>I have highlighted the interesting lines in bold.</div><div><br></div><div>I was interested in the use of array "a" in the second loop and and wanted to check if memorySSA would show the reaching definitions for these uses to emanate from the definitions in  1 = MemoryDef(3)<b> </b> and, indeed, the MemoryUse(4) corresponding to the use of "a" shows the reaching definition to be from the MemoryPhi node 4, which, in turn has one of its reaching definitions as 1 = MemoryDef(3). But this MemoryPHi node also has another reaching definition which is 2 = MemoryDef(4) which corresponds to the definition of array e in the second loop. </div><div><br></div><div>This seems to make the MemorySSA form imprecise because it seems to indicate that the use of "a" in the second loop could be having a reaching definition from the definition of "a" in the first loop or the definition of "e" in the second loop (through the MemoryPhi). I would have expected only the first reaching definition to be inferred.</div><div><br></div><div>Am I mis-interpreting the information here or mis-understanding the capabilities of MemorySSA? If not, can someone explain why the information is imprecise? Maybe the underlying alias analysis is unable to disambiguate the different arrays? But I would have thought that this would not be a difficult case for alias analysis.</div><div><br></div><div>Thanks.</div><div><br></div><div>Regards,</div><div>Venugopal Raghavan.</div><div><b>       </b><br></div><div><br></div></div></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><span class="m_8594822884922690211HOEnZb"><font color="#888888"><br>
</font></span></blockquote></div><span class="m_8594822884922690211HOEnZb"><font color="#888888"><div dir="ltr">-- <br></div><div class="m_8594822884922690211m_3686150438235044522gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Sending this from my phone, please excuse any typos!</div></div>
</font></span><br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div></div></div></blockquote></div><div dir="ltr">-- <br></div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">Sending this from my phone, please excuse any typos!</div></div>