[llvm] [SDAG][X86] Merge MMOs when reusing morphed node (PR #206700)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 1 02:04:12 PDT 2026


================
@@ -4461,7 +4461,34 @@ void SelectionDAGISel::SelectCodeCommon(SDNode *NodeToMatch,
           }
         }
 
-        CurDAG->setNodeMemRefs(Res, FilteredMemRefs);
+        if (Res->memoperands_empty()) {
+          // If the node is new, just copy the MMOs.
+          CurDAG->setNodeMemRefs(Res, FilteredMemRefs);
----------------
nikic wrote:

As far as I can tell, this case doesn't go through this code path at all (OPFL_MemRefs will not be set).

I also testing asserting `FilteredMemRefs.size() != 0` and this never triggers on X86 -- but there are a few failures in other backends. One case I looked at (CodeGen/SPARC/bswap.ll) looks like a bug in the filtering logic above -- we start with a `load store` MMO and `mayStore` and this gets filtered out above, which I don't think is correct. (There's the other bug that it's created as `load store` in the first place, but that's just a quality issue.)

I think that enforcing that there are no empty FilteredMemRefs here is probably something we should do, but it will require some yak shaving, and it mostly orthogonal to this change.

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


More information about the llvm-commits mailing list