<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/TR/REC-html40" 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"><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<TITLE>Message</TITLE>

<META content="MSHTML 6.00.6001.18023" name=GENERATOR>
<STYLE>@font-face {
        font-family: Cambria Math;
}
@font-face {
        font-family: Calibri;
}
@font-face {
        font-family: Tahoma;
}
@page Section1 {size: 612.0pt 792.0pt; margin: 72.0pt 72.0pt 72.0pt 72.0pt; }
P.MsoNormal {
        FONT-SIZE: 11pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Calibri","sans-serif"
}
LI.MsoNormal {
        FONT-SIZE: 11pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Calibri","sans-serif"
}
DIV.MsoNormal {
        FONT-SIZE: 11pt; MARGIN: 0cm 0cm 0pt; FONT-FAMILY: "Calibri","sans-serif"
}
A:link {
        COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlink {
        COLOR: blue; TEXT-DECORATION: underline; mso-style-priority: 99
}
A:visited {
        COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.MsoHyperlinkFollowed {
        COLOR: purple; TEXT-DECORATION: underline; mso-style-priority: 99
}
SPAN.EmailStyle17 {
        COLOR: windowtext; FONT-FAMILY: "Calibri","sans-serif"; mso-style-type: personal
}
SPAN.EmailStyle18 {
        COLOR: #1f497d; FONT-FAMILY: "Calibri","sans-serif"; mso-style-type: personal-reply
}
.MsoChpDefault {
        FONT-SIZE: 10pt; mso-style-type: export-only
}
DIV.Section1 {
        page: Section1
}
</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 vLink=purple link=blue>
<DIV><FONT face=Tahoma size=2></FONT> </DIV>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
  <DIV class=Section1>
  <P class=MsoNormal><SPAN style="COLOR: #1f497d">Hi Marc,<o:p></o:p></SPAN></P>
  <P class=MsoNormal><SPAN style="COLOR: #1f497d"><o:p> </o:p></SPAN></P>
  <P class=MsoNormal><SPAN style="COLOR: #1f497d">I’m a bit confused. Isn’t the 
  standard compare (i.e. the one for a language like C) an ordered one? I tried 
  converting some C code to LLVM C++ API code with the online demo, and it uses 
  FCMP_OEQ…<o:p></o:p></SPAN></P>
  <P class=MsoNormal><SPAN 
  style="COLOR: #1f497d"><o:p> </o:p></SPAN></P><SPAN 
  style="COLOR: #1f497d">
  <DIV><FONT face=Arial color=#0000ff size=2><SPAN class=287072516-27052008>No, 
  if you have:</SPAN></FONT></DIV>
  <DIV><SPAN class=287072516-27052008><FONT face=Arial color=#0000ff 
  size=2></FONT></SPAN> </DIV>
  <DIV><SPAN class=287072516-27052008><FONT face=Arial color=#0000ff 
  size=2>  x = NaN </FONT></SPAN></DIV>
  <DIV><SPAN class=287072516-27052008><FONT face=Arial color=#0000ff 
  size=2>  y = NaN</FONT></SPAN></DIV>
  <DIV><SPAN class=287072516-27052008><FONT face=Arial color=#0000ff 
  size=2></FONT></SPAN> </DIV>
  <DIV><SPAN class=287072516-27052008><FONT face=Arial color=#0000ff size=2>then 
  the comparison:</FONT></SPAN></DIV>
  <DIV><SPAN class=287072516-27052008><FONT face=Arial color=#0000ff 
  size=2>  (x == y) is false.</FONT></SPAN></DIV>
  <DIV><SPAN class=287072516-27052008><FONT face=Arial color=#0000ff 
  size=2></FONT></SPAN> </DIV>
  <DIV><SPAN class=287072516-27052008><FONT face=Arial color=#0000ff 
  size=2>Which is what your seeing from your first post and is the standard IEEE 
  expected behavior.</FONT></SPAN></DIV>
  <DIV><SPAN class=287072516-27052008><FONT face=Arial color=#0000ff 
  size=2></FONT></SPAN> </DIV>
  <DIV><SPAN class=287072516-27052008><FONT face=Arial color=#0000ff size=2>Why 
  I expected your min/max question to be related, consider the flags 
  of  'comiss, ucomiss, etc.' :</FONT></SPAN></DIV>
  <DIV><SPAN class=287072516-27052008><FONT face=Arial color=#0000ff 
  size=2>                            
  ZPC</FONT></SPAN></DIV>
  <DIV><SPAN class=287072516-27052008>    <FONT face=Arial 
  color=#0000ff 
  size=2>unordered          
  111</FONT></SPAN></DIV>
  <DIV><SPAN class=287072516-27052008>    <FONT face=Arial 
  color=#0000ff size=2>greater 
  than       000</FONT></SPAN></DIV>
  <DIV><SPAN class=287072516-27052008><FONT face=Arial color=#0000ff 
  size=2>    less 
  than           001</FONT></SPAN></DIV>
  <DIV><SPAN class=287072516-27052008><FONT face=Arial color=#0000ff 
  size=2>    
  equal                
  100</FONT></SPAN></DIV>
  <DIV><SPAN class=287072516-27052008><FONT face=Arial color=#0000ff 
  size=2></FONT></SPAN> </DIV>
  <DIV><SPAN class=287072516-27052008>
  <DIV><SPAN class=287072516-27052008><FONT face=Arial color=#0000ff size=2>Try 
  the following C program with gcc, first with no options and then with 
  --ffinite-math-only (or --ffast-math)</FONT></SPAN></DIV>
  <DIV></SPAN><SPAN class=287072516-27052008><FONT face=Arial color=#0000ff 
  size=2></FONT></SPAN> </DIV></DIV>
  <DIV><SPAN class=287072516-27052008><FONT face=Arial color=#0000ff 
  size=2>-----------</FONT></SPAN><SPAN class=287072516-27052008><BR><FONT 
  face=Arial color=#0000ff size=2>#define STR(X) #X<BR>#define CMP(X) if (X) { 
  printf(STR(X) " true\n"); } else { printf(STR(X) " false\n"); }</FONT></DIV>
  <DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
  <DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2>int main(int argc, 
  char** argv)<BR>{<BR>  float a = 0.f/0.f;<SPAN 
  class=287072516-27052008>   // generate a NaN </SPAN><BR>  
  float b = 1;<SPAN 
  class=287072516-27052008>         
  // any finite </SPAN></FONT></FONT></FONT></DIV>
  <DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
  <DIV><FONT face=Arial color=#0000ff size=2>  CMP(a!=a);<BR>  
  CMP(a==a);<BR>  CMP(a> b);<BR>  CMP(a>=b);<BR>  CMP(a< 
  b);<BR>  CMP(a<=b);<BR>  CMP(a!=b);</FONT></DIV>
  <DIV><FONT face=Arial color=#0000ff size=2></FONT> </DIV>
  <DIV><FONT face=Arial><FONT color=#0000ff><FONT size=2>  return 
  0;<BR>}<BR><SPAN 
  class=287072516-27052008>------------------------</SPAN></FONT></FONT></FONT></SPAN></DIV></SPAN>
  <P class=MsoNormal><SPAN style="COLOR: #1f497d"><o:p> </o:p></SPAN></P>
  <DIV>
  <DIV 
  style="BORDER-RIGHT: medium none; PADDING-RIGHT: 0cm; BORDER-TOP: #b5c4df 1pt solid; PADDING-LEFT: 0cm; PADDING-BOTTOM: 0cm; BORDER-LEFT: medium none; PADDING-TOP: 3pt; BORDER-BOTTOM: medium none">
  <P class=MsoNormal><B><SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'">From:</SPAN></B><SPAN 
  style="FONT-SIZE: 10pt; FONT-FAMILY: 'Tahoma','sans-serif'"> 
  llvmdev-bounces@cs.uiuc.edu [mailto:llvmdev-bounces@cs.uiuc.edu] <B>On Behalf 
  Of </B>Marc B. Reynolds<BR><B>Sent:</B> Tuesday, 27 May, 2008 
  14:07<BR><B>To:</B> 'LLVM Developers Mailing List'<BR><B>Subject:</B> Re: 
  [LLVMdev] Float compare-for-equality and select 
  optimizationopportunity<o:p></o:p></SPAN></P></DIV></DIV>
  <P class=MsoNormal><o:p> </o:p></P>
  <DIV>
  <P class=MsoNormal><SPAN 
  style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'">Both 
  ZF and PF will be set if unordered, so the code below is IEEE correct...you 
  want to generate 'fcmp ueq' instead of 'fcmp oqe'</SPAN><SPAN 
  style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman','serif'"><o:p></o:p></SPAN></P></DIV>
  <BLOCKQUOTE style="MARGIN-TOP: 5pt; MARGIN-BOTTOM: 5pt; MARGIN-RIGHT: 0cm">
    <P class=MsoNormal>This is the resulting x86 assembly code:<o:p></o:p></P>
    <P class=MsoNormal><o:p> </o:p></P>
    <P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">movss       
    xmm0,dword ptr [ecx+4] <o:p></o:p></SPAN></P>
    <P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN lang=NL-BE 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">ucomiss     
    xmm0,dword ptr [ecx+8] <o:p></o:p></SPAN></P>
    <P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN lang=NL-BE 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">sete        
    al   <o:p></o:p></SPAN></P>
    <P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">setnp       
    dl   <o:p></o:p></SPAN></P>
    <P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">test        
    dl,al <o:p></o:p></SPAN></P>
    <P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">mov         
    edx,edi <o:p></o:p></SPAN></P>
    <P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">cmovne      
    edx,ecx <o:p></o:p></SPAN></P>
    <P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">cmovne      
    ecx,esi <o:p></o:p></SPAN></P>
    <P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">cmovne      
    esi,edi</SPAN><o:p></o:p></P>
    <P class=MsoNormal><o:p> </o:p></P>
    <P class=MsoNormal>While I’m pleasantly surprised that my branch does get 
    turned into several select operations as intended (cmov - conditional move – 
    in x86), I’m confused why it uses the ucomiss instruction (unordered compare 
    and set flags). I only used IRBuilder::CreateFCmpOEQ. It also appears to 
    invert the conditional, for no clear reason. I think it could be rewritten 
    as follows:<o:p></o:p></P>
    <P class=MsoNormal><o:p> </o:p></P>
    <P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">movss       
    xmm0,dword ptr [ecx+4] <o:p></o:p></SPAN></P>
    <P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">comiss     
     xmm0,dword ptr [ecx+8] <o:p></o:p></SPAN></P>
    <P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">mov         
    edx,edi <o:p></o:p></SPAN></P>
    <P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">cmove      
     edx,ecx <o:p></o:p></SPAN></P>
    <P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">cmove      
     ecx,esi <o:p></o:p></SPAN></P>
    <P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">cmove      
     esi,edi</SPAN><o:p></o:p></P>
    <P class=MsoNormal><o:p> </o:p></P>
    <P class=MsoNormal>Compared to the original C syntax code this looks pretty 
    straightforward. Curiously, when I replace the compare-for-equality with 
    something like a less-than, it does generate such compact code (using <SPAN 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">comiss</SPAN> 
    and <SPAN 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">cmova</SPAN>). 
    And the not-equal case looks like this:<o:p></o:p></P>
    <P class=MsoNormal><o:p> </o:p></P>
    <P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">movss       
    xmm0,dword ptr [ecx+4] <o:p></o:p></SPAN></P>
    <P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">ucomiss     
    xmm0,dword ptr [ecx+8] <o:p></o:p></SPAN></P>
    <P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">mov         
    esi,ecx <o:p></o:p></SPAN></P>
    <P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">cmove       
    esi,edx <o:p></o:p></SPAN></P>
    <P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">cmovne      
    ecx,eax <o:p></o:p></SPAN></P>
    <P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN 
    style="FONT-SIZE: 8pt; COLOR: gray; FONT-FAMILY: 'Courier New'">cmove       
    edx,eax</SPAN><o:p></o:p></P>
    <P class=MsoNormal><o:p> </o:p></P>
    <P class=MsoNormal>So this generates compact code but with an unordered 
    compare.<o:p></o:p></P>
    <P class=MsoNormal><o:p> </o:p></P>
    <P class=MsoNormal>Anyway, it looks like the compare-for-equality case in 
    particular is missing an optimization opportunity. It’s no big deal to me 
    but I thought someone here might be interested…<o:p></o:p></P>
    <P class=MsoNormal><o:p> </o:p></P>
    <P class=MsoNormal>Cheers,<o:p></o:p></P>
    <P class=MsoNormal><o:p> </o:p></P>
    <P class=MsoNormal>Nicolas 
Capens<o:p></o:p></P></BLOCKQUOTE></DIV></BLOCKQUOTE></BODY></HTML>