Open Quuxplusone opened 3 years ago
Call instructions are also not handled correctly:
#include <math.h>
#pragma float_control(precise, on)
float f(float x) {
return logf(x + 3.2f);
}
compiled with 'clang -O2 -ffast-math'
define dso_local float @f(float %0) local_unnamed_addr #0 {
%2 = fadd float %0, 0x40099999A0000000
%3 = tail call fast float @llvm.log.f32(float %2)
ret float %3
}
Notice the fadd instruction has no fast-math flags, but the call instruction does.
When pragmas are used that modify the fast-math flags, clang doesn't correctly apply the changes to all instructions. I've seen this with phi and fneg instructions. There may be others.
Here are some examples (compiled with -funsafe-math-optimizations, which applies 'reassoc nsz arcp' outside pragma scopes):
clang generates a phi instruction with the 'reassoc' flag set.
Here clang correctly omits the 'reassoc' flag from the fcmp but incorrectly sets it for the fneg.
Here clang correctly omits the 'reassoc' flag from the fsub but incorrectly sets it for the fneg.
The same problem occurs with "pragma float_control"