This is an archive of the discontinued LLVM Phabricator instance.

Add support for generating MIPS legacy NaN
ClosedPublic

Authored by vradosavljevic on Feb 25 2015, 8:18 AM.

Details

Summary

Currently, the NaN values emitted for MIPS architectures, do not cover non-2008 compliant case. This change fixes the issue.

Diff Detail

Repository
rL LLVM

Event Timeline

vradosavljevic retitled this revision from to Add support for generating MIPS legacy NaN.
vradosavljevic updated this object.
vradosavljevic edited the test plan for this revision. (Show Details)
vradosavljevic added reviewers: dsanders, petarj.
vradosavljevic added a subscriber: Unknown Object (MLST).
dsanders added inline comments.
lib/AST/ExprConstant.cpp
7599–7603 ↗(On Diff #20678)

Could you add a comment explaining the relevant history and why that leads to QNaN and SNaN being reversed here. It won't be obvious to most readers.

lib/Basic/Targets.cpp
5679 ↗(On Diff #20678)

This isn't quite right. It should just be IsNan2008 since IsNan2008 is initialized with the result of isNaN2008Default().

test/CodeGen/builtin-nan-legacy.c
2–3 ↗(On Diff #20678)

New tests should be using FileCheck rather than grep.

vradosavljevic added inline comments.Feb 26 2015, 5:28 AM
lib/Basic/Targets.cpp
5679 ↗(On Diff #20678)

When you generating code for mips32r6/mips64r6 with option -mnan=legacy, IsNan2008 will be set to false.
In function handleTargetFeatures there are lines that change that.

else if (*it == "-nan2008")
  IsNan2008 = false;

Because of that, I use the result of isNaN2008Default().

petarj added inline comments.Feb 26 2015, 6:51 AM
lib/Basic/Targets.cpp
5679 ↗(On Diff #20678)

We should not allow that case. Clang should (at least) issue a warning if "-mnan=legacy" is passed for the revisions that do not support the NaN legacy encoding.

dsanders added inline comments.Feb 26 2015, 8:01 AM
lib/Basic/Targets.cpp
5679 ↗(On Diff #20678)

Agreed. I'd prefer an error* since the user is requesting an impossible combination of options but it should at least warn instead of quietly ignoring the user.

*Ideally with a suggestion for fixing it, e.g. "error: IEEE754(2008) compliant NaN's are mandatory on Mips32r6. Did you mean -mnan=2008?"

petarj added inline comments.Feb 26 2015, 8:11 AM
lib/Basic/Targets.cpp
5679 ↗(On Diff #20678)

I would also prefer an error, but gcc seems to produce a warning only.
Furthermore, we should do similar for "-mnan=2008" and earlier mips revisions. But this all can be part of another patch, not this one necessary.

vradosavljevic added inline comments.Feb 26 2015, 8:22 AM
lib/AST/ExprConstant.cpp
7599–7603 ↗(On Diff #20678)

Done.

lib/Basic/Targets.cpp
5679 ↗(On Diff #20678)

Done.

5679 ↗(On Diff #20678)

Ok. This will be part of the next patch.

test/CodeGen/builtin-nan-legacy.c
2–3 ↗(On Diff #20678)

Done.

New patch uploaded.

dsanders added inline comments.Feb 26 2015, 8:31 AM
lib/Basic/Targets.cpp
5679 ↗(On Diff #20678)

Furthermore, we should do similar for "-mnan=2008" and earlier mips revisions. But this all can be part of another patch, not this one necessary.

Off hand, I'm not sure exactly which ISA introduced the ABS2008 and NAN2008 config bits but at least some of the ISA's prior to 32r6/64r6 supported 2008 in addition to legacy. I don't think it's seen widespread use though.

dsanders accepted this revision.Feb 26 2015, 9:02 AM
dsanders edited edge metadata.

LGTM with a couple tiny nits.

include/clang/Basic/TargetInfo.h
642 ↗(On Diff #20765)

Small nit: The grammar is a little odd, possibly a missing word? Maybe use 'Only MIPS allows a different encoding'

lib/AST/ExprConstant.cpp
7599–7603 ↗(On Diff #20765)

Just a couple tiny grammar nits:

"...to choose the first bit of their significand set for qNaN and sNaN." -> "...to choose whether the first bit of their significand was set for qNaN or sNaN."

"MIPS chose different encoding..." -> "MIPS chose a different encoding...".

This revision is now accepted and ready to land.Feb 26 2015, 9:02 AM
petarj added inline comments.Feb 26 2015, 9:06 AM
lib/Basic/Targets.cpp
5679 ↗(On Diff #20678)

FIR.Has2008 is optional as of R3, so MIPS32R2 and earlier cores are in conflict with -mnan=2008.

vradosavljevic added inline comments.Feb 26 2015, 9:16 AM
include/clang/Basic/TargetInfo.h
642 ↗(On Diff #20765)

Done.

lib/AST/ExprConstant.cpp
7599–7603 ↗(On Diff #20765)

Done.

vradosavljevic edited edge metadata.

Comments addressed.

LGTM, Thanks. Do you have commit access or do you need someone to commit it for you?

This revision was automatically updated to reflect the committed changes.