[llvm] r362298 - [AVR] Disable register coalescing to the PTRDISPREGS class

Dylan McKay via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 1 05:38:56 PDT 2019


Author: dylanmckay
Date: Sat Jun  1 05:38:56 2019
New Revision: 362298

URL: http://llvm.org/viewvc/llvm-project?rev=362298&view=rev
Log:
[AVR] Disable register coalescing to the PTRDISPREGS class

If we would allow register coalescing on PTRDISPREGS class then register
allocator can lock Z register to some virtual register. Larger instructions
requiring a memory acces then fail during the register allocation phase since
there is no available register to hold a pointer if Y register was already
taken for a stack frame. This patch prevents it by keeping Z register
spillable. It does it by not allowing coalescer to lock it.

Original discussion on https://github.com/avr-rust/rust/issues/128.

Modified:
    llvm/trunk/lib/Target/AVR/AVRRegisterInfo.cpp
    llvm/trunk/lib/Target/AVR/AVRRegisterInfo.h
    llvm/trunk/test/CodeGen/AVR/PR37143.ll
    llvm/trunk/test/CodeGen/AVR/store.ll

Modified: llvm/trunk/lib/Target/AVR/AVRRegisterInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AVR/AVRRegisterInfo.cpp?rev=362298&r1=362297&r2=362298&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AVR/AVRRegisterInfo.cpp (original)
+++ llvm/trunk/lib/Target/AVR/AVRRegisterInfo.cpp Sat Jun  1 05:38:56 2019
@@ -16,6 +16,7 @@
 #include "llvm/CodeGen/MachineFrameInfo.h"
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/MachineInstrBuilder.h"
+#include "llvm/CodeGen/MachineRegisterInfo.h"
 #include "llvm/IR/Function.h"
 #include "llvm/CodeGen/TargetFrameLowering.h"
 
@@ -272,4 +273,18 @@ void AVRRegisterInfo::splitReg(unsigned
     HiReg = getSubReg(Reg, AVR::sub_hi);
 }
 
+bool AVRRegisterInfo::shouldCoalesce(MachineInstr *MI,
+                                     const TargetRegisterClass *SrcRC,
+                                     unsigned SubReg,
+                                     const TargetRegisterClass *DstRC,
+                                     unsigned DstSubReg,
+                                     const TargetRegisterClass *NewRC,
+                                     LiveIntervals &LIS) const {
+  if(this->getRegClass(AVR::PTRDISPREGSRegClassID)->hasSubClassEq(NewRC)) {
+    return false;
+  }
+
+  return TargetRegisterInfo::shouldCoalesce(MI, SrcRC, SubReg, DstRC, DstSubReg, NewRC, LIS);
+}
+
 } // end of namespace llvm

Modified: llvm/trunk/lib/Target/AVR/AVRRegisterInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AVR/AVRRegisterInfo.h?rev=362298&r1=362297&r2=362298&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AVR/AVRRegisterInfo.h (original)
+++ llvm/trunk/lib/Target/AVR/AVRRegisterInfo.h Sat Jun  1 05:38:56 2019
@@ -55,6 +55,13 @@ public:
     return true;
   }
 
+  bool shouldCoalesce(MachineInstr *MI,
+                      const TargetRegisterClass *SrcRC,
+                      unsigned SubReg,
+                      const TargetRegisterClass *DstRC,
+                      unsigned DstSubReg,
+                      const TargetRegisterClass *NewRC,
+                      LiveIntervals &LIS) const override;
 };
 
 } // end namespace llvm

Modified: llvm/trunk/test/CodeGen/AVR/PR37143.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AVR/PR37143.ll?rev=362298&r1=362297&r2=362298&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AVR/PR37143.ll (original)
+++ llvm/trunk/test/CodeGen/AVR/PR37143.ll Sat Jun  1 05:38:56 2019
@@ -1,9 +1,9 @@
 ; RUN: llc -mattr=avr6,sram < %s -march=avr | FileCheck %s
 
-; CHECK: ld {{r[0-9]+}}, [[PTR:[YZ]]]
+; CHECK: ld {{r[0-9]+}}, [[PTR:[XYZ]]]
 ; CHECK: ldd {{r[0-9]+}}, [[PTR]]+1
-; CHECK: st [[PTR]], {{r[0-9]+}}
-; CHECK: std [[PTR]]+1, {{r[0-9]+}}
+; CHECK: st [[PTR2:[XYZ]]], {{r[0-9]+}}
+; CHECK: std [[PTR2]]+1, {{r[0-9]+}}
 define void @load_store_16(i16* nocapture %ptr) local_unnamed_addr #1 {
 entry:
   %0 = load i16, i16* %ptr, align 2

Modified: llvm/trunk/test/CodeGen/AVR/store.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AVR/store.ll?rev=362298&r1=362297&r2=362298&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AVR/store.ll (original)
+++ llvm/trunk/test/CodeGen/AVR/store.ll Sat Jun  1 05:38:56 2019
@@ -45,9 +45,9 @@ define void @store16disp(i16* %x, i16 %y
 
 define void @store16nodisp(i16* %x, i16 %y) {
 ; CHECK-LABEL: store16nodisp:
+; CHECK: subi r24, 192
+; CHECK: sbci r25, 255
 ; CHECK: movw r30, r24
-; CHECK: subi r30, 192
-; CHECK: sbci r31, 255
 ; CHECK: st {{[YZ]}}, r22
 ; CHECK: std {{[YZ]}}+1, r23
   %arrayidx = getelementptr inbounds i16, i16* %x, i16 32




More information about the llvm-commits mailing list