[llvm] [SelectionDAG] Require same MMO base in relative-align no-alias proof (PR #217880)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 23 19:54:13 PDT 2026
https://github.com/chenqiant updated https://github.com/llvm/llvm-project/pull/217880
>From 6fabf9d4398361e54735cf8acf51b538626db99b Mon Sep 17 00:00:00 2001
From: chenqian <chen.qian at espressif.com>
Date: Mon, 24 Aug 2026 10:53:19 +0800
Subject: [PATCH] [RISCV] Pin load-all-then-store-all for overlapping 12-byte
memmove
A 12-byte memmove expands to three i32 pairs. Backward overlap is only
correct if every source word is loaded before the first store.
Withdraw the DAGCombiner same-MMO-Value guard: the relative-align
no-alias proof is base-independent, and dst/src alignments 16 vs 8
never entered that proof.
Assisted-by: Cursor
Co-authored-by: Cursor <cursoragent at cursor.com>
---
.../CodeGen/RISCV/memmove-overlap-order.ll | 24 +++++++++++++++++++
1 file changed, 24 insertions(+)
create mode 100644 llvm/test/CodeGen/RISCV/memmove-overlap-order.ll
diff --git a/llvm/test/CodeGen/RISCV/memmove-overlap-order.ll b/llvm/test/CodeGen/RISCV/memmove-overlap-order.ll
new file mode 100644
index 0000000000000..9b877bb91ba41
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/memmove-overlap-order.ll
@@ -0,0 +1,24 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: llc -mtriple=riscv32 -O2 < %s | FileCheck %s
+
+; A 12-byte memmove with dst 16-byte aligned and src 8-byte aligned lowers to
+; three i32 load/store pairs (offsets 0/4/8). For a backward copy (runtime
+; dst > src with 0 < dst-src < 12) every source chunk must be loaded before
+; the first store, otherwise a store to dst[0] clobbers src[4..8) before it
+; is read. Pin load-all-then-store-all so a later DAG combine cannot silently
+; reintroduce store-before-load.
+define void @memmove_overlap_12(ptr %dst, ptr %src) {
+; CHECK-LABEL: memmove_overlap_12:
+; CHECK: # %bb.0:
+; CHECK-NEXT: lw [[L0:.*]], 0(a1)
+; CHECK-NEXT: lw [[L4:.*]], 4(a1)
+; CHECK-NEXT: lw [[L8:.*]], 8(a1)
+; CHECK-NEXT: sw [[L0]], 0(a0)
+; CHECK-NEXT: sw [[L4]], 4(a0)
+; CHECK-NEXT: sw [[L8]], 8(a0)
+; CHECK-NEXT: ret
+entry:
+ tail call void @llvm.memmove.p0.p0.i32(ptr align 16 %dst, ptr align 8 %src, i32 12, i1 false)
+ ret void
+}
+declare void @llvm.memmove.p0.p0.i32(ptr, ptr, i32, i1)
More information about the llvm-commits
mailing list