[llvm-bugs] [Bug 51276] New: -Wdouble-promotion warning falsely emitted when floating point literals are not actually promoted to doubles

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jul 29 14:54:22 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=51276

            Bug ID: 51276
           Summary: -Wdouble-promotion warning falsely emitted when
                    floating point literals are not actually promoted to
                    doubles
           Product: clang
           Version: 11.0
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: make_all at t-online.de
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

Clang emits a double promotion warning when using the literal 0.5 with a float
and optimization turned on.

For example:

float func(float num) {
    return num * 0.5;
}


warning: implicit conversion increases floating-point precision: 'float' to
'double' [-Wdouble-promotion]
    return num * 0.5;

However, if optimization is turned on (-Os, -O1 and above), Clang does not
actually use the double representation for this literal (and others than can be
represented equally in float as in double).
The assembler output for both "0.5" and "0.5f" is the same:


.LCPI0_0:
        .long   1056964608              # float 0.5
func(float):                               # @func(float)
        mulss   xmm0, dword ptr [rip + .LCPI0_0]
        ret


One of the most relevant scopes for -Wdouble-promotion is probably optimization
(in particular for SIMD), where the unintended use of a double would cause a
significant performance hit. 
If the compiler is smart enough and is not using doubles and double
instructions, and no precision is changed anywhere in the process, it should be
smart enough to not throw a this warning.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210729/9936b735/attachment.html>


More information about the llvm-bugs mailing list