[llvm] [DAG][X86] Bitfield insertion can combine into SHL + SHRD (PR #220182)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 8 02:19:45 PDT 2026
================
@@ -54096,6 +54096,55 @@ static SDValue combineOrXorWithSETCC(unsigned Opc, const SDLoc &DL, EVT VT,
return SDValue();
}
+// Fold an OR with a masked destination and a left-shifted
+// source into a shift + double-precision shift (SHRD):
+static SDValue combineOrOnSHLToSHRD(SDNode *N, SDLoc &DL, SelectionDAG &DAG,
+ const X86Subtarget &Subtarget) {
+ using namespace SDPatternMatch;
+
+ // If optimizing for code size, run irrespective of slow SHLD.
+ // If not optimizing for code size and SHLD is slow, then bail.
+ bool IsOptSize = DAG.getMachineFunction().getFunction().hasOptSize();
+ if (!IsOptSize && Subtarget.isSHLDSlow())
+ return SDValue();
+
+ EVT VT = N->getValueType(0);
+
+ // SHRD does not suppport 8-bit operands
+ if (VT == MVT::i8)
+ return SDValue();
+
+ APInt Mask;
+ uint64_t ShiftAmount;
+ SDValue X, Y;
+
+ // Check for the following pattern:
+ // (or (and X, HighBitsMask(C)), (srl Y, C))
+ // Do not combine if there are multi-use AND and OR.
+ // It does not result in more performant code.
+ if (!sd_match(N, m_Or(m_OneUse(m_And(m_Value(X), m_ConstInt(Mask))),
+ m_OneUse(m_Shl(m_Value(Y), m_ConstInt(ShiftAmount))))))
+ return SDValue();
+
+ // Max bit-width of operands
+ uint64_t MaxMaskBitWidth = VT.getSizeInBits();
----------------
RKSimon wrote:
still not vector safe
https://github.com/llvm/llvm-project/pull/220182
More information about the llvm-commits
mailing list