HI,
Background and Motivation
In the MIPS architecture, there are two modes for encoding floating-point NaN (Not a Number):
· legacy mode: Traditional NaN encoding, where the quiet bit position differs from IEEE 754-2008.
· 2008 mode: NaN encoding compliant with the IEEE 754-2008 standard.
LLVM/Clang currently uses the -mnan=legacy and -mnan=2008 options to specify which NaN encoding to use. However, support for -mnan=legacy is incomplete in the actual codebase, leading to bugs (e.g., #100495) and inconsistencies.
Key points from recent reviews highlight the problem:
· RKSimon: “It is not acceptable to have target specific code like this in the generic DAG combines.”
· arsenm: “LLVM as a whole does not support the legacy mips nan encoding… We should probably just turn the flag into an error; it would be a huge undertaking to actually support it correctly”
· nikic: “What you do here is going to be a very partial solution, because we have tons of code that assumes IEEE NaNs… We should probably also consider making -mnan=legacy an error and stop pretending that we support it.”
Detailed Design
· Case A (Architecture supports nan2008): For CPUs/architectures that support the IEEE 754-2008 NaN encoding (e.g., mips32r2, mips64r2 and later), the -mnan=legacy option is silently converted to -mnan=2008. A warning is emitted: warning: ignoring unsupported ‘-mnan=legacy’ option and instead set to ‘-mnan=2008’ because the ‘%0’ architecture supports it.
· Case B (Architecture does NOT support nan2008): For older architectures (e.g., mips1, mips32, mips64), the -mnan=legacy option is ignored. A warning is emitted: warning: ignoring ‘-mnan=legacy’ option because the ‘%0’ architecture does not support it.
Discussion Points
Does the community agree with the proposed behavior of converting -mnan=legacy to -mnan=2008 with a warning on supported architectures?
References
· issue #100495: Original issue with incorrect NaN encoding
· pr #153777: Implementation of automatic conversion for -mnan=legacy
cc: @nikic
Thanks,
Ying