<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - -Wdouble-promotion warning falsely emitted when floating point literals are not actually promoted to doubles"
   href="https://bugs.llvm.org/show_bug.cgi?id=51276">51276</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>-Wdouble-promotion warning falsely emitted when floating point literals are not actually promoted to doubles
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>11.0
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>make_all@t-online.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>