<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". So in that sense, from what I understand, it does not actually model the heap in a fine grained way. Any write to any part of the heap will create a new memorydef node. </p>
<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 dir="ltr">On Tue 19 Dec, 2017, 15:13 Venugopal Raghavan via llvm-dev, <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.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>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>
_______________________________________________<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>
</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>