[llvm] [RegisterCoalescer] Don't commute two-address instructions which only define a subregister (PR #169031)

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 21 07:46:05 PST 2025


================
@@ -869,6 +869,14 @@ RegisterCoalescer::removeCopyByCommutingDef(const CoalescerPair &CP,
   if (!DefMI->isRegTiedToUseOperand(DefIdx, &UseOpIdx))
     return {false, false};
 
+  // If DefMI only defines the register partially, we can't replace uses of the
+  // full register with the new destination register after commuting it.
+  if (IntA.reg().isVirtual() &&
+      none_of(DefMI->all_defs(), [&](const MachineOperand &DefMO) {
----------------
KRM7 wrote:

The intention of going over all the defs is to still allowing commuting instructions which have an implicit def for the entire register, e.g.:
```
%0.sub_lo32:gpr64 = AND %0.sub_lo32:gpr64(tied-def 0), %1.sub_lo32:gpr64, implicit-def %0
```

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


More information about the llvm-commits mailing list