[llvm] [AArch64] Assert that `expandMOVImm` prioritizes optimal single MOVZ/… (PR #169341)

Tomer Shafir via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 24 07:29:39 PST 2025


https://github.com/tomershafir updated https://github.com/llvm/llvm-project/pull/169341

>From 9a2e070a33521eae956987dfb5845ce7a1351027 Mon Sep 17 00:00:00 2001
From: tomershafir <tomer.shafir8 at gmail.com>
Date: Mon, 24 Nov 2025 17:19:03 +0200
Subject: [PATCH] [AArch64] Assert `expandMOVImm` prioritizes optimal single
 MOVZ/N

The expansion of move immediate in `expandMOVImm` follows the priority of the `MOV` alias. In addition, the selection there properly prefers expansion based on perf optimality order. This change adds a simple assert that `expandMOVImmSimple` expands a single optimal MOVZ/MOVK.
---
 llvm/lib/Target/AArch64/AArch64ExpandImm.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/llvm/lib/Target/AArch64/AArch64ExpandImm.cpp b/llvm/lib/Target/AArch64/AArch64ExpandImm.cpp
index e9660ac140301..89d58b71e413e 100644
--- a/llvm/lib/Target/AArch64/AArch64ExpandImm.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ExpandImm.cpp
@@ -549,6 +549,7 @@ void AArch64_IMM::expandMOVImm(uint64_t Imm, unsigned BitSize,
   // Prefer MOVZ/MOVN over ORR because of the rules for the "mov" alias.
   if ((BitSize / 16) - OneChunks <= 1 || (BitSize / 16) - ZeroChunks <= 1) {
     expandMOVImmSimple(Imm, BitSize, OneChunks, ZeroChunks, Insn);
+    assert(Insn.size() == 1 && "Move of immediate should have expanded to a single MOVZ/MOVN");
     return;
   }
 



More information about the llvm-commits mailing list