<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=koi8-r"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:Cambria;
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:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
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";
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:2.0cm 42.5pt 2.0cm 3.0cm;}
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=RU link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span lang=EN-US>Hello everyone.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>I’m not an expert neither in llvm nor in x86 nor in IEEE standard for floating point numbers, thus any of my following assumptions maybe wrong. If so, I will be grateful if you clarify me what’s goes wrong. But if my guesses are correct we possibly have a bug in fp arithmetics on x86.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>I have the following ir:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> </span><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'>@g = constant i64 1<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> define i32 @main() {<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> %gval = load i64* @g<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> %gvalfp = bitcast i64 %gval to double<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> %fmul = fmul double %gvalfp, -5.000000e-01<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> %fcmp = fcmp ueq double %fmul, -0.000000e+00<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> %ret = select i1 %fcmp, i32 1, i32 0<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> ret i32 %ret<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> }</span><span lang=EN-US style='font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>And I expected that minimal positive denormalized double times -0.5 is equal to -0.0, so correct exit code is 1.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>llvm-3.4.2 on x86 linux target produced the following assembly:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas'> <span style='background:silver;mso-highlight:silver'>.file "fpfail.ll"<o:p></o:p></span></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .section .rodata.cst8,"aM",@progbits,8<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .align 8<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'>.LCPI0_0:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .quad -4620693217682128896 # double -0.5<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'>.LCPI0_1:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .quad -9223372036854775808 # double -0<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .text<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .globl main<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .align 16, 0x90<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .type main,@function<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'>main: # @main<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .cfi_startproc<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'># BB#0:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> vmovsd g, %xmm0<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> vmulsd .LCPI0_0, %xmm0, %xmm0<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> vucomisd .LCPI0_1, %xmm0<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> sete %al<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> movzbl %al, %eax<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> ret<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'>.Ltmp0:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .size main, .Ltmp0-main<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .cfi_endproc<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .type g,@object # @g<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .section .rodata,"a",@progbits<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .globl g<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .align 8<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'>g:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .quad 1 # 0x1<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .size g, 8<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .section ".note.GNU-stack","",@progbits</span><span lang=EN-US style='font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas'>./llc -march=x86 fpfail.ll; g++ fpfail.s; ./a.out; echo $?<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Cambria","serif"'>returns 1 as expected.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Cambria","serif"'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Cambria","serif"'>But llvm-3.5 (on the same target) lowers the previous ir using floating point instructions in the following way.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas'> <span style='background:silver;mso-highlight:silver'>.text<o:p></o:p></span></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .file "fpfail.ll"<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .section .rodata.cst4,"aM",@progbits,4<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .align 4<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'>.LCPI0_0:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .long 3204448256 # float -0.5<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .text<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .globl main<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .align 16, 0x90<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .type main,@function<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'>main: # @main<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .cfi_startproc<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'># BB#0:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> fldl g<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> fmuls .LCPI0_0<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> fldz<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> fchs<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> fxch %st(1)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> fucompp<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> fnstsw %ax<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> # kill: AX<def> AX<kill> EAX<def><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> # kill: AH<def> AH<kill> EAX<kill><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> sahf<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> sete %al<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> movzbl %al, %eax<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> retl<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'>.Ltmp0:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .size main, .Ltmp0-main<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .cfi_endproc<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .type g,@object # @g<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .section .rodata,"a",@progbits<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .globl g<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .align 8<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'>g:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .quad 1 # 0x1<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .size g, 8<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas;background:silver;mso-highlight:silver'> .section ".note.GNU-stack","",@progbits</span><span lang=EN-US style='font-family:Consolas'><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Cambria","serif"'>First, it doesn’t assemble with g++ (4.8):<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas'>fpfail.s:26: Error: invalid instruction suffix for `ret'<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Cambria","serif"'>I downloaded Intel manual and haven’t found any mention of retl instruction, so I manually exchanged it with ret and reassemble:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:Consolas'>g++ fpfail.s; ./a.out; echo $?<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-family:"Cambria","serif"'>The exit code is 0. This is correct for Intel 80-bit floats but wrong for doubles. What am I do wrong or this is actually a bug or even worse – correct behavior?<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal>--<o:p></o:p></p><p class=MsoNormal><span lang=EN-US style='mso-fareast-language:RU'>Kind regards, Dmitry Borisenkov<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>