Skip to content

Commit 18fc42a

Browse files
committed
Fix a bug in SelectionDAG scheduling backtracking code: PR22304.
It can happen (by line CurSU->isPending = true; // This SU is not in AvailableQueue right now.) that a SUnit is mark as available but is not in the AvailableQueue. For SUnit being selected for scheduling both conditions must be met. This patch mainly defensively protects from invalid removing a node from a queue. Sometimes nodes are marked isAvailable but are not in the queue because they have been defered due to some hazard. Patch by Pawel Bylica! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@233351 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent b3ad90e commit 18fc42a

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,9 +1423,10 @@ SUnit *ScheduleDAGRRList::PickNodeToScheduleBottomUp() {
14231423

14241424
// If one or more successors has been unscheduled, then the current
14251425
// node is no longer available.
1426-
if (!TrySU->isAvailable)
1426+
if (!TrySU->isAvailable || !TrySU->NodeQueueId)
14271427
CurSU = AvailableQueue->pop();
14281428
else {
1429+
// Available and in AvailableQueue
14291430
AvailableQueue->remove(TrySU);
14301431
CurSU = TrySU;
14311432
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
; RUN: llc < %s -pre-RA-sched=list-ilp | FileCheck %s
2+
; RUN: llc < %s -pre-RA-sched=list-hybrid | FileCheck %s
3+
; RUN: llc < %s -pre-RA-sched=source | FileCheck %s
4+
; RUN: llc < %s -pre-RA-sched=list-burr | FileCheck %s
5+
; RUN: llc < %s -pre-RA-sched=linearize | FileCheck %s
6+
7+
; PR22304 https://llvm.org/bugs/show_bug.cgi?id=22304
8+
; Tests checking backtracking in source scheduler. llc used to crash on them.
9+
10+
; CHECK-LABEL: test1
11+
define i256 @test1(i256 %a) {
12+
%b = add i256 %a, 1
13+
%m = shl i256 %b, 1
14+
%p = add i256 %m, 1
15+
%v = lshr i256 %b, %p
16+
%t = trunc i256 %v to i1
17+
%c = shl i256 1, %p
18+
%f = select i1 %t, i256 undef, i256 %c
19+
ret i256 %f
20+
}
21+
22+
; CHECK-LABEL: test2
23+
define i256 @test2(i256 %a) {
24+
%b = sub i256 0, %a
25+
%c = and i256 %b, %a
26+
%d = call i256 @llvm.ctlz.i256(i256 %c, i1 false)
27+
ret i256 %d
28+
}
29+
30+
; CHECK-LABEL: test3
31+
define i256 @test3(i256 %n) {
32+
%m = sub i256 -1, %n
33+
%x = sub i256 0, %n
34+
%y = and i256 %x, %m
35+
%z = call i256 @llvm.ctlz.i256(i256 %y, i1 false)
36+
ret i256 %z
37+
}
38+
39+
declare i256 @llvm.ctlz.i256(i256, i1) nounwind readnone
40+
41+
; CHECK-LABEL: test4
42+
define i64 @test4(i64 %a, i64 %b) {
43+
%r = zext i64 %b to i256
44+
%u = add i256 %r, 1
45+
%w = and i256 %u, 1461501637330902918203684832716283019655932542975
46+
%x = zext i64 %a to i256
47+
%c = icmp uge i256 %w, %x
48+
%y = select i1 %c, i64 0, i64 1
49+
%z = add i64 %y, 1
50+
ret i64 %z
51+
}

0 commit comments

Comments
 (0)