Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d9d04de
[X86] Combine `store + vselect` to `masked_store``
abhishek-kaushik22 Jun 21, 2025
9eca209
Use pattern match
abhishek-kaushik22 Jun 22, 2025
c0d5cf0
Fix tests
abhishek-kaushik22 Jun 22, 2025
b3a4522
Revert last 3 commits
abhishek-kaushik22 Jun 26, 2025
04366fa
Revert "[X86] Combine `store + vselect` to `masked_store``"
abhishek-kaushik22 Jun 26, 2025
34fa965
Move to DAGCombiner
abhishek-kaushik22 Jun 26, 2025
3106f46
Update macro-fuse-cmp.ll
abhishek-kaushik22 Jun 26, 2025
8c14fba
Use allowsMisalignedMemoryAccesses to check if unaligned stores are a…
abhishek-kaushik22 Jun 27, 2025
f1b33cc
Use reachesChainWithoutSideEffects
abhishek-kaushik22 Jul 20, 2025
82180a8
Merge branch 'main' into masked-store
abhishek-kaushik22 Jul 20, 2025
63356e0
Update tests
abhishek-kaushik22 Jul 21, 2025
6602267
Test more types
abhishek-kaushik22 Jul 22, 2025
0898e47
Fix review comments and update tests
abhishek-kaushik22 Jul 23, 2025
efcf75a
Update DAGCombiner.cpp
abhishek-kaushik22 Jul 29, 2025
acbc2c1
Update DAGCombiner.cpp
abhishek-kaushik22 Jul 29, 2025
baf3d77
Merge branch 'main' into masked-store
abhishek-kaushik22 Jul 29, 2025
4485b09
Place fold at the end of visitSTORE
abhishek-kaushik22 Jul 30, 2025
ad5ead1
Merge branch 'masked-store' of https://github.com/abhishek-kaushik22/…
abhishek-kaushik22 Jul 30, 2025
ed1d804
Update DAGCombiner.cpp
abhishek-kaushik22 Aug 3, 2025
f5aed1f
Merge branch 'main' into masked-store
abhishek-kaushik22 Aug 3, 2025
6d26be2
Merge branch 'main' into masked-store
abhishek-kaushik22 Aug 4, 2025
f4157dd
Add address space check
abhishek-kaushik22 Aug 4, 2025
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
53 changes: 53 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22534,6 +22534,56 @@ SDValue DAGCombiner::visitATOMIC_STORE(SDNode *N) {
return SDValue();
}

static SDValue foldToMaskedStore(StoreSDNode *Store, SelectionDAG &DAG,
const SDLoc &Dl) {
if (!Store->isSimple() || !ISD::isNormalStore(Store))
return SDValue();

SDValue StoredVal = Store->getValue();
SDValue StorePtr = Store->getBasePtr();
SDValue StoreOffset = Store->getOffset();
EVT VT = Store->getMemoryVT();
unsigned AddrSpace = Store->getAddressSpace();
Align Alignment = Store->getAlign();
const TargetLowering &TLI = DAG.getTargetLoweringInfo();

if (!TLI.isOperationLegalOrCustom(ISD::MSTORE, VT) ||
!TLI.allowsMisalignedMemoryAccesses(VT, AddrSpace, Alignment))
return SDValue();

SDValue Mask, OtherVec, LoadCh;
unsigned LoadPos;
if (sd_match(StoredVal,
m_VSelect(m_Value(Mask), m_Value(OtherVec),
m_Load(m_Value(LoadCh), m_Specific(StorePtr),
m_Specific(StoreOffset))))) {
LoadPos = 2;
} else if (sd_match(StoredVal,
m_VSelect(m_Value(Mask),
m_Load(m_Value(LoadCh), m_Specific(StorePtr),
m_Specific(StoreOffset)),
m_Value(OtherVec)))) {
LoadPos = 1;
} else {
return SDValue();
}

auto *Load = cast<LoadSDNode>(StoredVal.getOperand(LoadPos));
if (!Load->isSimple() || !ISD::isNormalLoad(Load) ||
Load->getAddressSpace() != AddrSpace)
return SDValue();

if (!Store->getChain().reachesChainWithoutSideEffects(LoadCh))
return SDValue();

if (LoadPos == 1)
Mask = DAG.getNOT(Dl, Mask, Mask.getValueType());

return DAG.getMaskedStore(Store->getChain(), Dl, OtherVec, StorePtr,
StoreOffset, Mask, VT, Store->getMemOperand(),
Store->getAddressingMode());
}

SDValue DAGCombiner::visitSTORE(SDNode *N) {
StoreSDNode *ST = cast<StoreSDNode>(N);
SDValue Chain = ST->getChain();
Expand Down Expand Up @@ -22768,6 +22818,9 @@ SDValue DAGCombiner::visitSTORE(SDNode *N) {
if (SDValue NewSt = splitMergedValStore(ST))
return NewSt;

if (SDValue MaskedStore = foldToMaskedStore(ST, DAG, SDLoc(N)))
return MaskedStore;

return ReduceLoadOpStoreWidth(N);
}

Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/CodeGen/TargetLoweringBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,8 @@ void TargetLoweringBase::initActions() {
setOperationAction(ISD::GET_FPENV, VT, Expand);
setOperationAction(ISD::SET_FPENV, VT, Expand);
setOperationAction(ISD::RESET_FPENV, VT, Expand);

setOperationAction(ISD::MSTORE, VT, Expand);
}

// Most targets ignore the @llvm.prefetch intrinsic.
Expand Down
Loading