http://llvm.org/bugs/show_bug.cgi?id=9661

           Summary: Missed optimization: unnecessary branching
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected]


This code:
float clamp_float(float a) {
        if (a > 1.0f)
                return 1.0f;
        else if (a < 0.0f)
                return 0.0f;
        else
                return a;
}

compiles to:

clamp_float:                            # @clamp_float
        movss   .LCPI0_0(%rip), %xmm1
        ucomiss %xmm1, %xmm0
        ja      .LBB0_2
        pxor    %xmm1, %xmm1
        maxss   %xmm0, %xmm1
.LBB0_2:                                # %return
        movaps  %xmm1, %xmm0
        ret


It should be able to be something like:
clamp_float:                            # @clamp_float
        movss   .LCPI0_0(%rip), %xmm1
        minss   %xmm1, %xmm0
        pxor    %xmm1, %xmm1
        maxss   %xmm1, %xmm0
        ret

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to