[LLVMbugs] [Bug 12559] New: Optimizer reduces (float)sqrt and (float)floor to sqrtf and floorf, which aren't functions in i386-*-win32 C runtime

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat Apr 14 13:47:05 PDT 2012


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

             Bug #: 12559
           Summary: Optimizer reduces (float)sqrt and (float)floor to
                    sqrtf and floorf, which aren't functions in
                    i386-*-win32 C runtime
           Product: new-bugs
           Version: 3.0
          Platform: PC
        OS/Version: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: arcata at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


This IR:

---
target triple = "i386-pc-win32"

declare double @floor(double %x)
declare double @sqrt(double %x)

define float @float_sqrt(float %x) nounwind readnone {
    %1 = fpext float %x to double
    %2 = call double @sqrt(double %1)
    %3 = fptrunc double %2 to float
    ret float %3
}

define float @float_floor(float %x) nounwind readnone {
    %1 = fpext float %x to double
    %2 = call double @floor(double %1)
    %3 = fptrunc double %2 to float
    ret float %3
}
---

gets transformed by "opt -O2 -S" into:

---
; ModuleID = '<stdin>'
target triple = "i386-pc-win32"

define float @float_sqrt(float %x) nounwind readnone {
  %1 = tail call float @sqrtf(float %x) nounwind
  ret float %1
}

define float @float_floor(float %x) nounwind readnone {
  %floorf = tail call float @floorf(float %x) nounwind
  ret float %floorf
}

declare float @sqrtf(float)

declare float @floorf(float)
---

This transformation is not valid on i386-*-win32, because sqrtf and floorf are
not real entry points in MSVCRT. MSVC's standard C library implements sqrtf and
floorf (and most other float versions of math functions) as macros over the
double versions for x86-32. (However, on x86_64-*-win32 and *-*-mingw32, the
float math functions are true entry points in the CRT.) Optimizing with
-disable-simplify-libcalls suppresses the optimization of 'floor' but does not
suppress the optimization of 'sqrt'.

-- 
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.



More information about the llvm-bugs mailing list