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

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 13 12:53:24 PDT 2026


================
@@ -839,3 +839,36 @@ define void @i32_to_i8_wrong_order(i32 %x, ptr %p0) {
   store i8 %t1, ptr %p2, align 1
   ret void
 }
+
+; Negative test - the pattern only becomes visible after type legalization here,
+; because the stored bytes are forwarded from the earlier stores. Merging would
+; need an i16 truncate/bswap, and i16 is not a legal type, so the fold must not
+; run this late.
+
+define void @merge_i16_illegal_after_type_legalization(i64 %x, ptr %p, ptr noalias %q) {
+; CHECK-LABEL: merge_i16_illegal_after_type_legalization:
+; CHECK:       // %bb.0:
+; CHECK-NEXT:    mov x8, xzr
+; CHECK-NEXT:    lsr x9, x0, #8
+; CHECK-NEXT:    strb w0, [x2]
+; CHECK-NEXT:    ldr x8, [x8]
+; CHECK-NEXT:    strb w9, [x1]
+; CHECK-NEXT:    strb w9, [x8]
+; CHECK-NEXT:    strb w0, [x8, #1]
+; CHECK-NEXT:    strb wzr, [x1]
+; CHECK-NEXT:    ret
+  %b = load ptr, ptr null, align 8
----------------
arsenm wrote:

Can you avoid UB in tests, this should be a real pointer 

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


More information about the llvm-commits mailing list