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: unassignedclangb...@nondot.org
Reporter: make_...@t-online.de
CC: blitzrak...@gmail.com, dgre...@apple.com,
erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
richard-l...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs