[PATCH] D12811: RegAllocGreedy: Fix crash when setting CostPerUse

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 11 12:20:07 PDT 2015

arsenm created this revision.
arsenm added reviewers: qcolombet, MatzeB.
arsenm added a subscriber: llvm-commits.
Herald added subscribers: qcolombet, MatzeB.

When CostPerUse is non-zero and tryAssign was attempting
to assign an undef VirtReg, the empty VirtReg LiveInterval would
assert in intervalIsInOneMBB.
This happens when I attempt to make the cost of all registers
except VCC have a CostPerUse of 1 on AMDGPU.
I'm not sure I will ever commit that change, because I'm not sure
it's exactly what I want. This results in overly aggressive
VCC usage instead of the relatively few operands where it is
advantageous to use it.
The testcase is the simplest case I've found where this happens
from a branch on undef, but only with the CopyCost change applied.



Index: test/CodeGen/AMDGPU/branch-on-undef.ll
--- /dev/null
+++ test/CodeGen/AMDGPU/branch-on-undef.ll
@@ -0,0 +1,14 @@
+; RUN: llc -march=amdgcn -verify-machineinstrs < %s
+define void @undef_br(i32 addrspace(1)* %ptr) nounwind {
+  br i1 undef, label %exit, label %bb
+  store volatile i32 0, i32 addrspace(1)* %ptr
+  br label %exit
+  ret void
Index: lib/CodeGen/RegAllocGreedy.cpp
--- lib/CodeGen/RegAllocGreedy.cpp
+++ lib/CodeGen/RegAllocGreedy.cpp
@@ -726,7 +726,7 @@
   if (Matrix->checkInterference(VirtReg, PhysReg) > LiveRegMatrix::IK_VirtReg)
     return false;
-  bool IsLocal = LIS->intervalIsInOneMBB(VirtReg);
+  bool IsLocal = VirtReg.empty() || LIS->intervalIsInOneMBB(VirtReg);
   // Find VirtReg's cascade number. This will be unassigned if VirtReg was never
   // involved in an eviction before. If a cascade number was assigned, deny

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12811.34570.patch
Type: text/x-patch
Size: 1028 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150911/f008c9de/attachment.bin>

More information about the llvm-commits mailing list