Skip to content

Commit 4616866

Browse files
committed
[X86] narrowBitOpRMW - allow additional uses of the BTC/R/S result
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 12f392c commit 4616866

File tree

2 files changed

+89
-331
lines changed

2 files changed

+89
-331
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

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

53444-
return DAG.getStore(St->getChain(), DL, Res, NewPtr, St->getPointerInfo(),
53445-
Align(), St->getMemOperand()->getFlags());
53443+
SDValue NewStore =
53444+
DAG.getStore(St->getChain(), DL, Res, NewPtr, St->getPointerInfo(),
53445+
Align(), St->getMemOperand()->getFlags());
53446+
53447+
// If there are other uses of StoredVal, replace with a new load of the
53448+
// whole (updated) value and ensure that any chained dependencies on the
53449+
// original store are updated to come AFTER the new load.
53450+
if (!StoredVal.hasOneUse()) {
53451+
SDValue NewLoad =
53452+
DAG.getLoad(VT, DL, NewStore, Ld->getBasePtr(), Ld->getMemOperand());
53453+
DAG.ReplaceAllUsesWith(StoredVal, NewLoad);
53454+
DAG.ReplaceAllUsesWith(SDValue(St, 0), NewLoad.getValue(1));
53455+
}
53456+
return NewStore;
5344653457
}
5344753458

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

0 commit comments

Comments
 (0)