<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;}
@font-face
        {font-family:"Segoe UI Symbol";
        panose-1:2 11 5 2 4 2 4 2 2 3;}
/* 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;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
        {mso-style-priority:99;
        mso-style-link:"Plain Text Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.PlainTextChar
        {mso-style-name:"Plain Text Char";
        mso-style-priority:99;
        mso-style-link:"Plain Text";
        font-family:"Calibri",sans-serif;}
.MsoChpDefault
        {mso-style-type:export-only;}
@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"><div class=WordSection1><p class=MsoPlainText>Hi,<o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>Let me try to give a bit more context on why select is so tricky.<o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>First thing to consider is which transformations we would like to support:<o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText><u>1) Control-flow -> select (SimplifyCFG)<o:p></o:p></u></p><p class=MsoPlainText><span style='font-size:10.0pt;font-family:Consolas'>if (c)<o:p></o:p></span></p><p class=MsoPlainText><span style='font-size:10.0pt;font-family:Consolas'> a = x<o:p></o:p></span></p><p class=MsoPlainText><span style='font-size:10.0pt;font-family:Consolas'>else<o:p></o:p></span></p><p class=MsoPlainText><span style='font-size:10.0pt;font-family:Consolas'> a = y<o:p></o:p></span></p><p class=MsoPlainText><span style='font-size:10.0pt;font-family:Consolas'><o:p> </o:p></span></p><p class=MsoPlainText><span style='font-size:10.0pt;font-family:Consolas'>  =><o:p></o:p></span></p><p class=MsoPlainText><span style='font-size:10.0pt;font-family:Consolas'>%a = select %c, %x, %y<o:p></o:p></span></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText><u>2) select -> control-flow</u>; reverse of 1)<o:p></o:p></p><p class=MsoPlainText>Not sure if this is done at IR level, or only later at SDAG.<o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText><u>3) select -> arithmetic<o:p></o:p></u></p><p class=MsoPlainText><span style='font-size:10.0pt;font-family:Consolas'>%a = select %c, true, %y<o:p></o:p></span></p><p class=MsoPlainText><span style='font-size:10.0pt;font-family:Consolas'>  =><o:p></o:p></span></p><p class=MsoPlainText><span style='font-size:10.0pt;font-family:Consolas'>%a = or %c, %y<o:p></o:p></span></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText><u>4) select removal<o:p></o:p></u></p><p class=MsoPlainText><span style='font-size:10.0pt;font-family:Consolas'>%c = icmp eq %x, C<o:p></o:p></span></p><p class=MsoPlainText><span style='font-size:10.0pt;font-family:Consolas'>%r = select %c, C, %x<o:p></o:p></span></p><p class=MsoPlainText><span style='font-size:10.0pt;font-family:Consolas'>  =><o:p></o:p></span></p><p class=MsoPlainText><span style='font-size:10.0pt;font-family:Consolas'>%r = %x<o:p></o:p></span></p><p class=MsoPlainText><span lang=PT><o:p> </o:p></span></p><p class=MsoPlainText><span lang=PT><o:p> </o:p></span></p><p class=MsoPlainText><u><span lang=PT>5) select hoisting past binops<o:p></o:p></span></u></p><p class=MsoPlainText><span style='font-size:10.0pt;font-family:Consolas'>%a = udiv %x, %y<o:p></o:p></span></p><p class=MsoPlainText><span style='font-size:10.0pt;font-family:Consolas'>%b = udiv %x, %z<o:p></o:p></span></p><p class=MsoPlainText><span style='font-size:10.0pt;font-family:Consolas'>%r = select %c, %a, %b<o:p></o:p></span></p><p class=MsoPlainText><span style='font-size:10.0pt;font-family:Consolas'>  =><o:p></o:p></span></p><p class=MsoPlainText><span style='font-size:10.0pt;font-family:Consolas'>%t = select %c, %y, %z<o:p></o:p></span></p><p class=MsoPlainText><span style='font-size:10.0pt;font-family:Consolas'>%r = udiv %x, %t<o:p></o:p></span></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText><u>6) Bonus: easy to move</u> select instructions around. Should be possible to hoist selects out of loops easily.<o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>Ideally we want semantics for select that allow all transformations 1-6. It's hard because:<o:p></o:p></p><p class=MsoPlainText>1) %a can only be poison conditionally on %c, i.e., %a is poison if %c=true and %x is poison, or %c=false and %y is poison<o:p></o:p></p><p class=MsoPlainText>2) since we introduce a branch on %c, select on poison has to be UB like branch on poison<o:p></o:p></p><p class=MsoPlainText>3) with arithmetic all operands are always evaluated, so conditional poison like in 1) doesn’t work<o:p></o:p></p><p class=MsoPlainText>4) the example provided replaces C with %x in case %x=C. C is never poison, but %x might be.<o:p></o:p></p><p class=MsoPlainText>5) We cannot introduce a division by poison if %y and %z are not poison<o:p></o:p></p><p class=MsoPlainText>6) Making select trigger UB for some cases makes movement harder because then we need to prove that it won’t trigger UB before e.g. hoisting it out of loops.<o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>Summary table of what each transformation allows for %z = select %c, %x, %y. Each column is a different alternative of semantics for select:<o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><table class=MsoTableGrid border=1 cellspacing=0 cellpadding=0 style='border-collapse:collapse;border:none'><tr><td width=141 valign=top style='width:105.95pt;border:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText><o:p> </o:p></p></td><td width=108 valign=top style='width:81.05pt;border:solid windowtext 1.0pt;border-left:none;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText>UB if %c poison<o:p></o:p></p><p class=MsoPlainText>+ conditional poison<o:p></o:p></p></td><td width=128 valign=top style='width:96.1pt;border:solid windowtext 1.0pt;border-left:none;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText>UB if %c poison + poison if either<br>%x/%y poison<o:p></o:p></p></td><td width=128 valign=top style='width:96.1pt;border:solid windowtext 1.0pt;border-left:none;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText>Conditional poison<o:p></o:p></p><p class=MsoPlainText> + non-det choice if %c poison<o:p></o:p></p></td><td width=132 valign=top style='width:99.25pt;border:solid windowtext 1.0pt;border-left:none;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText>Conditional poison + poison if %c poison**<o:p></o:p></p></td><td width=151 valign=top style='width:4.0cm;border:solid windowtext 1.0pt;border-left:none;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText>Poison if any of<br>%c/%x/%y are poison<o:p></o:p></p></td></tr><tr><td width=141 valign=top style='width:105.95pt;border:solid windowtext 1.0pt;border-top:none;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText>SimplifyCFG<o:p></o:p></p></td><td width=108 valign=top style='width:81.05pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><span style='font-family:"Segoe UI Symbol",sans-serif'>✓</span><o:p></o:p></p></td><td width=128 valign=top style='width:96.1pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><o:p> </o:p></p></td><td width=128 valign=top style='width:96.1pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><span style='font-family:"Segoe UI Symbol",sans-serif'>✓</span><o:p></o:p></p></td><td width=132 valign=top style='width:99.25pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><span style='font-family:"Segoe UI Symbol",sans-serif'>✓</span><o:p></o:p></p></td><td width=151 valign=top style='width:4.0cm;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><o:p> </o:p></p></td></tr><tr><td width=141 valign=top style='width:105.95pt;border:solid windowtext 1.0pt;border-top:none;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText>Select->control-flow<o:p></o:p></p></td><td width=108 valign=top style='width:81.05pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><span style='font-family:"Segoe UI Symbol",sans-serif'>✓</span><o:p></o:p></p></td><td width=128 valign=top style='width:96.1pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><span style='font-family:"Segoe UI Symbol",sans-serif'>✓</span><o:p></o:p></p></td><td width=128 valign=top style='width:96.1pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><o:p> </o:p></p></td><td width=132 valign=top style='width:99.25pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><o:p> </o:p></p></td><td width=151 valign=top style='width:4.0cm;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><o:p> </o:p></p></td></tr><tr><td width=141 valign=top style='width:105.95pt;border:solid windowtext 1.0pt;border-top:none;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText>Select->arithmetic<o:p></o:p></p></td><td width=108 valign=top style='width:81.05pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><o:p> </o:p></p></td><td width=128 valign=top style='width:96.1pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><span style='font-family:"Segoe UI Symbol",sans-serif'>✓</span><o:p></o:p></p></td><td width=128 valign=top style='width:96.1pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><o:p> </o:p></p></td><td width=132 valign=top style='width:99.25pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><o:p> </o:p></p></td><td width=151 valign=top style='width:4.0cm;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><span style='font-family:"Segoe UI Symbol",sans-serif'>✓</span><o:p></o:p></p></td></tr><tr><td width=141 valign=top style='width:105.95pt;border:solid windowtext 1.0pt;border-top:none;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText>Select removal<o:p></o:p></p></td><td width=108 valign=top style='width:81.05pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><span style='font-family:"Segoe UI Symbol",sans-serif'>✓</span><o:p></o:p></p></td><td width=128 valign=top style='width:96.1pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><span style='font-family:"Segoe UI Symbol",sans-serif'>✓</span><o:p></o:p></p></td><td width=128 valign=top style='width:96.1pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><o:p> </o:p></p></td><td width=132 valign=top style='width:99.25pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><span style='font-family:"Segoe UI Symbol",sans-serif'>✓</span><o:p></o:p></p></td><td width=151 valign=top style='width:4.0cm;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><span style='font-family:"Segoe UI Symbol",sans-serif'>✓</span><o:p></o:p></p></td></tr><tr><td width=141 valign=top style='width:105.95pt;border:solid windowtext 1.0pt;border-top:none;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText>Select hoist<o:p></o:p></p></td><td width=108 valign=top style='width:81.05pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><span style='font-family:"Segoe UI Symbol",sans-serif'>✓</span><o:p></o:p></p></td><td width=128 valign=top style='width:96.1pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><span style='font-family:"Segoe UI Symbol",sans-serif'>✓</span><o:p></o:p></p></td><td width=128 valign=top style='width:96.1pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><span style='font-family:"Segoe UI Symbol",sans-serif'>✓</span><o:p></o:p></p></td><td width=132 valign=top style='width:99.25pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><o:p> </o:p></p></td><td width=151 valign=top style='width:4.0cm;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><o:p> </o:p></p></td></tr><tr><td width=141 valign=top style='width:105.95pt;border:solid windowtext 1.0pt;border-top:none;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText>Easy movement<o:p></o:p></p></td><td width=108 valign=top style='width:81.05pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><o:p> </o:p></p></td><td width=128 valign=top style='width:96.1pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><o:p> </o:p></p></td><td width=128 valign=top style='width:96.1pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><span style='font-family:"Segoe UI Symbol",sans-serif'>✓</span><o:p></o:p></p></td><td width=132 valign=top style='width:99.25pt;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><span style='font-family:"Segoe UI Symbol",sans-serif'>✓</span><o:p></o:p></p></td><td width=151 valign=top style='width:4.0cm;border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 5.4pt 0cm 5.4pt'><p class=MsoPlainText align=center style='text-align:center'><span style='font-family:"Segoe UI Symbol",sans-serif'>✓</span><o:p></o:p></p></td></tr></table><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>Modulo bugs in the table, you can see there’s no single column with all rows with a <span style='font-family:"Segoe UI Symbol",sans-serif'>✓</span>.  That means there’s no way (that I’m aware of) to make all transformations that we are interested in doing to be correct.  A solution is to introduce something like the freeze instruction that can land a <span style='font-family:"Segoe UI Symbol",sans-serif'>✓</span> on any cell you want.<o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>So unless someone has a clever idea and proposes a new column that has ticks in all rows, we are left with picking a trade-off: either we disable some optimizations, or we introduce something like freeze to continue doing them.<o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>BTW, this table assumes that branch on poison is UB, otherwise optimizations like GVN are wrong (for more details see our paper: <a href="http://www.cs.utah.edu/~regehr/papers/undef-pldi17.pdf">http://www.cs.utah.edu/~regehr/papers/undef-pldi17.pdf</a>). The column marked with ** is the one that Alive currently implements.<o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>Regarding SDAG: it has undef, and I believe there was some discussion regarding introducing poison there as well. I don’t recall if it was introduce already, but I believe there’s already nsw/nuw there. If that’s the case, the (il)legality of transformations should be exactly the same as in LLVM IR.  Otherwise some transformations may be easier.<o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>Sorry for the longish email; just wanted to give some background about the problem so that we can reach some consensus at some point.<o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>Nuno<o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>-----Original Message-----<br>From: John Regehr<br>Sent: 22 de maio de 2017 21:45<br>Subject: Re: [poison] is select-of-select to logic+select allowed?</p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>Nuno and I have been looking through the results of experiments like the one reported here:<o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>   <a href="https://blog.regehr.org/archives/1510"><span style='color:windowtext;text-decoration:none'>https://blog.regehr.org/archives/1510</span></a><o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>Indeed there are some select-related transformations in LLVM that are illegal in terms of Alive's semantics. As far as we know, they cannot be made legal (by adjusting the semantics of instructions) without breaking a bunch of other optimizations.<o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>The optimizations currently in LLVM are not only inconsistent but they can lead to end-to-end miscompilations. Sorting this out is going to require (1) figuring out what select means WRT poison/undef and (2) backing out some optimizations. This is going to be slightly painful but it is the only way forward.<o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>John<o:p></o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText><o:p> </o:p></p><p class=MsoPlainText>On 5/22/17 2:32 PM, Sanjay Patel wrote:<o:p></o:p></p><p class=MsoPlainText>> Some InstCombine transforms for select-of-select were added here:<o:p></o:p></p><p class=MsoPlainText>> <a href="https://reviews.llvm.org/rL228409"><span style='color:windowtext;text-decoration:none'>https://reviews.llvm.org/rL228409</span></a><o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> But Alive says this is more poisonous:<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> Name: selsel<o:p></o:p></p><p class=MsoPlainText>> %s1 = select i1 %cond1, i8 C1, i8 C2<o:p></o:p></p><p class=MsoPlainText>> %s2 = select i1 %cond2, i8 %s1, i8 C2<o:p></o:p></p><p class=MsoPlainText>>   =><o:p></o:p></p><p class=MsoPlainText>> %andcond = and i1 %cond1, %cond2<o:p></o:p></p><p class=MsoPlainText>> %s2 = select i1 %andcond, i8 C1, i8 C2<o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> <a href="http://rise4fun.com/Alive/JT6"><span style='color:windowtext;text-decoration:none'>http://rise4fun.com/Alive/JT6</span></a><o:p></o:p></p><p class=MsoPlainText>><o:p> </o:p></p><p class=MsoPlainText>> Are those transforms legal?<o:p></o:p></p></div></body></html>