<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=us-ascii">
<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;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        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;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 2.0cm 70.85pt;}
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"><span lang="DE">Hi,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="DE"><o:p> </o:p></span></p>
<p class="MsoNormal">I try to understand why llvm can’t optimize this small piece of code.
<o:p></o:p></p>
<p class="MsoNormal">My expectation is that the IR will be optimized to a “ ret i64 2101545.<o:p></o:p></p>
<p class="MsoNormal">But somehow the alias analysis fails when the pointer is casted to an integer value,<o:p></o:p></p>
<p class="MsoNormal">so the dead code eliminator can’t optimize it away.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Could someone explain to me why this is failing and if there is a solution for that ?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I can trick the alias analysis by setting %5 to a concrete integer so the code can be optimized further,<o:p></o:p></p>
<p class="MsoNormal">but I’m still wondering why llvm can’t do it.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
<p class="MsoNormal">Peter<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">define dso_local i64 @func(i64, i64, i64) local_unnamed_addr #0 {<o:p></o:p></p>
<p class="MsoNormal">.split:<o:p></o:p></p>
<p class="MsoNormal">  %3 = alloca [100 x i64], align 16<o:p></o:p></p>
<p class="MsoNormal">  %4 = getelementptr inbounds [100 x i64], [100 x i64]* %3, i64 0, i64 2<o:p></o:p></p>
<p class="MsoNormal">  %5 = ptrtoint i64* %4 to i64<o:p></o:p></p>
<p class="MsoNormal">  %6 = add i64 %5, -8<o:p></o:p></p>
<p class="MsoNormal">  %7 = inttoptr i64 %6 to i64*<o:p></o:p></p>
<p class="MsoNormal">  store i64 0, i64* %7, align 8<o:p></o:p></p>
<p class="MsoNormal">  %8 = add i64 %5, -12<o:p></o:p></p>
<p class="MsoNormal">  %9 = inttoptr i64 %8 to i32*<o:p></o:p></p>
<p class="MsoNormal">  store i32 0, i32* %9, align 4<o:p></o:p></p>
<p class="MsoNormal">  %10 = add i64 %5, -16<o:p></o:p></p>
<p class="MsoNormal">  %11 = inttoptr i64 %10 to i32*<o:p></o:p></p>
<p class="MsoNormal">  store i32 0, i32* %11, align 16<o:p></o:p></p>
<p class="MsoNormal">  <span lang="DE">ret i64 2101545<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="DE">}<o:p></o:p></span></p>
</div>
<hr>
<span lang="EN-US" style="font-style:italic;font-size:10.0pt;font-family:
"Arial","sans-serif";color:maroon;mso-ansi-language:EN-US">This message and any attachments are intended solely for the addressees and may contain confidential information. Any unauthorized
 use or disclosure, either whole or partial, is prohibited.<br>
E-mails are susceptible to alteration. Our company shall not be liable for the message if altered, changed or falsified. If you are not the intended recipient of this message, please delete it and notify the sender.<br>
Although all reasonable efforts have been made to keep this transmission free from viruses, the sender will not be liable for damages caused by a transmitted virus.</span>
</body>
</html>