https://bugs.llvm.org/show_bug.cgi?id=43847
Bug ID: 43847
Summary: narrow truncated FP math with 'reassoc' fast-math-flag
FMF
Product: libraries
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: Scalar Optimizations
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected]
Forking this off from the non-FMF example in bug 43841 - it's the same source
code:
float fmaf(float x, float y, float z) {
return (((double)x * (double)y) + (double)z);
}
But let's compile with a flag that gives us wide license to rearrange
floating-point math:
$ clang -O2 fma2.c -S -o - -emit-llvm -funsafe-math-optimizations
define float @fmaf(float %x, float %y, float %z) {
%conv = fpext float %x to double
%conv1 = fpext float %y to double
%mul = fmul reassoc nsz arcp double %conv, %conv1
%conv2 = fpext float %z to double
%add = fadd reassoc nsz arcp double %mul, %conv2
%conv3 = fptrunc double %add to float
ret float %conv3
}
------------------------------------------------------------------------------
We should be able to remove all of the cast ops (fptrunc/fpext) in this IR and
narrow the math ops (fmul/fadd) to float type. Related transforms are already
implemented in InstCombine.
Notes:
1. "-funsafe-math-optimizations" translates to "reassoc nsz arcp" in IR. We
only care about "reassoc" in this example, but we don't seem to have the clang
flag for that wired up.
2. We're moving to a fast-math-flags model where all FP values can carry FMF.
But this example shows that we can not or do not apply the flags to the cast
instructions yet.
3. Ideally, we will implement #2 to allow pattern-matching from the trailing
"fptrunc", but even without that, we could allow this fold:
fmul reassoc (fpext X), (fpext Y) --> fpext (fmul X, Y)
--
You are receiving this mail because:
You are on the CC list for the bug._______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs