<html xmlns:v="urn:schemas-microsoft-com:vml" 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:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal">It probably thinks that the call to fprintf can clobber memory.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-size:9.0pt;font-family:Consolas">-- </span>
<span style="font-size:9.0pt;font-family:Consolas"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:8.0pt;font-family:Consolas">Krzysztof Parzyszek 
<a href="mailto:kparzysz@quicinc.com"><span style="color:#0563C1">kparzysz@quicinc.com</span></a>   LLVM compiler development<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b>From:</b> llvm-dev <llvm-dev-bounces@lists.llvm.org> <b>On Behalf Of
</b>Fami H via llvm-dev<br>
<b>Sent:</b> Thursday, March 28, 2019 9:17 AM<br>
<b>To:</b> llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> [EXT] [llvm-dev] Why does LLVM keep some loads in the loops even after applying the O3 optimization?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt">Hello all,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt">I am looking at the assembly code of a loop body which is created by applying O3 optimization. Here it is: <br>
<br>
.LBB4_19:                               @ %for.body.91 <br>
                                        @ =>This Inner Loop Header: Depth=1 <br>
        ldr r0, [r5] <br>
        mov r1, r8 <br>
        add r0, r0, r7 <br>
        vldr s0, [r0] <br>
        mov r0, r6 <br>
        vcvt.f64.f32 d0, s0 <br>
        vmov r2, r3, d0 <br>
        bl fprintf <br>
        cmp r0, #0 <br>
        blt .LBB4_25 <br>
@ BB#20:                                @ %for.cond.89 <br>
                                        @   in Loop: Header=BB4_19 Depth=1 <br>
        ldr r0, .LCPI4_2 <br>
        add r4, r4, #1 <br>
        add r7, r7, #4 <br>
        ldr r0, [r0] <br>
        cmp r4, r0 <br>
        blt .LBB4_19 <br>
<br>
There are no other basic blocks in the loop.  I am wondering why the first load instruction (ldr r0, [r5]) is repeatedly executed in the loop while the load address (r5) is never changed in the loop body. Shouldn't this instruction be moved out of the loop
 as a result of -licm flag? I mean this load could have been executed only once outside of the loop and the result could have been saved in the register and used in the loop. I'd greatly appreciate if anyone can tell me why this is not the case. <br>
<br>
Thank you in advance, <br>
Fami <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:12.0pt"> <o:p></o:p></span></p>
</div>
</div>
</div>
</body>
</html>