Skip to content

Conversation

@tomershafir
Copy link
Contributor

@tomershafir tomershafir commented Nov 24, 2025

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.

@tomershafir tomershafir force-pushed the aarch64-assert-expand-imm-priority branch from 43e7361 to 9a2e070 Compare November 24, 2025 15:29
@tomershafir tomershafir changed the title [AArch64] Assert that expandMOVImm prioritizes optimal single MOVZ/… [AArch64] Assert expandMOVImm prioritizes optimal single MOVZ/N Nov 24, 2025
@github-actions
Copy link

github-actions bot commented Nov 24, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@tomershafir tomershafir force-pushed the aarch64-assert-expand-imm-priority branch from 9a2e070 to ab50da9 Compare November 24, 2025 15:32
@tomershafir tomershafir marked this pull request as ready for review November 24, 2025 16:21
@llvmbot
Copy link
Member

llvmbot commented Nov 24, 2025

@llvm/pr-subscribers-backend-aarch64

Author: Tomer Shafir (tomershafir)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/169341.diff

1 Files Affected:

  • (modified) llvm/lib/Target/AArch64/AArch64ExpandImm.cpp (+2)
diff --git a/llvm/lib/Target/AArch64/AArch64ExpandImm.cpp b/llvm/lib/Target/AArch64/AArch64ExpandImm.cpp
index e9660ac140301..ae5818419cba5 100644
--- a/llvm/lib/Target/AArch64/AArch64ExpandImm.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ExpandImm.cpp
@@ -549,6 +549,8 @@ 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;
   }
 

Copy link
Collaborator

@efriedma-quic efriedma-quic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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/N.
@tomershafir tomershafir force-pushed the aarch64-assert-expand-imm-priority branch from ab50da9 to 54f500f Compare November 25, 2025 08:04
@tomershafir tomershafir merged commit 6193f2a into llvm:main Nov 25, 2025
10 checks passed
@tomershafir tomershafir deleted the aarch64-assert-expand-imm-priority branch November 25, 2025 08:48
aadeshps-mcw pushed a commit to aadeshps-mcw/llvm-project that referenced this pull request Nov 26, 2025
…vm#169341)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants