<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)"><!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><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;
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:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
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" style='word-wrap:break-word'><div class=WordSection1><p class=MsoNormal>Undef means it can take any value (except poison). Therefore LLVM replaces phi(undef, %x) with %x, as it can fix the value of undef. This is optimization is common and it<span style='font-family:"Times New Roman",serif'>’</span>s not architecture dependent.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>This optimization is actually *<b>wrong</b>* in case %x is poison, as then we are replacing undef with poison for one of the predecessors (which is not correct). But LLVM is still inconsistent in the treatment of undef and we can<span style='font-family:"Times New Roman",serif'>’</span>t fix it straight away.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Nuno<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b>From:</b> Charitha Saumya<br><b>Sent:</b> 15 August 2021 02:53<br><b>To:</b> via Llvm-dev <llvm-dev@lists.llvm.org><br><b>Subject:</b> [llvm-dev] Semantics of udef values in PHI instructions<o:p></o:p></p></div><p class=MsoNormal><o:p> </o:p></p><div><div><div><div><div><div><div><p class=MsoNormal><span style='font-family:"Times New Roman",serif'>Hi,</span><o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><span style='font-family:"Times New Roman",serif'>Consider the following LLVM IR snippet. (also attached)</span><o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><span style='font-family:"Times New Roman",serif'>the value of %unify.phi is undefined if the loop body (while.body9) is executed, otherwise it has some specific value (%c.1 is a defined value).</span><o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><span style='font-family:"Times New Roman",serif'>However when I execute this IR (using lli), the value of %c.2 is always the value of %c.1, even if the loop is executed multiple times.</span><o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><span style='font-family:"Times New Roman",serif'>What is the reason for this behavior? how undefined values are handled in LLVM and is this behaviour architecture dependent (depending on how undef is handled in Codegen) ?</span><o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><span style='font-family:"Times New Roman",serif'>Thanks</span><o:p></o:p></p></div><div><p class=MsoNormal><span style='font-family:"Times New Roman",serif'>Charitha</span><o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal><img width=563 height=479 style='width:5.868in;height:4.9861in' id="Picture_x0020_1" src="cid:image002.png@01D79291.91F51430"><o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div></div></div></div></div></div></div></div></body></html>