[llvm] [X86] Fold vgf2p8affineqb XOR with splat constant into immediate (PR #179103)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 3 04:52:54 PST 2026


================
@@ -55850,6 +55821,51 @@ static SDValue foldXor1SetCC(SDNode *N, const SDLoc &DL, SelectionDAG &DAG) {
   return getSETCC(NewCC, LHS->getOperand(1), DL, DAG);
 }
 
+static SDValue combineXorWithGF2P8AFFINEQB(SDNode *N, const SDLoc &DL,
+                                           SelectionDAG &DAG) {
+  using namespace SDPatternMatch;
+
+  EVT VT = N->getValueType(0);
+  if (VT.getScalarSizeInBits() != 8)
+    return SDValue();
+
+  if (!DAG.getTargetLoweringInfo().isTypeLegal(VT.getSimpleVT()))
+    return SDValue();
+
+  SDValue X, Y, SplatOp;
+  APInt Imm;
+  // Use sd_match for structure matching - m_Xor handles commutation
+  if (!sd_match(N, m_Xor(m_OneUse(m_TernaryOp(X86ISD::GF2P8AFFINEQB, m_Value(X),
+                                              m_Value(Y), m_ConstInt(Imm))),
+                         m_Value(SplatOp))))
+    return SDValue();
+
+  // Use getTargetConstantBitsFromNode for robust splat constant extraction
+  APInt UndefElts;
+  SmallVector<APInt, 16> EltBits;
+  if (!getTargetConstantBitsFromNode(SplatOp, 8, UndefElts, EltBits, true,
+                                     false))
+    return SDValue();
+
+  // Check all elements are the same (splat constant)
----------------
RKSimon wrote:

You might be able to use X86::isConstantSplat?

https://github.com/llvm/llvm-project/pull/179103


More information about the llvm-commits mailing list