[llvm] [X86] added computeKnownBits for X86ISD::GF2P8AFFINEQB (PR #194197)
via llvm-commits
llvm-commits at lists.llvm.org
Fri May 1 21:25:23 PDT 2026
================
@@ -39022,6 +39026,51 @@ void X86TargetLowering::computeKnownBitsForTargetNode(const SDValue Op,
Known.resetAll();
switch (Opc) {
default: break;
+ case X86ISD::GF2P8AFFINEQB: {
+ SDValue Input = Op.getOperand(0);
+ SDValue Matrix = Op.getOperand(1);
+ SDValue Imm = Op.getOperand(2);
+
+ auto *ImmN = dyn_cast<ConstantSDNode>(Imm);
+ if (!ImmN)
+ break;
+
+ uint8_t Imm8 = ImmN->getZExtValue();
+ APInt UndefElts;
+ SmallVector<APInt, 64> MatEltBits;
+ if (!getTargetConstantBitsFromNode(Matrix, 8, UndefElts, MatEltBits,
+ /*AllowWholeUndefs=*/false,
+ /*AllowPartialUndefs=*/false))
+ break;
+
+ KnownBits InputKnown = DAG.computeKnownBits(Input, DemandedElts, Depth + 1);
+
+ APInt KnownMask = InputKnown.Zero | InputKnown.One;
+ KnownBits Res(BitWidth);
+ Res.resetAll();
+
+ for (unsigned OutBit = 0; OutBit != 8; ++OutBit) {
+ unsigned RowIdx = 7 - OutBit;
+
+ uint8_t Row = MatEltBits[RowIdx].getZExtValue();
+ APInt RowMask(8, Row);
+
+ if (!(RowMask & ~KnownMask).isZero())
+ continue;
+
+ uint8_t Bits = (InputKnown.One & RowMask).getZExtValue();
+ bool Parity = llvm::popcount(Bits) & 1;
+ bool FinalBit = Parity ^ ((Imm8 >> OutBit) & 1);
+
+ if (FinalBit)
----------------
WalterKruger wrote:
```suggestion
KnownBits KnownRow = KnownBits::makeConstant(MatEltBits[RowIdx]);
KnownRow &= InputKnown;
if (!KnownRow.isConstant())
continue;
if (KnownRow.One.popcount() & 1)
```
You can then apply the immediate to the Res struct after you finish looping using `^= KnownBits::makeConstant`.
https://github.com/llvm/llvm-project/pull/194197
More information about the llvm-commits
mailing list