[llvm] [X86] Merge insertsubvector(load(p0),load_subv(p0),hi) -> subvbroadcast(p0) if either load is oneuse (PR #128857)
Phoebe Wang via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 26 19:22:48 PST 2025
================
@@ -58567,15 +58567,22 @@ static SDValue combineINSERT_SUBVECTOR(SDNode *N, SelectionDAG &DAG,
// 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));
----------------
phoebewang wrote:
This only required when `SubVec` has multiple user. Do we need to add a condition check?
https://github.com/llvm/llvm-project/pull/128857
More information about the llvm-commits
mailing list