[llvm] [AArch64MIPeepholeOpt] Coalesce sibling base-address materializations (PR #223682)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 15 19:46:28 PDT 2026
================
@@ -0,0 +1,207 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc -mtriple=aarch64 -verify-machineinstrs < %s | FileCheck %s --check-prefix=ENABLED
+; RUN: llc -mtriple=aarch64 -verify-machineinstrs -aarch64-base-address-cse=0 < %s | FileCheck %s --check-prefix=NOBASECSE
+;
+; End-to-end tests for the AArch64 base-address CSE peephole (item 8 in
+; AArch64MIPeepholeOpt). When ISel materializes a per-access SUBXri/ADDXri
+; base for far offsets it cannot fold into a single immediate, this pass
+; coalesces sibling materializations sharing a common source so that the
+; downstream load/store optimizer can form LDP/STP.
+;
+; The cases below use NEGATIVE far offsets, which (unlike positive far offsets)
+; cannot be expressed as a single unsigned scaled immediate and therefore
+; require base-address CSE to pair. With the pass disabled (-aarch64-base-address-cse=0,
+; NOBASECSE) the two accesses stay as separate sub+ldr/str with no LDP/STP.
+
+define void @ldp_neg_far_offset_i32(ptr %p) {
+; ENABLED-LABEL: ldp_neg_far_offset_i32:
+; ENABLED: // %bb.0:
+; ENABLED-NEXT: sub x8, x0, #400
+; ENABLED-NEXT: ldp w9, w8, [x8]
+; ENABLED-NEXT: str w9, [x8]
+; ENABLED-NEXT: str w8, [x8]
+; ENABLED-NEXT: ret
+;
+; NOBASECSE-LABEL: ldp_neg_far_offset_i32:
+; NOBASECSE: // %bb.0:
+; NOBASECSE-NEXT: sub x8, x0, #400
+; NOBASECSE-NEXT: sub x9, x0, #396
+; NOBASECSE-NEXT: ldr w8, [x8]
+; NOBASECSE-NEXT: ldr w9, [x9]
+; NOBASECSE-NEXT: str w8, [x8]
+; NOBASECSE-NEXT: str w9, [x8]
+; NOBASECSE-NEXT: ret
+ %gep0 = getelementptr i32, ptr %p, i64 -100
+ %gep1 = getelementptr i32, ptr %p, i64 -99
+ %v0 = load i32, ptr %gep0
+ %v1 = load i32, ptr %gep1
+ store volatile i32 %v0, ptr undef
----------------
whokeke wrote:
Fixed, replaced all new undef uses.
https://github.com/llvm/llvm-project/pull/223682
More information about the llvm-commits
mailing list