From fa8fadc0e55e0929a9cfd7e70e7ae38e20e00f8b Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Thu, 13 Oct 2016 12:49:31 +0000 Subject: [DAGCombiner] Add vector support to C2-(A+C1) -> (C2-C1)-A folding llvm-svn: 284117 --- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp') diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp index d01606e07e8..da37c777f33 100644 --- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp @@ -1939,7 +1939,6 @@ SDValue DAGCombiner::visitSUB(SDNode *N) { N1.getNode()); } - ConstantSDNode *N0C = getAsNonOpaqueConstant(N0); ConstantSDNode *N1C = getAsNonOpaqueConstant(N1); // fold (sub x, c) -> (add x, -c) @@ -1965,10 +1964,11 @@ SDValue DAGCombiner::visitSUB(SDNode *N) { return N0.getOperand(0); // fold C2-(A+C1) -> (C2-C1)-A - if (N1.getOpcode() == ISD::ADD && N0C) { - if (auto *N1C1 = dyn_cast(N1.getOperand(1).getNode())) { - SDValue NewC = - DAG.getConstant(N0C->getAPIntValue() - N1C1->getAPIntValue(), DL, VT); + if (N1.getOpcode() == ISD::ADD) { + SDValue N11 = N1.getOperand(1); + if (isConstantOrConstantVector(N0, /* NoOpaques */ true) && + isConstantOrConstantVector(N11, /* NoOpaques */ true)) { + SDValue NewC = DAG.getNode(ISD::SUB, DL, VT, N0, N11); return DAG.getNode(ISD::SUB, DL, VT, NewC, N1.getOperand(0)); } } -- cgit v1.2.3