Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show First 20 Lines • Show All 23,349 Lines • ▼ Show 20 Lines | static SDValue scalarizeBinOpOfSplats(SDNode *N, SelectionDAG &DAG, | ||||
const TargetLowering &TLI = DAG.getTargetLoweringInfo(); | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); | ||||
// TODO: Remove/replace the extract cost check? If the elements are available | // TODO: Remove/replace the extract cost check? If the elements are available | ||||
// as scalars, then there may be no extract cost. Should we ask if | // as scalars, then there may be no extract cost. Should we ask if | ||||
// inserting a scalar back into a vector is cheap instead? | // inserting a scalar back into a vector is cheap instead? | ||||
int Index0, Index1; | int Index0, Index1; | ||||
SDValue Src0 = DAG.getSplatSourceVector(N0, Index0); | SDValue Src0 = DAG.getSplatSourceVector(N0, Index0); | ||||
SDValue Src1 = DAG.getSplatSourceVector(N1, Index1); | SDValue Src1 = DAG.getSplatSourceVector(N1, Index1); | ||||
// Extract element from splat_vector should be free. | |||||
bool IsBothSplatVector = N0.getOpcode() == ISD::SPLAT_VECTOR && | |||||
N1.getOpcode() == ISD::SPLAT_VECTOR; | |||||
RKSimon: Use DAG.isSplatValue instead? | |||||
I tried to use DAG.isSplatValue, but this way would affect many no splat cases of X86 target, some of them are negative. jacquesguan: I tried to use DAG.isSplatValue, but this way would affect many no splat cases of X86 target… | |||||
Not Done ReplyInline ActionsOK - please can you add a TODO comment? It sounds like something that needs revisiting in the future. RKSimon: OK - please can you add a TODO comment? It sounds like something that needs revisiting in the… | |||||
if (!Src0 || !Src1 || Index0 != Index1 || | if (!Src0 || !Src1 || Index0 != Index1 || | ||||
Src0.getValueType().getVectorElementType() != EltVT || | Src0.getValueType().getVectorElementType() != EltVT || | ||||
Src1.getValueType().getVectorElementType() != EltVT || | Src1.getValueType().getVectorElementType() != EltVT || | ||||
!TLI.isExtractVecEltCheap(VT, Index0) || | !(IsBothSplatVector || TLI.isExtractVecEltCheap(VT, Index0)) || | ||||
!TLI.isOperationLegalOrCustom(Opcode, EltVT)) | !TLI.isOperationLegalOrCustom(Opcode, EltVT)) | ||||
return SDValue(); | return SDValue(); | ||||
SDValue IndexC = DAG.getVectorIdxConstant(Index0, DL); | SDValue IndexC = DAG.getVectorIdxConstant(Index0, DL); | ||||
SDValue X = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, Src0, IndexC); | SDValue X = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, Src0, IndexC); | ||||
SDValue Y = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, Src1, IndexC); | SDValue Y = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, EltVT, Src1, IndexC); | ||||
SDValue ScalarBO = DAG.getNode(Opcode, DL, EltVT, X, Y, N->getFlags()); | SDValue ScalarBO = DAG.getNode(Opcode, DL, EltVT, X, Y, N->getFlags()); | ||||
// If all lanes but 1 are undefined, no need to splat the scalar result. | // If all lanes but 1 are undefined, no need to splat the scalar result. | ||||
// TODO: Keep track of undefs and use that info in the general case. | // TODO: Keep track of undefs and use that info in the general case. | ||||
if (N0.getOpcode() == ISD::BUILD_VECTOR && N0.getOpcode() == N1.getOpcode() && | if (N0.getOpcode() == ISD::BUILD_VECTOR && N0.getOpcode() == N1.getOpcode() && | ||||
count_if(N0->ops(), [](SDValue V) { return !V.isUndef(); }) == 1 && | count_if(N0->ops(), [](SDValue V) { return !V.isUndef(); }) == 1 && | ||||
count_if(N1->ops(), [](SDValue V) { return !V.isUndef(); }) == 1) { | count_if(N1->ops(), [](SDValue V) { return !V.isUndef(); }) == 1) { | ||||
// bo (build_vec ..undef, X, undef...), (build_vec ..undef, Y, undef...) --> | // bo (build_vec ..undef, X, undef...), (build_vec ..undef, Y, undef...) --> | ||||
// build_vec ..undef, (bo X, Y), undef... | // build_vec ..undef, (bo X, Y), undef... | ||||
SmallVector<SDValue, 8> Ops(VT.getVectorNumElements(), DAG.getUNDEF(EltVT)); | SmallVector<SDValue, 8> Ops(VT.getVectorNumElements(), DAG.getUNDEF(EltVT)); | ||||
Ops[Index0] = ScalarBO; | Ops[Index0] = ScalarBO; | ||||
return DAG.getBuildVector(VT, DL, Ops); | return DAG.getBuildVector(VT, DL, Ops); | ||||
} | } | ||||
// bo (splat X, Index), (splat Y, Index) --> splat (bo X, Y), Index | // bo (splat X, Index), (splat Y, Index) --> splat (bo X, Y), Index | ||||
if (VT.isScalableVector()) | |||||
return DAG.getSplatVector(VT, DL, ScalarBO); | |||||
SmallVector<SDValue, 8> Ops(VT.getVectorNumElements(), ScalarBO); | SmallVector<SDValue, 8> Ops(VT.getVectorNumElements(), ScalarBO); | ||||
return DAG.getBuildVector(VT, DL, Ops); | return DAG.getBuildVector(VT, DL, Ops); | ||||
Not Done ReplyInline ActionsNot sure we should be creating SPLAT_VECTOR on targets that don't support SPLAT_VECTOR. At the very least it's a waste of compile time to convert it back to a BUILD_VECTOR. craig.topper: Not sure we should be creating SPLAT_VECTOR on targets that don't support SPLAT_VECTOR. At the… | |||||
Not Done ReplyInline Actions+1 at the very least we need a hasOperation() check for the getSplatVector path and getBuildVector fallback RKSimon: +1 at the very least we need a hasOperation() check for the getSplatVector path and… | |||||
Done, I only build splat_vector when is scalable now. jacquesguan: Done, I only build splat_vector when is scalable now. | |||||
} | } | ||||
/// Visit a binary vector operation, like ADD. | /// Visit a binary vector operation, like ADD. | ||||
SDValue DAGCombiner::SimplifyVBinOp(SDNode *N, const SDLoc &DL) { | SDValue DAGCombiner::SimplifyVBinOp(SDNode *N, const SDLoc &DL) { | ||||
EVT VT = N->getValueType(0); | EVT VT = N->getValueType(0); | ||||
assert(VT.isVector() && "SimplifyVBinOp only works on vectors!"); | assert(VT.isVector() && "SimplifyVBinOp only works on vectors!"); | ||||
SDValue LHS = N->getOperand(0); | SDValue LHS = N->getOperand(0); | ||||
▲ Show 20 Lines • Show All 1,468 Lines • Show Last 20 Lines |
Use DAG.isSplatValue instead?