<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></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 Jun 2, 2015, at 12:02 PM, Adam Nemet <<a href="mailto:anemet@apple.com" class="">anemet@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Helvetica; font-size: 11px; 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;">Hi,</div><div class="" style="font-family: Helvetica; font-size: 11px; 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><div class="" style="font-family: Helvetica; font-size: 11px; 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;">The patch looks good but I’d like to see some benchmarking data before fully signing off on this.  Most importantly, do we vectorize more now?  My concern is that we may have tuned the threshold with the incorrect formula.</div></div></blockquote><div><br class=""></div><div>Also since we’re benchmarking in this area it would be great to completely move away from using an estimate for the number of memchecks.</div><div><br class=""></div><div>There is a new API in LAA (RuntimePointerCheck::needsAnyChecking) that uses the actual number of memchecks needed.  Most notably it excludes checks that the dependence analysis deems unnecessary (i.e. the DependencySetId check in needsChecking).</div><div><br class=""></div><div>We could add a new API returning the actual number instead of estimating this.</div><div><br class=""></div><div>Adam</div><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Helvetica; font-size: 11px; 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><div class="" style="font-family: Helvetica; font-size: 11px; 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;">More comments below.  Also next time, please use Phab, thanks!</div><div class="" style="font-family: Helvetica; font-size: 11px; 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><span style="font-family: Helvetica; font-size: 11px; 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="">On Jun 2, 2015, at 9:44 AM, Silviu Baranga <</span><a href="mailto:silviu.baranga@arm.com" class="" style="font-family: Helvetica; font-size: 11px; 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;">silviu.baranga@arm.com</a><span style="font-family: Helvetica; font-size: 11px; 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="">> wrote:</span><br class="" style="font-family: Helvetica; font-size: 11px; 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;"><div style="font-family: Helvetica; font-size: 11px; 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=""><blockquote type="cite" class=""><br class="Apple-interchange-newline"><div class=""><div class="WordSection1" style="page: WordSection1; orphans: auto; text-align: start; text-indent: 0px; widows: auto; -webkit-text-stroke-width: 0px; word-spacing: 0px; white-space: normal; text-transform: none; line-height: normal; letter-spacing: normal; font-weight: normal; font-variant: normal; font-style: normal; font-size: 11px; font-family: Helvetica;"><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">Hi,<o:p class=""></o:p></div><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p class=""> </o:p></div><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">The attached patch fixes the estimation of the number of memchecks.<o:p class=""></o:p></div><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p class=""> </o:p></div><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">We need to add a runtime memcheck for pair of accesses (x,y) where at least one of x and y<o:p class=""></o:p></div><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">are writes.<o:p class=""></o:p></div><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p class=""> </o:p></div><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">Assuming we have w writes and r reads, currently this number is  estimated as being<o:p class=""></o:p></div><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">w* (w+r-1). This estimation will count (write,write) pairs twice and will overestimate<o:p class=""></o:p></div><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">the number of checks required.<o:p class=""></o:p></div><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p class=""> </o:p></div><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">The actual number of memchecks is (r + w - 1) + (r + w - 2) + .. + r which is equal to<o:p class=""></o:p></div><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">(w^2 + 2wr - w)/2.<o:p class=""></o:p></div><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p class=""> </o:p></div><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">The patch changes the formula and adds a small test.<o:p class=""></o:p></div><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p class=""> </o:p></div><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">Please review!<o:p class=""></o:p></div><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p class=""> </o:p></div><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">Thanks,<o:p class=""></o:p></div><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;">Silviu<o:p class=""></o:p></div><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p class=""> </o:p></div><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p class=""> </o:p></div></div></div></blockquote><div class=""><blockquote type="cite" class=""><div class="">diff --git a/lib/Analysis/LoopAccessAnalysis.cpp b/lib/Analysis/LoopAccessAnalysis.cpp</div><div class="">index 782bf70..5f97392 100644</div><div class="">--- a/lib/Analysis/LoopAccessAnalysis.cpp</div><div class="">+++ b/lib/Analysis/LoopAccessAnalysis.cpp</div><div class="">@@ -357,8 +357,12 @@ bool AccessAnalysis::canCheckPtrAtRT(</div><div class="">     if (IsDepCheckNeeded && CanDoRT && RunningDepId == 2)</div><div class="">       NumComparisons += 0; // Only one dependence set.</div><div class="">     else {</div><div class="">-      NumComparisons += (NumWritePtrChecks * (NumReadPtrChecks +</div><div class="">-                                              NumWritePtrChecks - 1));</div><div class="">+      // For r reads and w writes we will do</div><div class="">+      // (r + w - 1) + (r + w - 2) + .. + r checks,</div><div class="">+      // which evaluates to (w^2 + 2wr - w) / 2 checks.</div><div class="">+      NumComparisons += (NumWritePtrChecks * NumWritePtrChecks +</div><div class="">+                         2 * NumWritePtrChecks * NumReadPtrChecks -</div><div class="">+                         NumWritePtrChecks) / 2;</div></blockquote><div class=""><br class=""></div><div class="">Please add more comment.  Clearly this is not obvious because whoever wrote the original code didn’t get it right.  Something like this: for each write we have to compare against all reads and write that we haven’t previously compared against.</div><div class=""><br class=""></div><div class="">You may also want to add the alternative way of how for example I worked out your formula:  it’s a combination of two writes plus all writes against all reads, i.e. C(w, 2) + w*r = w*(w-1)/2 + wr = (w^2 - w + 2wr)/2</div><br class=""><blockquote type="cite" class=""><div class="">     }</div><div class=""> </div><div class="">     ++ASId;</div><div class="">diff --git a/test/Analysis/LoopAccessAnalysis/number-of-memchecks.ll b/test/Analysis/LoopAccessAnalysis/number-of-memchecks.ll</div><div class="">new file mode 100644</div><div class="">index 0000000..4ef3667</div><div class="">--- /dev/null</div><div class="">+++ b/test/Analysis/LoopAccessAnalysis/number-of-memchecks.ll</div><div class="">@@ -0,0 +1,52 @@</div><div class="">+; RUN: opt -loop-accesses -analyze < %s | FileCheck %s</div><div class="">+</div><div class="">+; 3 reads and 3 writes should need 12 memchecks</div><div class="">+</div><div class="">+target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"</div><div class="">+target triple = "aarch64--linux-gnueabi"</div><div class="">+</div><div class="">+; CHECK: Memory dependences are safe with run-time checks</div><div class="">+; CHECK: 11:</div><div class="">+; CHECK-NOT: 12:</div></blockquote><div class=""><br class=""></div><div class="">Your comment above and what you’re checking disagree.  I think the correct number is 12 and we used estimate 15 here.</div><div class=""><br class=""></div><div class="">Please also match the line "Run-time memory checks:” and then the number after it with CHECK-NEXT.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Adam</div><br class=""><blockquote type="cite" class=""><div class="">+</div><div class="">+define void @testf(i16* %a,</div><div class="">+               i16* %b,</div><div class="">+               i16* %c,</div><div class="">+               i16* %d,</div><div class="">+               i16* %e,</div><div class="">+               i16* %f) {</div><div class="">+entry:</div><div class="">+  br label %for.body</div><div class="">+</div><div class="">+for.body:                                         ; preds = %for.body, %entry</div><div class="">+  %ind = phi i64 [ 0, %entry ], [ %add, %for.body ]</div><div class="">+</div><div class="">+  %add = add nuw nsw i64 %ind, 1</div><div class="">+</div><div class="">+  %arrayidxA = getelementptr inbounds i16, i16* %a, i64 %ind</div><div class="">+  %loadA = load i16, i16* %arrayidxA, align 2</div><div class="">+</div><div class="">+  %arrayidxB = getelementptr inbounds i16, i16* %b, i64 %ind</div><div class="">+  %loadB = load i16, i16* %arrayidxB, align 2</div><div class="">+</div><div class="">+  %arrayidxC = getelementptr inbounds i16, i16* %c, i64 %ind</div><div class="">+  %loadC = load i16, i16* %arrayidxC, align 2</div><div class="">+</div><div class="">+  %mul = mul i16 %loadB, %loadA</div><div class="">+  %mul1 = mul i16 %mul, %loadC</div><div class="">+</div><div class="">+  %arrayidxD = getelementptr inbounds i16, i16* %d, i64 %ind</div><div class="">+  store i16 %mul1, i16* %arrayidxD, align 2</div><div class="">+</div><div class="">+  %arrayidxE = getelementptr inbounds i16, i16* %e, i64 %ind</div><div class="">+  store i16 %mul, i16* %arrayidxE, align 2</div><div class="">+</div><div class="">+  %arrayidxF = getelementptr inbounds i16, i16* %f, i64 %ind</div><div class="">+  store i16 %mul1, i16* %arrayidxF, align 2</div><div class="">+</div><div class="">+  %exitcond = icmp eq i64 %add, 20</div><div class="">+  br i1 %exitcond, label %for.end, label %for.body</div><div class="">+</div><div class="">+for.end:                                          ; preds = %for.body</div><div class="">+  ret void</div><div class="">+}</div></blockquote><div class=""><div class=""><br class=""></div></div></div><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div class="WordSection1" style="page: WordSection1; orphans: auto; text-align: start; text-indent: 0px; widows: auto; -webkit-text-stroke-width: 0px; word-spacing: 0px; white-space: normal; text-transform: none; line-height: normal; letter-spacing: normal; font-weight: normal; font-variant: normal; font-style: normal; font-size: 11px; font-family: Helvetica;"><div class="" style="margin: 0cm 0cm 0.0001pt; font-size: 11pt; font-family: Calibri, sans-serif;"><o:p class=""> </o:p></div></div><span id="cid:15AA98ED-0D71-4A28-8A80-CABB100E7D09@apple.com" class=""><runtime.diff></span><span class="" style="font-family: Helvetica; font-size: 11px; 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;">_______________________________________________</span><br class="" style="font-family: Helvetica; font-size: 11px; 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;"><span class="" style="font-family: Helvetica; font-size: 11px; 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;">llvm-commits mailing list</span><br class="" style="font-family: Helvetica; font-size: 11px; 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;"><a href="mailto:llvm-commits@cs.uiuc.edu" class="" style="color: purple; text-decoration: underline; font-family: Helvetica; font-size: 11px; 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;">llvm-commits@cs.uiuc.edu</a><br class="" style="font-family: Helvetica; font-size: 11px; 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;"><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" class="" style="color: purple; text-decoration: underline; font-family: Helvetica; font-size: 11px; 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;">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a></div></blockquote></div><br class="" style="font-family: Helvetica; font-size: 11px; 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;"><span style="font-family: Helvetica; font-size: 11px; 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: 11px; 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: 11px; 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: 11px; 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: 11px; 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: 11px; 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: 11px; 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>