[llvm] [DAG] Combine `store + vselect` to `masked_store` (PR #145176)

Abhishek Kaushik via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 20 04:10:37 PDT 2025


================
@@ -22451,12 +22452,84 @@ SDValue DAGCombiner::visitATOMIC_STORE(SDNode *N) {
   return SDValue();
 }
 
+static SDValue foldToMaskedStore(StoreSDNode *Store, SelectionDAG &DAG,
+                                 const SDLoc &Dl) {
+  using namespace llvm::SDPatternMatch;
+
+  if (!Store->isSimple() || Store->isTruncatingStore())
+    return SDValue();
+
+  SDValue StoredVal = Store->getValue();
+  SDValue StorePtr = Store->getBasePtr();
+  SDValue StoreOffset = Store->getOffset();
+  EVT VT = Store->getMemoryVT();
+  unsigned AddrSpace = Store->getAddressSpace();
+  Align Alignment = Store->getAlign();
+  const TargetLowering &TLI = DAG.getTargetLoweringInfo();
+
+  if (!TLI.isOperationLegalOrCustom(ISD::MSTORE, VT) ||
+      !TLI.allowsMisalignedMemoryAccesses(VT, AddrSpace, Alignment))
----------------
abhishek-kaushik22 wrote:

There a test in `llvm/test/CodeGen/RISCV/combine-storetomstore.ll`, `@test_masked_store_unaligned` which does this, and doesn't conver the load + blend to a masked store

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


More information about the llvm-commits mailing list