summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Pilgrim <llvm-dev@redking.me.uk>2019-10-11 11:34:18 +0000
committerSimon Pilgrim <llvm-dev@redking.me.uk>2019-10-11 11:34:18 +0000
commit6434eac86086ed1dbeec873980d1fc9c1b0c895b (patch)
treed59394fe1d9decd87008cb86c5f0cc781b65b866
parentc8eb0547efc568ac688010961a5c19934caad4a2 (diff)
downloadbcm5719-llvm-6434eac86086ed1dbeec873980d1fc9c1b0c895b.tar.gz
bcm5719-llvm-6434eac86086ed1dbeec873980d1fc9c1b0c895b.zip
[X86] isFNEG - add recursion depth limit
Now that its used by isNegatibleForFree we should try to avoid costly deep recursion llvm-svn: 374534
-rw-r--r--llvm/lib/Target/X86/X86ISelLowering.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 0e119415303..ad0f7134c25 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -41254,10 +41254,14 @@ static SDValue combineVTRUNC(SDNode *N, SelectionDAG &DAG) {
/// In this case we go though all bitcasts.
/// This also recognizes splat of a negated value and returns the splat of that
/// value.
-static SDValue isFNEG(SelectionDAG &DAG, SDNode *N) {
+static SDValue isFNEG(SelectionDAG &DAG, SDNode *N, unsigned Depth = 0) {
if (N->getOpcode() == ISD::FNEG)
return N->getOperand(0);
+ // Don't recurse exponentially.
+ if (Depth > SelectionDAG::MaxRecursionDepth)
+ return SDValue();
+
unsigned ScalarSize = N->getValueType(0).getScalarSizeInBits();
SDValue Op = peekThroughBitcasts(SDValue(N, 0));
@@ -41271,7 +41275,7 @@ static SDValue isFNEG(SelectionDAG &DAG, SDNode *N) {
// of this is VECTOR_SHUFFLE(-VEC1, UNDEF). The mask can be anything here.
if (!SVOp->getOperand(1).isUndef())
return SDValue();
- if (SDValue NegOp0 = isFNEG(DAG, SVOp->getOperand(0).getNode()))
+ if (SDValue NegOp0 = isFNEG(DAG, SVOp->getOperand(0).getNode(), Depth + 1))
if (NegOp0.getValueType() == VT) // FIXME: Can we do better?
return DAG.getVectorShuffle(VT, SDLoc(SVOp), NegOp0, DAG.getUNDEF(VT),
SVOp->getMask());
@@ -41285,7 +41289,7 @@ static SDValue isFNEG(SelectionDAG &DAG, SDNode *N) {
SDValue InsVal = Op.getOperand(1);
if (!InsVector.isUndef())
return SDValue();
- if (SDValue NegInsVal = isFNEG(DAG, InsVal.getNode()))
+ if (SDValue NegInsVal = isFNEG(DAG, InsVal.getNode(), Depth + 1))
if (NegInsVal.getValueType() == VT.getVectorElementType()) // FIXME
return DAG.getNode(ISD::INSERT_VECTOR_ELT, SDLoc(Op), VT, InsVector,
NegInsVal, Op.getOperand(2));
@@ -41429,7 +41433,7 @@ char X86TargetLowering::isNegatibleForFree(SDValue Op, SelectionDAG &DAG,
bool ForCodeSize,
unsigned Depth) const {
// fneg patterns are removable even if they have multiple uses.
- if (isFNEG(DAG, Op.getNode()))
+ if (isFNEG(DAG, Op.getNode(), Depth))
return 2;
// Don't recurse exponentially.
@@ -41472,7 +41476,7 @@ SDValue X86TargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG,
bool ForCodeSize,
unsigned Depth) const {
// fneg patterns are removable even if they have multiple uses.
- if (SDValue Arg = isFNEG(DAG, Op.getNode()))
+ if (SDValue Arg = isFNEG(DAG, Op.getNode(), Depth))
return DAG.getBitcast(Op.getValueType(), Arg);
EVT VT = Op.getValueType();
OpenPOWER on IntegriCloud