[llvm] [DAGCombiner] Teach MatchLoadCombine to look through AND masks (PR #200247)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 3 07:05:06 PDT 2026


================
@@ -9614,11 +9614,42 @@ calculateByteProvider(SDValue Op, unsigned Index, unsigned Depth,
                        SDByteProvider::getConstantZero())
                  : std::nullopt;
     return calculateByteProvider(NarrowOp, Index, Depth + 1, VectorIndex,
-                                 StartingIndex);
+                                 StartingIndex, ByteMask);
   }
   case ISD::BSWAP:
     return calculateByteProvider(Op->getOperand(0), ByteWidth - Index - 1,
-                                 Depth + 1, VectorIndex, StartingIndex);
+                                 Depth + 1, VectorIndex, StartingIndex,
+                                 ByteMask);
+  case ISD::AND: {
+    unsigned MaskIdx = 1;
+    auto MaskOp = dyn_cast<ConstantSDNode>(Op->getOperand(MaskIdx));
+    if (!MaskOp) {
+      MaskIdx = 0;
+      MaskOp = dyn_cast<ConstantSDNode>(Op->getOperand(MaskIdx));
+      if (!MaskOp)
+        return std::nullopt;
+    }
+
+    uint64_t Mask = MaskOp->getZExtValue();
+    uint8_t MaskByte = (Mask >> (Index * 8)) & 0xFF;
----------------
RKSimon wrote:

```suggestion
    uint8_t MaskByte = MaskOp->getAPIntValue().extractBitsAsZExtValue(8, Index * 8);
```

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


More information about the llvm-commits mailing list