Matt Arsenault 4a36e96c3f RegAllocGreedy: Account for reserved registers in num regs heuristic
This simple heuristic uses the estimated live range length combined
with the number of registers in the class to switch which heuristic to
use. This was taking the raw number of registers in the class, even
though not all of them may be available. AMDGPU heavily relies on
dynamically reserved numbers of registers based on user attributes to
satisfy occupancy constraints, so the raw number is highly misleading.

There are still a few problems here. In the original testcase that
made me notice this, the live range size is incorrect after the
scheduler rearranges instructions, since the instructions don't have
the original InstrDist offsets. Additionally, I think it would be more
appropriate to use the number of disjointly allocatable registers in
the class. For the AMDGPU register tuples, there are a large number of
registers in each tuple class, but only a small fraction can actually
be allocated at the same time since they all overlap with each
other. It seems we do not have a query that corresponds to the number
of independently allocatable registers. Relatedly, I'm still debugging
some allocation failures where overlapping tuples seem to not be
handled correctly.

The test changes are mostly noise. There are a handful of x86 tests
that look like regressions with an additional spill, and a handful
that now avoid a spill. The worst looking regression is likely
test/Thumb2/mve-vld4.ll which introduces a few additional
spills. test/CodeGen/AMDGPU/soft-clause-exceeds-register-budget.ll
shows a massive improvement by completely eliminating a large number
of spills inside a loop.
2021-09-14 21:00:29 -04:00

62 lines
2.5 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
; RUN: llc -mtriple=i386-apple-macosx10.13.0 -o - %s | FileCheck %s
target datalayout = "e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128"
@c = external local_unnamed_addr global i32, align 4
@b = external local_unnamed_addr global [1 x i32], align 4
@d = external local_unnamed_addr global i32, align 4
define void @pr32610(i32 %a0, i32 %a1) #0 {
; CHECK-LABEL: pr32610:
; CHECK: ## %bb.0: ## %entry
; CHECK-NEXT: pushl %ebp
; CHECK-NEXT: movl %esp, %ebp
; CHECK-NEXT: pushl %esi
; CHECK-NEXT: movl 8(%ebp), %edx
; CHECK-NEXT: movl L_b$non_lazy_ptr, %eax
; CHECK-NEXT: xorl %ecx, %ecx
; CHECK-NEXT: cmpl (%eax), %edx
; CHECK-NEXT: sete %cl
; CHECK-NEXT: xorl %esi, %esi
; CHECK-NEXT: incl %esi
; CHECK-NEXT: cmpl $0, 12(%ebp)
; CHECK-NEXT: cmovel %esi, %ecx
; CHECK-NEXT: cmpl (%eax), %edx
; CHECK-NEXT: cmovnel %esi, %ecx
; CHECK-NEXT: movl L_c$non_lazy_ptr, %edx
; CHECK-NEXT: movl %ecx, (%edx)
; CHECK-NEXT: movl (%eax), %eax
; CHECK-NEXT: testl %eax, %eax
; CHECK-NEXT: movl $2, %ecx
; CHECK-NEXT: cmovnel %eax, %ecx
; CHECK-NEXT: movl L_d$non_lazy_ptr, %eax
; CHECK-NEXT: movl %ecx, (%eax)
; CHECK-NEXT: popl %esi
; CHECK-NEXT: popl %ebp
; CHECK-NEXT: retl
entry:
%0 = load i32, i32* getelementptr ([1 x i32], [1 x i32]* @b, i32 0, i32 undef), align 4, !tbaa !1
%cmp = icmp eq i32 %a0, %0
%conv = zext i1 %cmp to i32
%tobool1.i = icmp ne i32 %a1, 0
%or.cond.i = and i1 %cmp, %tobool1.i
%cond.i = select i1 %or.cond.i, i32 %conv, i32 1
store i32 %cond.i, i32* @c, align 4, !tbaa !1
%1 = load i32, i32* getelementptr inbounds ([1 x i32], [1 x i32]* @b, i32 0, i32 0), align 4
%tobool = icmp ne i32 %1, 0
%2 = select i1 %tobool, i32 %1, i32 2
store i32 %2, i32* @d, align 4, !tbaa !1
ret void
}
attributes #0 = { norecurse nounwind optsize ssp "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="penryn" "target-features"="+cx16,+fxsr,+mmx,+sse,+sse2,+sse3,+sse4.1,+ssse3,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
!llvm.ident = !{!0}
!0 = !{!"clang version 5.0.0 (trunk 301507) (llvm/trunk 301505)"}
!1 = !{!2, !2, i64 0}
!2 = !{!"int", !3, i64 0}
!3 = !{!"omnipotent char", !4, i64 0}
!4 = !{!"Simple C/C++ TBAA"}