<div dir="ltr"><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:calibri,sans-serif"><span style="color:rgb(79,129,189)">void foo(int x) {<u></u><u></u></span></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:calibri,sans-serif"><span style="color:rgb(79,129,189)"> int p, i = 1;<u></u><u></u></span></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:calibri,sans-serif"><span style="color:rgb(79,129,189)"> int mat[6][6][6];<u></u><u></u></span></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:calibri,sans-serif"><span style="color:rgb(79,129,189)"> for (p = x+3 ; p<= x+6 ;p++)<u></u><u></u></span></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:calibri,sans-serif"><span style="color:rgb(79,129,189)"> mat[x][p][i] = mat[x][p][i] + 5;<u></u><u></u></span></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:calibri,sans-serif"><span style="color:rgb(79,129,189)">}</span></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:calibri,sans-serif"><span style="color:rgb(79,129,189)"><br></span></p><p class="MsoNormal" style="margin:0in 0in 0.0001pt;font-size:11pt;font-family:calibri,sans-serif"><span style="color:rgb(79,129,189)">When x=0, max(p)=6, which is outside of allocated 3d array, which is UB.</span></p></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 16, 2016 at 12:31 AM, Rai, Deepali 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">
<div lang="EN-US" link="blue" vlink="purple">
<div>
<p class="MsoNormal">Hi All,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I am trying to unroll the below loop, but couldn’t as SCEV returns TripCount as 0.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal"><span style="color:#4f81bd">void foo(int x) {<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> int p, i = 1;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> int mat[6][6][6];<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> for (p = x+3 ; p<= x+6 ;p++)<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> mat[x][p][i] = mat[x][p][i] + 5;<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd">}<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"><u></u> <u></u></span></p>
<p class="MsoNormal">For a quick reference I have added the generated IR compiled with clang using –O3.<u></u><u></u></p>
<p class="MsoNormal">Please let me know if this is an known issue in SCEV or I am missing something here ?<u></u><u></u></p>
<p class="MsoNormal"><span style="color:#4f81bd"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd">; Function Attrs: nounwind readnone uwtable<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd">define void @_Z3fooi(i32 %x) local_unnamed_addr #0 {<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd">entry:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> %mat = alloca [6 x [6 x [6 x i32]]], align 16<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> %0 = bitcast [6 x [6 x [6 x i32]]]* %mat to i8*<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> call void @llvm.lifetime.start(i64 864, i8* %0) #2<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> %add = add nsw i32 %x, 3<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> %add1 = add nsw i32 %x, 6<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> %idxprom3 = sext i32 %x to i64<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> %1 = sext i32 %add to i64<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> %2 = sext i32 %add1 to i64<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> br label %for.body<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd">for.body: <wbr> ; preds = %for.body, %entry<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ %1, %entry ]<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> %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<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> %3 = load i32, i32* %arrayidx5, align 4, !tbaa !1<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> %add6 = add nsw i32 %3, 5<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> store i32 %add6, i32* %arrayidx5, align 4, !tbaa !1<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> %indvars.iv.next = add nsw i64 %indvars.iv, 1<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> %cmp = icmp slt i64 %indvars.iv, %2<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> br i1 %cmp, label %for.body, label %for.end<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd">for.end: <wbr> ; preds = %for.body<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> call void @llvm.lifetime.end(i64 864, i8* nonnull %0) #2<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"> ret void<u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd">} <u></u><u></u></span></p>
<p class="MsoNormal"><span style="color:#4f81bd"><u></u> <u></u></span></p>
<p class="MsoNormal">Thanks,<u></u><u></u></p>
<p class="MsoNormal">Deepali<u></u><u></u></p>
</div>
</div>
<br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">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/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>