[llvm] [AMDGPU] Commute instructions to avoid VGPR MSB changes (PR #181918)

Stanislav Mekhanoshin via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 18 10:57:14 PST 2026


================
@@ -276,6 +288,17 @@ bool AMDGPULowerVGPREncoding::runOnMachineInstr(MachineInstr &MI) {
   if (Ops.first) {
     ModeTy NewMode;
     computeMode(NewMode, MI, Ops.first, Ops.second);
+    if (!CurrentMode.isCompatible(NewMode) && MI.isCommutable() &&
+        TII->commuteInstruction(MI)) {
+      ModeTy NewModeCommuted;
+      computeMode(NewModeCommuted, MI, Ops.first, Ops.second);
+      if (CurrentMode.isCompatible(NewModeCommuted))
+        return false;
+      // Commute back.
+      [[maybe_unused]] MachineInstr *CommutedInst;
+      CommutedInst = TII->commuteInstruction(MI);
----------------
rampitec wrote:

Did it with llvm_unrecheable.

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


More information about the llvm-commits mailing list