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

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 21 07:35:55 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) {
----------------
arsenm wrote:

I think this code assumes a single def anyway. Can you move this down where the DstOperand is handled? 

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


More information about the llvm-commits mailing list