NOTE: I selected 5.5 but this problem is not dependent on the Unreal Engine version, instead specific to Clang compiler and its version 19 onward. Tested with 5 Main for the time being.
Say I insert some code like below into arbitrary UE runtime code.
{ static VectorRegister4Float v = MakeVectorRegisterFloat(4.0, -3.0, 2.0, -1.0f); auto f = [](VectorRegister4Float const& x) { return VectorAbs(x); }; static VectorRegister4Float a = f(v); printf("%f %f %f %f\n", VectorGetComponent(a, 0), VectorGetComponent(a, 1), VectorGetComponent(a, 2), VectorGetComponent(a, 3)); }
When compiled with Clang 19 for any supported SSE-enabled platform with FPSemanticsMode.Imprecise (hence with -ffast-math), I found that the runtime output may NOT be the correct absolute value. It can be zero or some broken float value.
This is due to the behavior change in Clang 19 as filed in this GitHub issue [[clang] -ffast-math in 19.1.0 prevents function from returning intended __m128 bitmask]([clang] -ffast-math in 19.1.0 prevents function from returning intended __m128 bitmask · Issue #118152 · llvm/llvm-project · GitHub) .
As discussed there, constant values used for bitwise intrinsics may be optimized out if is float NAN, despite them not intended for floating point interpretation. This affects numerous operation using constants defined in UnrealMathVectorConstants.h, including VectorAbs() which uses 0x7FFFFFFF.
Because the result depends on the optimizer’s interpretation, similar code may work in some case and not others, potentially causing a nasty sleeper bug.
Only viable/available/reliable workaround at the time of writing seems to be to add -fno-finite-math-only when -ffast-math is enabled, to make sure the compiler honor the non-finite values. With this option, the above code yielded correct results.
So I would like to suggest pairing of the -fno-finite-math-only to -ffast-math option in UBT for the time being.
Best Regards,