[PATCH] D22685: Disable shrinking of SNaN constants on SystemZ
Elliot Colp via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 26 06:50:59 PDT 2016
colpell updated this revision to Diff 65507.
colpell added a comment.
Re-add test case that went missing.
https://reviews.llvm.org/D22685
Files:
include/llvm/Target/TargetLowering.h
lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
lib/Target/SystemZ/SystemZISelLowering.h
test/CodeGen/SystemZ/fp-const-10.ll
Index: test/CodeGen/SystemZ/fp-const-10.ll
===================================================================
--- test/CodeGen/SystemZ/fp-const-10.ll
+++ test/CodeGen/SystemZ/fp-const-10.ll
@@ -0,0 +1,15 @@
+; Test loads of SNaN.
+;
+; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
+
+; Test that we don't do an FP extending load, as this would result in a
+; converstion to QNaN.
+define double @f1() {
+; CHECK-LABEL: .LCPI0_0
+; CHECK: .quad 9219994337134247936
+; CHECK-LABEL: f1:
+; CHECK: larl %r1, .LCPI0_0
+; CHECK-NOT: ldeb %f0, 0(%r1)
+; CHECK: ld %f0, 0(%r1)
+ ret double 0x7FF4000000000000
+}
Index: lib/Target/SystemZ/SystemZISelLowering.h
===================================================================
--- lib/Target/SystemZ/SystemZISelLowering.h
+++ lib/Target/SystemZ/SystemZISelLowering.h
@@ -486,6 +486,10 @@
return true;
}
+ bool ShouldShrinkSNaNConstant() const override {
+ return false;
+ }
+
private:
const SystemZSubtarget &Subtarget;
Index: lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -259,19 +259,23 @@
(VT == MVT::f64) ? MVT::i64 : MVT::i32);
}
+ APFloat APF = CFP->getValueAPF();
EVT OrigVT = VT;
EVT SVT = VT;
- while (SVT != MVT::f32 && SVT != MVT::f16) {
- SVT = (MVT::SimpleValueType)(SVT.getSimpleVT().SimpleTy - 1);
- if (ConstantFPSDNode::isValueValidForType(SVT, CFP->getValueAPF()) &&
- // Only do this if the target has a native EXTLOAD instruction from
- // smaller type.
- TLI.isLoadExtLegal(ISD::EXTLOAD, OrigVT, SVT) &&
- TLI.ShouldShrinkFPConstant(OrigVT)) {
- Type *SType = SVT.getTypeForEVT(*DAG.getContext());
- LLVMC = cast<ConstantFP>(ConstantExpr::getFPTrunc(LLVMC, SType));
- VT = SVT;
- Extend = true;
+
+ if (TLI.ShouldShrinkSNaNConstant() || !APF.isSignaling()) {
+ while (SVT != MVT::f32 && SVT != MVT::f16) {
+ SVT = (MVT::SimpleValueType)(SVT.getSimpleVT().SimpleTy - 1);
+ if (ConstantFPSDNode::isValueValidForType(SVT, APF) &&
+ // Only do this if the target has a native EXTLOAD instruction from
+ // smaller type.
+ TLI.isLoadExtLegal(ISD::EXTLOAD, OrigVT, SVT) &&
+ TLI.ShouldShrinkFPConstant(OrigVT)) {
+ Type *SType = SVT.getTypeForEVT(*DAG.getContext());
+ LLVMC = cast<ConstantFP>(ConstantExpr::getFPTrunc(LLVMC, SType));
+ VT = SVT;
+ Extend = true;
+ }
}
}
Index: include/llvm/Target/TargetLowering.h
===================================================================
--- include/llvm/Target/TargetLowering.h
+++ include/llvm/Target/TargetLowering.h
@@ -887,6 +887,12 @@
/// reduce runtime.
virtual bool ShouldShrinkFPConstant(EVT) const { return true; }
+ /// If true (and ShouldShrinkFPConstant is also true), then instruction
+ /// selection should shrink SNaN constants. This is needeed for architectures
+ /// (e.g. SystemZ) in which FP extending loads of a SNaN result in a QNaN
+ /// instead.
+ virtual bool ShouldShrinkSNaNConstant() const { return true; }
+
// Return true if it is profitable to reduce the given load node to a smaller
// type.
//
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22685.65507.patch
Type: text/x-patch
Size: 3358 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160726/775235c9/attachment.bin>
More information about the llvm-commits
mailing list