[llvm] [AMDGPU] Commute instructions to avoid VGPR MSB changes (PR #181918)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 18 10:47:53 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);
+ assert(CommutedInst && "Failed to restore commuted instruction.");
----------------
arsenm wrote:
```suggestion
if (!TII->commuteInstruction(MI))
llvm_unreachable("Failed to restore commuted instruction.");
```
https://github.com/llvm/llvm-project/pull/181918
More information about the llvm-commits
mailing list