Skip to content

[X86] Merge insertsubvector(load(p0),load_subv(p0),hi) -> subvbroadcast(p0) if either load is oneuse #128857

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

Merged
merged 3 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions llvm/lib/Target/X86/X86ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58567,15 +58567,22 @@ static SDValue combineINSERT_SUBVECTOR(SDNode *N, SelectionDAG &DAG,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Vec have oneuse matter? Can't the loaded value be used more than once?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me see if I can get this to always replace uses of subvec - then we can get rid of the oneuse checks entirely

Copy link
Collaborator Author

@RKSimon RKSimon Feb 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The oneuse checks are still preventing some regressions due to shouldReduceLoadWidth being so permissive, but I've at least ensured that any other uses of SubVec are replaced now.

// If we're splatting the lower half subvector of a full vector load into the
// upper half, attempt to create a subvector broadcast.
if (IdxVal == (OpVT.getVectorNumElements() / 2) && SubVec.hasOneUse() &&
Vec.getValueSizeInBits() == (2 * SubVec.getValueSizeInBits())) {
// TODO: Drop hasOneUse checks.
if (IdxVal == (OpVT.getVectorNumElements() / 2) &&
Vec.getValueSizeInBits() == (2 * SubVec.getValueSizeInBits()) &&
(Vec.hasOneUse() || SubVec.hasOneUse())) {
auto *VecLd = dyn_cast<LoadSDNode>(Vec);
auto *SubLd = dyn_cast<LoadSDNode>(SubVec);
if (VecLd && SubLd &&
DAG.areNonVolatileConsecutiveLoads(SubLd, VecLd,
SubVec.getValueSizeInBits() / 8, 0))
return getBROADCAST_LOAD(X86ISD::SUBV_BROADCAST_LOAD, dl, OpVT, SubVecVT,
SubLd, 0, DAG);
DAG.areNonVolatileConsecutiveLoads(
SubLd, VecLd, SubVec.getValueSizeInBits() / 8, 0)) {
SDValue BcastLd = getBROADCAST_LOAD(X86ISD::SUBV_BROADCAST_LOAD, dl, OpVT,
SubVecVT, SubLd, 0, DAG);
SDValue NewSubVec = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, SubVecVT,
BcastLd, DAG.getVectorIdxConstant(0, dl));
DCI.CombineTo(SubLd, NewSubVec, BcastLd.getValue(1));
Comment on lines +58581 to +58583
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only required when SubVec has multiple user. Do we need to add a condition check?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need the check, oneuse cases will be handled fine, but it might slightly improve perf

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its easier if we always call it, just in case there's weird cases like only Subvec's chain is still in use.

return BcastLd;
}
}

return SDValue();
Expand Down
Loading