Skip to content

Commit 28e024f

Browse files
authored
[X86] narrowBitOpRMW - allow additional uses of the BTC/R/S result (#166376)
If there are additional uses of the bit twiddled value as well as the rmw store, we can replace them with a (re)loaded copy of the full width integer value after the store. There's some memory op chain handling to handle here - the additional (re)load is chained after the new store and then any dependencies of the original store are chained after the (re)load.
1 parent fb49adb commit 28e024f

File tree

2 files changed

+87
-331
lines changed

2 files changed

+87
-331
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53370,8 +53370,7 @@ static SDValue narrowBitOpRMW(StoreSDNode *St, const SDLoc &DL,
5337053370
//
5337153371
// BitInsert: (X & ~(1 << ShAmt)) | (InsertBit << ShAmt)
5337253372
SDValue SrcVal, InsertBit, ShAmt;
53373-
if (!StoredVal.hasOneUse() ||
53374-
!(sd_match(StoredVal, m_And(m_Value(SrcVal),
53373+
if (!(sd_match(StoredVal, m_And(m_Value(SrcVal),
5337553374
m_Not(m_Shl(m_One(), m_Value(ShAmt))))) ||
5337653375
sd_match(StoredVal,
5337753376
m_Or(m_Value(SrcVal), m_Shl(m_One(), m_Value(ShAmt)))) ||
@@ -53442,8 +53441,18 @@ static SDValue narrowBitOpRMW(StoreSDNode *St, const SDLoc &DL,
5344253441
Res = DAG.getNode(StoredVal.getOpcode(), DL, MVT::i32, X, Mask);
5344353442
}
5344453443

53445-
return DAG.getStore(St->getChain(), DL, Res, NewPtr, St->getPointerInfo(),
53446-
Align(), St->getMemOperand()->getFlags());
53444+
SDValue NewStore =
53445+
DAG.getStore(St->getChain(), DL, Res, NewPtr, St->getPointerInfo(),
53446+
Align(), St->getMemOperand()->getFlags());
53447+
53448+
// If there are other uses of StoredVal, replace with a new load of the
53449+
// whole (updated) value.
53450+
if (!StoredVal.hasOneUse()) {
53451+
SDValue NewLoad =
53452+
DAG.getLoad(VT, DL, NewStore, Ld->getBasePtr(), Ld->getMemOperand());
53453+
DAG.ReplaceAllUsesWith(StoredVal, NewLoad);
53454+
}
53455+
return NewStore;
5344753456
}
5344853457

5344953458
static SDValue combineStore(SDNode *N, SelectionDAG &DAG,

0 commit comments

Comments
 (0)