<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:DengXian;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"\@DengXian";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
span.apple-converted-space
{mso-style-name:apple-converted-space;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style></head><body lang=en-CN link="#0563C1" vlink="#954F72" style='word-wrap:break-word'><div class=WordSection1><p class=MsoNormal><span style='color:black'>Hi, ALL<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> I have something unclear about calling memset for array storage, the case is showing as below.<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> <o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>// cat test.c<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>void foo(int *p);<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>void test (int len) { <o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> int a[7];<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> for (int i = 0; i < len; i++) a[i] = 0;<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> foo(a); <o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>}<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> <o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>; Function Attrs: nounwind<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>define void @test(i32 signext %len) {<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>entry:<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> %a = alloca [7 x i32], align 4<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> %0 = bitcast [7 x i32]* %a to i8*<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> %cmp4 = icmp sgt i32 %len, 0<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> <o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>for.body.preheader: ; preds = %entry<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> %1 = zext i32 %len to i64<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> %2 = shl nuw nsw i64 %1, 2<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> call void @llvm.memset.p0i8.i64(i8* nonnull align 4 %0, i8 0, i64 %2, i1 false)<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> br label %for.cond.cleanup<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> <o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>for.cond.cleanup: ; preds = %for.body.preheader, %entry<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> %arraydecay = getelementptr inbounds [7 x i32], [7 x i32]* %a, i64 0, i64 0<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> call void @foo(i32* nonnull %arraydecay) #4<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'> ret void<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>}<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:black'>For such a case, I want to get the exact loop upper bound, but now there is no API to help. So I post a patch about to infer loop bound from array accesses. And a modified patch was posted after some review comments.<o:p></o:p></span></p><p class=MsoNormal><span style='color:black'>For the implementation details, please comment on this patch :<span class=apple-converted-space> </span></span><a href="https://reviews.llvm.org/D109821" title="https://reviews.llvm.org/D109821">https://reviews.llvm.org/D109821</a><o:p></o:p></p><p class=MsoNormal><span lang=EN-US>Any comment are precious to me, thank you all.<o:p></o:p></span></p></div></body></html>