aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2019-05-02 14:47:59 +0000
committerSanjay Patel <spatel@rotateright.com>2019-05-02 14:47:59 +0000
commit284472be6da3353d81dfd25b1ac4218e852d1e5f (patch)
treecb2d7ce58399facb3870f7cfcfe648fdf1f35f9b /llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
parent8e6bf88cf763e7e5baa9b9745fe4616298040e4c (diff)
downloadllvm-284472be6da3353d81dfd25b1ac4218e852d1e5f.zip
llvm-284472be6da3353d81dfd25b1ac4218e852d1e5f.tar.gz
llvm-284472be6da3353d81dfd25b1ac4218e852d1e5f.tar.bz2
[SelectionDAG] remove constant folding limitations based on FP exceptions
We don't have FP exception limits in the IR constant folder for the binops (apart from strict ops), so it does not make sense to have them here in the DAG either. Nothing else in the backend tries to preserve exceptions (again outside of strict ops), so I don't see how this could have ever worked for real code that cares about FP exceptions. There are still cases (examples: unary opcodes in SDAG, FMA in IR) where we are trying (at least partially) to preserve exceptions without even asking if the target supports FP exceptions. Those should be corrected in subsequent patches. Real support for FP exceptions requires several changes to handle the constrained/strict FP ops. Differential Revision: https://reviews.llvm.org/D61331 llvm-svn: 359791
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp42
1 files changed, 16 insertions, 26 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 86e2fc2..b893d3f 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -4804,38 +4804,30 @@ SDValue SelectionDAG::FoldConstantVectorArithmetic(unsigned Opcode,
SDValue SelectionDAG::foldConstantFPMath(unsigned Opcode, const SDLoc &DL,
EVT VT, SDValue N1, SDValue N2) {
+ // TODO: We don't do any constant folding for strict FP opcodes here, but we
+ // should. That will require dealing with a potentially non-default
+ // rounding mode, checking the "opStatus" return value from the APFloat
+ // math calculations, and possibly other variations.
auto *N1CFP = dyn_cast<ConstantFPSDNode>(N1.getNode());
auto *N2CFP = dyn_cast<ConstantFPSDNode>(N2.getNode());
- bool HasFPExceptions = TLI->hasFloatingPointExceptions();
if (N1CFP && N2CFP) {
APFloat C1 = N1CFP->getValueAPF(), C2 = N2CFP->getValueAPF();
- APFloat::opStatus Status;
switch (Opcode) {
case ISD::FADD:
- Status = C1.add(C2, APFloat::rmNearestTiesToEven);
- if (!HasFPExceptions || Status != APFloat::opInvalidOp)
- return getConstantFP(C1, DL, VT);
- break;
+ C1.add(C2, APFloat::rmNearestTiesToEven);
+ return getConstantFP(C1, DL, VT);
case ISD::FSUB:
- Status = C1.subtract(C2, APFloat::rmNearestTiesToEven);
- if (!HasFPExceptions || Status != APFloat::opInvalidOp)
- return getConstantFP(C1, DL, VT);
- break;
+ C1.subtract(C2, APFloat::rmNearestTiesToEven);
+ return getConstantFP(C1, DL, VT);
case ISD::FMUL:
- Status = C1.multiply(C2, APFloat::rmNearestTiesToEven);
- if (!HasFPExceptions || Status != APFloat::opInvalidOp)
- return getConstantFP(C1, DL, VT);
- break;
+ C1.multiply(C2, APFloat::rmNearestTiesToEven);
+ return getConstantFP(C1, DL, VT);
case ISD::FDIV:
- Status = C1.divide(C2, APFloat::rmNearestTiesToEven);
- if (!HasFPExceptions || Status != APFloat::opInvalidOp)
- return getConstantFP(C1, DL, VT);
- break;
+ C1.divide(C2, APFloat::rmNearestTiesToEven);
+ return getConstantFP(C1, DL, VT);
case ISD::FREM:
- Status = C1.mod(C2);
- if (!HasFPExceptions || Status != APFloat::opInvalidOp)
- return getConstantFP(C1, DL, VT);
- break;
+ C1.mod(C2);
+ return getConstantFP(C1, DL, VT);
case ISD::FCOPYSIGN:
C1.copySign(C2);
return getConstantFP(C1, DL, VT);
@@ -5311,10 +5303,8 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, EVT VT,
APFloat V1 = N1CFP->getValueAPF();
const APFloat &V2 = N2CFP->getValueAPF();
const APFloat &V3 = N3CFP->getValueAPF();
- APFloat::opStatus s =
- V1.fusedMultiplyAdd(V2, V3, APFloat::rmNearestTiesToEven);
- if (!TLI->hasFloatingPointExceptions() || s != APFloat::opInvalidOp)
- return getConstantFP(V1, DL, VT);
+ V1.fusedMultiplyAdd(V2, V3, APFloat::rmNearestTiesToEven);
+ return getConstantFP(V1, DL, VT);
}
break;
}