[llvm] [DAGCombiner] Restrict mergeTruncStores to pre-type-legalization combines (PR #222245)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 14 04:47:07 PDT 2026


================
@@ -9946,10 +9946,14 @@ static SDValue stripTruncAndExt(SDValue Value) {
 SDValue DAGCombiner::mergeTruncStores(StoreSDNode *N) {
   // The matching looks for "store (trunc x)" patterns that appear early but are
   // likely to be replaced by truncating store nodes during combining.
+  // This must be restricted to the combine rounds that run before type
+  // legalization: the fold creates a truncate to the wide type plus an optional
+  // bswap/rotate of it, and those are only allowed to have an illegal type
+  // while types have not been legalized yet.
----------------
arsenm wrote:

This should be a `!LegalOperations || isOperationLegalOrCustom(ISD::BSWAP, VT)` check; the type legality will be implied by the operation being legal

(Also looking again, I thought I saw a bswap legality check but I don't actually)

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


More information about the llvm-commits mailing list