RegisterCoalescer: Remap subregister lanemasks before exchanging operands
authorMatthias Braun <matze@braunis.de>
Sat, 5 Mar 2016 04:36:13 +0000 (04:36 +0000)
committerMatthias Braun <matze@braunis.de>
Sat, 5 Mar 2016 04:36:13 +0000 (04:36 +0000)
Rematerializing and merging into a bigger register class at the same
time, requires the subregister range lanemasks getting remapped to the
new register class.

This fixes http://llvm.org/PR26805

llvm-svn: 262768

llvm/lib/CodeGen/RegisterCoalescer.cpp
llvm/test/CodeGen/AMDGPU/reg-coalescer-sched-crash.ll

index 7855d2b..18cbad5 100644 (file)
@@ -1007,8 +1007,14 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
         NewRC = TRI->getCommonSubClass(NewRC, DefRC);
       assert(NewRC && "subreg chosen for remat incompatible with instruction");
     }
+    // Remap subranges to new lanemask and change register class.
+    LiveInterval &DstInt = LIS->getInterval(DstReg);
+    for (LiveInterval::SubRange &SR : DstInt.subranges()) {
+      SR.LaneMask = TRI->composeSubRegIndexLaneMask(DstIdx, SR.LaneMask);
+    }
     MRI->setRegClass(DstReg, NewRC);
 
+    // Update machine operands and add flags.
     updateRegDefsUses(DstReg, DstReg, DstIdx);
     NewMI->getOperand(0).setSubReg(NewIdx);
     // Add dead subregister definitions if we are defining the whole register
@@ -1025,7 +1031,6 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
     //
     // at this point for the part that wasn't defined before we could have
     // subranges missing the definition.
-    LiveInterval &DstInt = LIS->getInterval(DstReg);
     if (NewIdx == 0 && DstInt.hasSubRanges()) {
       SlotIndex CurrIdx = LIS->getInstructionIndex(*NewMI);
       SlotIndex DefIndex = CurrIdx.getRegSlot(NewMI->getOperand(0).isEarlyClobber());
index 2b7a4b2..6e95f4c 100644 (file)
@@ -1,6 +1,5 @@
-; XFAIL: *
-; RUN: llc -march=amdgcn -verify-machineinstrs < %s
-; XUN: llc -march=amdgcn -mcpu=tonga -verify-machineinstrs < %s
+; RUN: llc -march=amdgcn -verify-machineinstrs -o /dev/null < %s
+; RUN: llc -march=amdgcn -mcpu=tonga -verify-machineinstrs -o /dev/null < %s
 
 ; The register coalescer introduces a verifier error which later
 ; results in a crash during scheduling.