<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></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 Sep 16, 2016, at 4:45 AM, Philip Pfaffe via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">There is no way to express the trip count in a closed expression.<div class=""><br class=""></div><div class="">E.g., if I call foo(MAX_INT - 2), the loop condition will evaluate to false immediately.</div></div></div></blockquote><div><br class=""></div><div>Are you implying that because of wrapping?</div><div>Signed integer wrapping is UB.</div><div><br class=""></div><div>— </div><div>Mehdi</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">Best,</div><div class="">Philip</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">2016-09-16 10:44 GMT+02:00 Rai, Deepali via llvm-dev <span dir="ltr" class=""><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>></span>:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-US" link="blue" vlink="purple" class="">
<div class=""><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" class="">I have modified the example test case for UB error, still it didn’t unroll<u class=""></u><u class=""></u></span></p><span class=""><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" class=""><u class=""></u> <u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#4f81bd" class="">void foo(int x) {<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#4f81bd" class="">  int p, i = 1;<u class=""></u><u class=""></u></span></p>
</span><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#4f81bd" class="">  int mat[9][9][9];<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#4f81bd" class="">  for (p = (x+1) ; p < (x+3) ;p++)<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#4f81bd" class="">    mat[x][p-1][i] = mat[x][p-1][i] + 5;<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#4f81bd" class="">}<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" class=""><u class=""></u> <u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" class="">Regard,<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" class="">Deepali<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1f497d" class=""><u class=""></u> <u class=""></u></span></p><p class="MsoNormal"><b class=""><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"" class="">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"" class=""> Kevin Choi [mailto:<a href="mailto:code.kchoi@gmail.com" target="_blank" class="">code.kchoi@gmail.com</a>]
<br class="">
<b class="">Sent:</b> Friday, September 16, 2016 1:20 PM<br class="">
<b class="">To:</b> Rai, Deepali<br class="">
<b class="">Cc:</b> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><br class="">
<b class="">Subject:</b> Re: [llvm-dev] SCEV cannot compute the trip count of Simple loop<u class=""></u><u class=""></u></span></p><div class=""><div class="h5"><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
<div class=""><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#4f81bd" class="">void foo(int x) {</span><span style="font-size:11.0pt;font-family:"Calibri","sans-serif"" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#4f81bd" class="">  int p, i = 1;</span><span style="font-size:11.0pt;font-family:"Calibri","sans-serif"" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#4f81bd" class="">  int mat[6][6][6];</span><span style="font-size:11.0pt;font-family:"Calibri","sans-serif"" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#4f81bd" class="">  for (p = x+3 ; p<= x+6 ;p++)</span><span style="font-size:11.0pt;font-family:"Calibri","sans-serif"" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#4f81bd" class="">    mat[x][p][i] = mat[x][p][i] + 5;</span><span style="font-size:11.0pt;font-family:"Calibri","sans-serif"" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#4f81bd" class="">}</span><span style="font-size:11.0pt;font-family:"Calibri","sans-serif"" class=""><u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif"" class=""><u class=""></u> <u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#4f81bd" class="">When x=0, max(p)=6, which is outside of allocated 3d array, which is UB.</span><span style="font-size:11.0pt;font-family:"Calibri","sans-serif"" class=""><u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
<div class=""><p class="MsoNormal">On Fri, Sep 16, 2016 at 12:31 AM, Rai, Deepali via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>> wrote:<u class=""></u><u class=""></u></p>
<div class="">
<div class=""><p class="MsoNormal">Hi All,<u class=""></u><u class=""></u></p><p class="MsoNormal"> <u class=""></u><u class=""></u></p><p class="MsoNormal">I am trying to unroll the below loop, but couldn’t as SCEV returns TripCount as 0.<u class=""></u><u class=""></u></p><p class="MsoNormal"> <u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">void foo(int x) {</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">  int p, i = 1;</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">  int mat[6][6][6];</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">  for (p = x+3 ; p<= x+6 ;p++)</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">    mat[x][p][i] = mat[x][p][i] + 5;</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">}</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class=""> </span><u class=""></u><u class=""></u></p><p class="MsoNormal">For a quick reference I have added the generated IR compiled with clang using –O3.<u class=""></u><u class=""></u></p><p class="MsoNormal">Please let me know if this is an known issue in SCEV or I am missing something here ?<u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class=""> </span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">; Function Attrs: nounwind readnone uwtable</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">define void @_Z3fooi(i32 %x) local_unnamed_addr #0 {</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">entry:</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">  %mat = alloca [6 x [6 x [6 x i32]]], align 16</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">  %0 = bitcast [6 x [6 x [6 x i32]]]* %mat to i8*</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">  call void @llvm.lifetime.start(i64 864, i8* %0) #2</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">  %add = add nsw i32 %x, 3</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">  %add1 = add nsw i32 %x, 6</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">  %idxprom3 = sext i32 %x to i64</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">  %1 = sext i32 %add to i64</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">  %2 = sext i32 %add1 to i64</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">  br label %for.body</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class=""> </span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">for.body:                     <wbr class="">                    ; preds = %for.body, %entry</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ %1, %entry ]</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">  %arrayidx5 = getelementptr inbounds [6 x [6 x [6 x i32]]], [6 x [6 x [6 x i32]]]* %mat, i64 0, i64 %idxprom3, i64 %indvars.iv, i64 1</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">  %3 = load i32, i32* %arrayidx5, align 4, !tbaa !1</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">  %add6 = add nsw i32 %3, 5</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">  store i32 %add6, i32* %arrayidx5, align 4, !tbaa !1</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">  %indvars.iv.next = add nsw i64 %indvars.iv, 1</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">  %cmp = icmp slt i64 %indvars.iv, %2</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">  br i1 %cmp, label %for.body, label %for.end</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class=""> </span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">for.end:                      <wbr class="">                    ; preds = %for.body</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">  call void @llvm.lifetime.end(i64 864, i8* nonnull %0) #2</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">  ret void</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class="">}
</span><u class=""></u><u class=""></u></p><p class="MsoNormal"><span style="color:#4f81bd" class=""> </span><u class=""></u><u class=""></u></p><p class="MsoNormal">Thanks,<u class=""></u><u class=""></u></p><p class="MsoNormal">Deepali<u class=""></u><u class=""></u></p>
</div>
</div><p class="MsoNormal" style="margin-bottom:12.0pt"><br class="">
______________________________<wbr class="">_________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank" class="">http://lists.llvm.org/cgi-bin/<wbr class="">mailman/listinfo/llvm-dev</a><u class=""></u><u class=""></u></p>
</div><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
</div></div></div>
</div>

<br class="">______________________________<wbr class="">_________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/<wbr class="">mailman/listinfo/llvm-dev</a><br class="">
<br class=""></blockquote></div><br class=""></div>
_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></blockquote></div><br class=""></body></html>