Skip to content

Commit 6196828

Browse files
authored
[polly][ScheduleOptimizer] Reland Fix long compile time(hang) reported in polly (#77280)
There is no upper cap set on current Schedule Optimizer to compute schedule. In some cases a very long compile time taken to compute the schedule resulting in hang kind of behavior. This patch introduces a flag 'polly-schedule-computeout' to pass the capwhich is initialized to 300000. This patch handles the compute out cases by bailing out and exiting gracefully. Fixed the test that failed in previous commit. Fixes #69090
1 parent a146505 commit 6196828

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

polly/lib/Transform/ScheduleOptimizer.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ static cl::opt<std::string>
9696
cl::desc("Maximize the band depth (yes/no)"), cl::Hidden,
9797
cl::init("yes"), cl::cat(PollyCategory));
9898

99+
static cl::opt<int>
100+
ScheduleComputeOut("polly-schedule-computeout",
101+
cl::desc("Bound the scheduler by maximal amount"
102+
"of computational steps. "),
103+
cl::Hidden, cl::init(300000), cl::ZeroOrMore,
104+
cl::cat(PollyCategory));
105+
99106
static cl::opt<bool>
100107
GreedyFusion("polly-loopfusion-greedy",
101108
cl::desc("Aggressively try to fuse everything"), cl::Hidden,
@@ -860,7 +867,25 @@ static void runIslScheduleOptimizer(
860867
SC = SC.set_proximity(Proximity);
861868
SC = SC.set_validity(Validity);
862869
SC = SC.set_coincidence(Validity);
870+
871+
// Save error handling behavior
872+
long MaxOperations = isl_ctx_get_max_operations(Ctx);
873+
isl_ctx_set_max_operations(Ctx, ScheduleComputeOut);
863874
Schedule = SC.compute_schedule();
875+
bool ScheduleQuota = false;
876+
if (isl_ctx_last_error(Ctx) == isl_error_quota) {
877+
isl_ctx_reset_error(Ctx);
878+
LLVM_DEBUG(
879+
dbgs() << "Schedule optimizer calculation exceeds ISL quota\n");
880+
ScheduleQuota = true;
881+
}
882+
isl_options_set_on_error(Ctx, ISL_ON_ERROR_ABORT);
883+
isl_ctx_reset_operations(Ctx);
884+
isl_ctx_set_max_operations(Ctx, MaxOperations);
885+
886+
if (ScheduleQuota)
887+
return;
888+
864889
isl_options_set_on_error(Ctx, OnErrorStatus);
865890

866891
ScopsRescheduled++;
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
; RUN: opt %loadPolly -S -polly-optree -polly-delicm -polly-opt-isl -polly-schedule-computeout=100000 -debug-only="polly-opt-isl" < %s 2>&1 | FileCheck %s
2+
; REQUIRES: asserts
3+
4+
; Bailout if the computations of schedule compute exceeds the max scheduling quota.
5+
; Max compute out is initialized to 300000, Here it is set to 100000 for test purpose.
6+
7+
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
8+
target triple = "aarch64-unknown-linux-gnu"
9+
10+
@a = dso_local local_unnamed_addr global ptr null, align 8
11+
@b = dso_local local_unnamed_addr global ptr null, align 8
12+
@c = dso_local local_unnamed_addr global ptr null, align 8
13+
14+
define dso_local void @foo(i32 noundef %I, i32 noundef %J, i32 noundef %K1, i32 noundef %K2, i32 noundef %L1, i32 noundef %L2) local_unnamed_addr {
15+
entry:
16+
%j = alloca i32, align 4
17+
store volatile i32 0, ptr %j, align 4
18+
%j.0.j.0.j.0.54 = load volatile i32, ptr %j, align 4
19+
%cmp55 = icmp slt i32 %j.0.j.0.j.0.54, %J
20+
br i1 %cmp55, label %for.body.lr.ph, label %for.cond.cleanup
21+
22+
for.body.lr.ph: ; preds = %entry
23+
%0 = load ptr, ptr @a, align 8
24+
%1 = load ptr, ptr @b, align 8
25+
%2 = load ptr, ptr %1, align 8
26+
%cmp352 = icmp slt i32 %L1, %L2
27+
%cmp750 = icmp slt i32 %K1, %K2
28+
%3 = sext i32 %K1 to i64
29+
%4 = sext i32 %L1 to i64
30+
br label %for.body
31+
32+
for.cond.cleanup: ; preds = %for.cond.cleanup4, %entry
33+
ret void
34+
35+
for.body: ; preds = %for.cond.cleanup4, %for.body.lr.ph
36+
br i1 %cmp352, label %for.cond6.preheader.preheader, label %for.cond.cleanup4
37+
38+
for.cond6.preheader.preheader: ; preds = %for.body
39+
%wide.trip.count66 = sext i32 %L2 to i64
40+
br label %for.cond6.preheader
41+
42+
for.cond6.preheader: ; preds = %for.cond.cleanup8, %for.cond6.preheader.preheader
43+
%indvars.iv61 = phi i64 [ %4, %for.cond6.preheader.preheader ], [ %indvars.iv.next62, %for.cond.cleanup8 ]
44+
br i1 %cmp750, label %for.cond10.preheader.lr.ph, label %for.cond.cleanup8
45+
46+
for.cond10.preheader.lr.ph: ; preds = %for.cond6.preheader
47+
%5 = mul nsw i64 %indvars.iv61, 516
48+
%6 = mul nsw i64 %indvars.iv61, 516
49+
%wide.trip.count = sext i32 %K2 to i64
50+
br label %for.cond10.preheader
51+
52+
for.cond.cleanup4: ; preds = %for.cond.cleanup8, %for.body
53+
%j.0.j.0.j.0.45 = load volatile i32, ptr %j, align 4
54+
%inc34 = add nsw i32 %j.0.j.0.j.0.45, 1
55+
store volatile i32 %inc34, ptr %j, align 4
56+
%j.0.j.0.j.0. = load volatile i32, ptr %j, align 4
57+
%cmp = icmp slt i32 %j.0.j.0.j.0., %J
58+
br i1 %cmp, label %for.body, label %for.cond.cleanup
59+
60+
for.cond10.preheader: ; preds = %for.cond.cleanup12, %for.cond10.preheader.lr.ph
61+
%indvars.iv = phi i64 [ %3, %for.cond10.preheader.lr.ph ], [ %indvars.iv.next, %for.cond.cleanup12 ]
62+
%7 = getelementptr float, ptr %0, i64 %indvars.iv
63+
%arrayidx18 = getelementptr float, ptr %7, i64 %5
64+
%8 = load float, ptr %arrayidx18, align 4
65+
br label %for.cond14.preheader
66+
67+
for.cond.cleanup8: ; preds = %for.cond.cleanup12, %for.cond6.preheader
68+
%indvars.iv.next62 = add nsw i64 %indvars.iv61, 1
69+
%exitcond67.not = icmp eq i64 %indvars.iv.next62, %wide.trip.count66
70+
br i1 %exitcond67.not, label %for.cond.cleanup4, label %for.cond6.preheader
71+
72+
for.cond14.preheader: ; preds = %for.cond.cleanup16, %for.cond10.preheader
73+
%m.049 = phi i32 [ -2, %for.cond10.preheader ], [ %inc21, %for.cond.cleanup16 ]
74+
%sum.048 = phi float [ 0.000000e+00, %for.cond10.preheader ], [ %add19, %for.cond.cleanup16 ]
75+
br label %for.body17
76+
77+
for.cond.cleanup12: ; preds = %for.cond.cleanup16
78+
%9 = getelementptr float, ptr %2, i64 %indvars.iv
79+
%arrayidx26 = getelementptr float, ptr %9, i64 %6
80+
store float %add19, ptr %arrayidx26, align 4
81+
%indvars.iv.next = add nsw i64 %indvars.iv, 1
82+
%exitcond60.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
83+
br i1 %exitcond60.not, label %for.cond.cleanup8, label %for.cond10.preheader
84+
85+
for.cond.cleanup16: ; preds = %for.body17
86+
%inc21 = add nsw i32 %m.049, 1
87+
%exitcond56.not = icmp eq i32 %inc21, 3
88+
br i1 %exitcond56.not, label %for.cond.cleanup12, label %for.cond14.preheader
89+
90+
for.body17: ; preds = %for.body17, %for.cond14.preheader
91+
%n.047 = phi i32 [ -2, %for.cond14.preheader ], [ %inc, %for.body17 ]
92+
%sum.146 = phi float [ %sum.048, %for.cond14.preheader ], [ %add19, %for.body17 ]
93+
%add19 = fadd float %sum.146, %8
94+
%inc = add nsw i32 %n.047, 1
95+
%exitcond.not = icmp eq i32 %inc, 3
96+
br i1 %exitcond.not, label %for.cond.cleanup16, label %for.body17
97+
}
98+
99+
; CHECK: Schedule optimizer calculation exceeds ISL quota

0 commit comments

Comments
 (0)