Skip to content

Commit 350ff2c

Browse files
committed
Fix PR18572 - llc crash during GenericScheduler::initPolicy().
Generalized the heuristic that looks at the (very rough) size of the register file before enabling regpressure tracking. llvm-svn: 199766
1 parent 8340592 commit 350ff2c

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

llvm/lib/CodeGen/MachineScheduler.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,10 +2531,16 @@ void GenericScheduler::initPolicy(MachineBasicBlock::iterator Begin,
25312531
// Avoid setting up the register pressure tracker for small regions to save
25322532
// compile time. As a rough heuristic, only track pressure when the number of
25332533
// schedulable instructions exceeds half the integer register file.
2534-
unsigned NIntRegs = Context->RegClassInfo->getNumAllocatableRegs(
2535-
TM.getTargetLowering()->getRegClassFor(MVT::i32));
2536-
2537-
RegionPolicy.ShouldTrackPressure = NumRegionInstrs > (NIntRegs / 2);
2534+
RegionPolicy.ShouldTrackPressure = true;
2535+
unsigned LegalIntVT = MVT::i32;
2536+
for (; LegalIntVT > (unsigned)MVT::i1; --LegalIntVT) {
2537+
if (TM.getTargetLowering()->isTypeLegal((MVT::SimpleValueType)LegalIntVT)) {
2538+
unsigned NIntRegs = Context->RegClassInfo->getNumAllocatableRegs(
2539+
TM.getTargetLowering()->getRegClassFor(
2540+
(MVT::SimpleValueType)LegalIntVT));
2541+
RegionPolicy.ShouldTrackPressure = NumRegionInstrs > (NIntRegs / 2);
2542+
}
2543+
}
25382544

25392545
// For generic targets, we default to bottom-up, because it's simpler and more
25402546
// compile-time optimizations have been implemented in that direction.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: llc < %s -mtriple=msp430-unknown-unknown -enable-misched | FileCheck %s
2+
3+
target datalayout = "e-p:16:16:16-i8:8:8-i16:16:16-i32:16:32-n8:16"
4+
5+
@y = common global i16 0, align 2
6+
@x = common global i16 0, align 2
7+
8+
; Test that the MI Scheduler's initPolicy does not crash when i32 is
9+
; unsupported. The content of the asm check below is unimportant. It
10+
; only verifies that the code generator ran succesfully.
11+
;
12+
; CHECK-LABEL: @f
13+
; CHECK: mov.w &y, &x
14+
; CHECK: ret
15+
define void @f() {
16+
entry:
17+
%0 = load i16* @y, align 2
18+
store i16 %0, i16* @x, align 2
19+
ret void
20+
}

0 commit comments

Comments
 (0)