diff options
| author | Bill Wendling <isanbard@gmail.com> | 2010-03-05 00:24:26 +0000 | 
|---|---|---|
| committer | Bill Wendling <isanbard@gmail.com> | 2010-03-05 00:24:26 +0000 | 
| commit | 37b52ee6d9141293c9aef0d2a4c753300a687536 (patch) | |
| tree | 34077edffbd28f8f34b799b41535c379b342c9c0 /test | |
| parent | b0812f114b83a32c4b90a4b553c7177c557558b5 (diff) | |
| download | external_llvm-37b52ee6d9141293c9aef0d2a4c753300a687536.zip external_llvm-37b52ee6d9141293c9aef0d2a4c753300a687536.tar.gz external_llvm-37b52ee6d9141293c9aef0d2a4c753300a687536.tar.bz2 | |
Micro-optimization:
This code:
float floatingPointComparison(float x, float y) {
    double product = (double)x * y;
    if (product == 0.0)
        return product;
    return product - 1.0;
}
produces this:
_floatingPointComparison:
0000000000000000        cvtss2sd        %xmm1,%xmm1
0000000000000004        cvtss2sd        %xmm0,%xmm0
0000000000000008        mulsd           %xmm1,%xmm0
000000000000000c        pxor            %xmm1,%xmm1
0000000000000010        ucomisd         %xmm1,%xmm0
0000000000000014        jne             0x00000004
0000000000000016        jp              0x00000002
0000000000000018        jmp             0x00000008
000000000000001a        addsd           0x00000006(%rip),%xmm0
0000000000000022        cvtsd2ss        %xmm0,%xmm0
0000000000000026        ret
The "jne/jp/jmp" sequence can be reduced to this instead:
_floatingPointComparison:
0000000000000000        cvtss2sd        %xmm1,%xmm1
0000000000000004        cvtss2sd        %xmm0,%xmm0
0000000000000008        mulsd           %xmm1,%xmm0
000000000000000c        pxor            %xmm1,%xmm1
0000000000000010        ucomisd         %xmm1,%xmm0
0000000000000014        jp              0x00000002
0000000000000016        je              0x00000008
0000000000000018        addsd           0x00000006(%rip),%xmm0
0000000000000020        cvtsd2ss        %xmm0,%xmm0
0000000000000024        ret
for a savings of 2 bytes.
This xform can happen when we recognize that jne and jp jump to the same "true"
MBB, the unconditional jump would jump to the "false" MBB, and the "true" branch
is the fall-through MBB.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@97766 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
| -rw-r--r-- | test/CodeGen/X86/jump-opt.ll | 22 | 
1 files changed, 22 insertions, 0 deletions
| diff --git a/test/CodeGen/X86/jump-opt.ll b/test/CodeGen/X86/jump-opt.ll new file mode 100644 index 0000000..dc32f66 --- /dev/null +++ b/test/CodeGen/X86/jump-opt.ll @@ -0,0 +1,22 @@ +; RUN: llc < %s -mtriple=i386-apple-darwin10 | FileCheck %s + +; <rdar://problem/7598384> +define float @test1(float %x, float %y) nounwind readnone optsize ssp { +; CHECK:      jp +; CHECK-NEXT: je +entry: +  %0 = fpext float %x to double +  %1 = fpext float %y to double +  %2 = fmul double %0, %1 +  %3 = fcmp oeq double %2, 0.000000e+00 +  br i1 %3, label %bb2, label %bb1 + +bb1: +  %4 = fadd double %2, -1.000000e+00 +  br label %bb2 + +bb2: +  %.0.in = phi double [ %4, %bb1 ], [ %2, %entry ] +  %.0 = fptrunc double %.0.in to float +  ret float %.0 +} | 
