[PATCH] Add support for generating MIPS legacy NaN
Vladimir Radosavljevic
vladimir.radosavljevic at rt-rk.com
Wed Feb 25 08:18:31 PST 2015
Hi dsanders, petarj,
Currently, the NaN values emitted for MIPS architectures, do not cover non-2008 compliant case. This change fixes the issue.
http://reviews.llvm.org/D7882
Files:
include/clang/Basic/TargetInfo.h
lib/AST/ExprConstant.cpp
lib/Basic/Targets.cpp
test/CodeGen/builtin-nan-legacy.c
Index: include/clang/Basic/TargetInfo.h
===================================================================
--- include/clang/Basic/TargetInfo.h
+++ include/clang/Basic/TargetInfo.h
@@ -638,6 +638,12 @@
return std::string(1, *Constraint);
}
+ /// \brief Returns true if NaN encoding is IEEE 754-2008.
+ /// Only on MIPS can be different encoding.
+ virtual bool isNan2008() const {
+ return true;
+ }
+
/// \brief Returns a string of target-specific clobbers, in LLVM format.
virtual const char *getClobbers() const = 0;
Index: lib/AST/ExprConstant.cpp
===================================================================
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -7590,10 +7590,19 @@
else if (S->getString().getAsInteger(0, fill))
return false;
- if (SNaN)
- Result = llvm::APFloat::getSNaN(Sem, false, &fill);
- else
- Result = llvm::APFloat::getQNaN(Sem, false, &fill);
+ if (Context.getTargetInfo().isNan2008()) {
+ if (SNaN)
+ Result = llvm::APFloat::getSNaN(Sem, false, &fill);
+ else
+ Result = llvm::APFloat::getQNaN(Sem, false, &fill);
+ } else {
+ // This case will be triggered for Mips legacy encoding.
+ if (SNaN)
+ Result = llvm::APFloat::getQNaN(Sem, false, &fill);
+ else
+ Result = llvm::APFloat::getSNaN(Sem, false, &fill);
+ }
+
return true;
}
Index: lib/Basic/Targets.cpp
===================================================================
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -5675,6 +5675,10 @@
return CPU == "mips32r6" || ABI == "n32" || ABI == "n64" || ABI == "64";
}
+ bool isNan2008() const override {
+ return IsNan2008 || isNaN2008Default();
+ }
+
StringRef getABI() const override { return ABI; }
bool setCPU(const std::string &Name) override {
bool IsMips32 = getTriple().getArch() == llvm::Triple::mips ||
Index: test/CodeGen/builtin-nan-legacy.c
===================================================================
--- /dev/null
+++ test/CodeGen/builtin-nan-legacy.c
@@ -0,0 +1,13 @@
+// RUN: %clang -target mipsel-unknown-linux -mnan=legacy -emit-llvm -S -o %t %s
+// RUN: grep 'float 0x7FF4000000000000, float 0x7FF8000000000000' %t
+// RUN: grep 'double 0x7FF4000000000000, double 0x7FF8000000000000' %t
+
+float f[] = {
+ __builtin_nan(""),
+ __builtin_nans(""),
+};
+
+double d[] = {
+ __builtin_nan(""),
+ __builtin_nans(""),
+};
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7882.20678.patch
Type: text/x-patch
Size: 2420 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150225/37097b88/attachment.bin>
More information about the cfe-commits
mailing list