summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp')
-rw-r--r--llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp26
1 files changed, 15 insertions, 11 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 9c67c3e948c..4f4f502442d 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -17889,30 +17889,34 @@ static SDValue narrowInsertExtractVectorBinOp(SDNode *Extract,
SelectionDAG &DAG) {
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
SDValue BinOp = Extract->getOperand(0);
- if (!TLI.isBinOp(BinOp.getOpcode()) || BinOp.getNode()->getNumValues() != 1)
+ unsigned BinOpcode = BinOp.getOpcode();
+ if (!TLI.isBinOp(BinOpcode) || BinOp.getNode()->getNumValues() != 1)
return SDValue();
SDValue Bop0 = BinOp.getOperand(0), Bop1 = BinOp.getOperand(1);
SDValue Index = Extract->getOperand(1);
EVT VT = Extract->getValueType(0);
- bool IsInsert0 = Bop0.getOpcode() == ISD::INSERT_SUBVECTOR &&
- Bop0.getOperand(1).getValueType() == VT &&
- Bop0.getOperand(2) == Index;
- bool IsInsert1 = Bop1.getOpcode() == ISD::INSERT_SUBVECTOR &&
- Bop1.getOperand(1).getValueType() == VT &&
- Bop1.getOperand(2) == Index;
+
+ auto GetSubVector = [VT, Index](SDValue V) {
+ if (V.getOpcode() != ISD::INSERT_SUBVECTOR ||
+ V.getOperand(1).getValueType() != VT || V.getOperand(2) != Index)
+ return SDValue();
+ return V.getOperand(1);
+ };
+ SDValue Sub0 = GetSubVector(Bop0);
+ SDValue Sub1 = GetSubVector(Bop1);
+
// TODO: We could handle the case where only 1 operand is being inserted by
// creating an extract of the other operand, but that requires checking
// number of uses and/or costs.
- if (!IsInsert0 || !IsInsert1 ||
- !TLI.isOperationLegalOrCustom(BinOp.getOpcode(), VT))
+ if (!Sub0 || !Sub1 || !TLI.isOperationLegalOrCustom(BinOpcode, VT))
return SDValue();
// We are inserting both operands of the wide binop only to extract back
// to the narrow vector size. Eliminate all of the insert/extract:
// ext (binop (ins ?, X, Index), (ins ?, Y, Index)), Index --> binop X, Y
- return DAG.getNode(BinOp.getOpcode(), SDLoc(Extract), VT, Bop0.getOperand(1),
- Bop1.getOperand(1), BinOp->getFlags());
+ return DAG.getNode(BinOpcode, SDLoc(Extract), VT, Sub0, Sub1,
+ BinOp->getFlags());
}
/// If we are extracting a subvector produced by a wide binary operator try
OpenPOWER on IntegriCloud