-
Notifications
You must be signed in to change notification settings - Fork 15.3k
DAG: Fix vector bin op scalarize defining a partially undef vector #122459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cf8120e
a4a1f28
351dfdf
70d7ce1
da27407
c41456e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27526,23 +27526,27 @@ static SDValue scalarizeBinOpOfSplats(SDNode *N, SelectionDAG &DAG, | |
| if ((Opcode == ISD::MULHS || Opcode == ISD::MULHU) && !TLI.isTypeLegal(EltVT)) | ||
| return SDValue(); | ||
|
|
||
| if (N0.getOpcode() == ISD::BUILD_VECTOR && N0.getOpcode() == N1.getOpcode()) { | ||
| // All but one element should have an undef input, which will fold to a | ||
| // constant or undef. Avoid splatting which would over-define potentially | ||
| // undefined elements. | ||
|
|
||
|
||
| // bo (build_vec ..undef, X, undef...), (build_vec ..undef, Y, undef...) --> | ||
| // build_vec ..undef, (bo X, Y), undef... | ||
| SmallVector<SDValue, 16> EltsX, EltsY, EltsResult; | ||
| DAG.ExtractVectorElements(Src0, EltsX); | ||
| DAG.ExtractVectorElements(Src1, EltsY); | ||
|
|
||
| for (auto [X, Y] : zip(EltsX, EltsY)) | ||
| EltsResult.push_back(DAG.getNode(Opcode, DL, EltVT, X, Y, N->getFlags())); | ||
| return DAG.getBuildVector(VT, DL, EltsResult); | ||
| } | ||
|
|
||
| SDValue IndexC = DAG.getVectorIdxConstant(Index0, DL); | ||
| 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 ScalarBO = DAG.getNode(Opcode, DL, EltVT, X, Y, N->getFlags()); | ||
|
|
||
| // 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. | ||
| if (N0.getOpcode() == ISD::BUILD_VECTOR && N0.getOpcode() == N1.getOpcode() && | ||
| count_if(N0->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...) --> | ||
| // build_vec ..undef, (bo X, Y), undef... | ||
| SmallVector<SDValue, 8> Ops(VT.getVectorNumElements(), DAG.getUNDEF(EltVT)); | ||
| Ops[Index0] = ScalarBO; | ||
| return DAG.getBuildVector(VT, DL, Ops); | ||
| } | ||
|
|
||
| // bo (splat X, Index), (splat Y, Index) --> splat (bo X, Y), Index | ||
| return DAG.getSplat(VT, DL, ScalarBO); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think both the comment and TODO need updating
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't check for all-but-one undef lanes though anymore?