Skip to content

Commit b6fce59

Browse files
committed
[polly] Bound ISL operations during pre-vectorization
Bound ISL operations during pre-vectorization to prevent indefinite compilation. If the bound fails, mark the SCoP invalid. Includes relevant unit test. Fixes #132717.
1 parent fe28ea3 commit b6fce59

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

polly/lib/Transform/ScheduleOptimizer.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ ScheduleTreeOptimizer::isolateFullPartialTiles(isl::schedule_node Node,
387387
isl::union_set ScheduleRangeUSet = SchedRelUMap.range();
388388
isl::set ScheduleRange{ScheduleRangeUSet};
389389
isl::set IsolateDomain = getPartialTilePrefixes(ScheduleRange, VectorWidth);
390+
if (IsolateDomain.is_null())
391+
return isl::schedule_node();
390392
auto AtomicOption = getDimOptions(IsolateDomain.ctx(), "atomic");
391393
isl::union_set IsolateOption = getIsolateOptions(IsolateDomain, 1);
392394
Node = Node.parent().parent();
@@ -430,6 +432,8 @@ isl::schedule_node ScheduleTreeOptimizer::prevectSchedBand(
430432
Node =
431433
isl::manage(isl_schedule_node_band_tile(Node.release(), Sizes.release()));
432434
Node = isolateFullPartialTiles(Node, VectorWidth);
435+
if (Node.is_null())
436+
return isl::schedule_node();
433437
Node = Node.child(0);
434438
// Make sure the "trivially vectorizable loop" is not unrolled. Otherwise,
435439
// we will have troubles to match it in the backend.
@@ -543,6 +547,8 @@ ScheduleTreeOptimizer::applyPrevectBandOpt(isl::schedule_node Node) {
543547
break;
544548
}
545549

550+
if (Node.is_null())
551+
return isl::schedule_node();
546552
return Node;
547553
}
548554

@@ -574,7 +580,12 @@ ScheduleTreeOptimizer::optimizeBand(__isl_take isl_schedule_node *NodeArg,
574580
if (OAI->Prevect) {
575581
// FIXME: Prevectorization requirements are different from those checked by
576582
// isTileableBandNode.
577-
Node = applyPrevectBandOpt(Node);
583+
{
584+
IslMaxOperationsGuard MaxOpGuard(Node.ctx().get(), ScheduleComputeOut);
585+
Node = applyPrevectBandOpt(Node);
586+
if (MaxOpGuard.hasQuotaExceeded() || Node.is_null())
587+
return (isl::schedule_node()).release();
588+
}
578589
}
579590

580591
return Node.release();
@@ -585,6 +596,8 @@ ScheduleTreeOptimizer::optimizeSchedule(isl::schedule Schedule,
585596
const OptimizerAdditionalInfoTy *OAI) {
586597
auto Root = Schedule.get_root();
587598
Root = optimizeScheduleNode(Root, OAI);
599+
if (Root.is_null())
600+
return isl::schedule();
588601
return Root.get_schedule();
589602
}
590603

@@ -593,6 +606,8 @@ isl::schedule_node ScheduleTreeOptimizer::optimizeScheduleNode(
593606
Node = isl::manage(isl_schedule_node_map_descendant_bottom_up(
594607
Node.release(), optimizeBand,
595608
const_cast<void *>(static_cast<const void *>(OAI))));
609+
if (Node.is_null())
610+
return isl::schedule_node();
596611
return Node;
597612
}
598613

@@ -908,6 +923,12 @@ static void runIslScheduleOptimizer(
908923
DepsChanged};
909924
if (OAI.PatternOpts || OAI.Postopts || OAI.Prevect) {
910925
Schedule = ScheduleTreeOptimizer::optimizeSchedule(Schedule, &OAI);
926+
if (Schedule.is_null()) {
927+
POLLY_DEBUG(dbgs() << "Invalidating scop from further optimization as "
928+
"max operations exceeded\n");
929+
S.invalidate(COMPLEXITY, DebugLoc());
930+
return;
931+
}
911932
Schedule = hoistExtensionNodes(Schedule);
912933
POLLY_DEBUG(printSchedule(dbgs(), Schedule, "After post-optimizations"));
913934
walkScheduleTreeForStatistics(Schedule, 2);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
; RUN: opt %loadNPMPolly -S "-polly-vectorizer=stripmine" -polly-opt-isl -polly-debug -disable-output < %s 2>&1 | FileCheck %s
2+
; REQUIRES: asserts
3+
; ModuleID = '<stdin>'
4+
source_filename = "<stdin>"
5+
target datalayout = "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i128:128-f64:32:64-f80:32-n8:16:32-S128"
6+
target triple = "i386-unknown-linux-gnu"
7+
8+
define void @ham(ptr %arg, ptr %arg1, i32 %arg2, i32 %arg3, ptr %arg4, i32 %arg5, i32 %arg6) {
9+
bb:
10+
%getelementptr = getelementptr [7 x float], ptr null, i32 0, i32 %arg3
11+
br label %bb7
12+
13+
bb7: ; preds = %bb11, %bb
14+
%phi = phi i32 [ 0, %bb ], [ %add16, %bb11 ]
15+
br label %bb8
16+
17+
bb8: ; preds = %bb8, %bb7
18+
%phi9 = phi i32 [ 0, %bb7 ], [ %add, %bb8 ]
19+
%getelementptr10 = getelementptr [7 x float], ptr null, i32 0, i32 %phi9
20+
store float 0.000000e+00, ptr %getelementptr10, align 4
21+
%add = add i32 %phi9, 1
22+
%icmp = icmp eq i32 %phi9, 0
23+
br i1 %icmp, label %bb8, label %bb11
24+
25+
bb11: ; preds = %bb8
26+
%load = load float, ptr %getelementptr, align 4
27+
store float %load, ptr %arg4, align 4
28+
%getelementptr12 = getelementptr [7 x float], ptr null, i32 0, i32 %arg5
29+
%load13 = load float, ptr %getelementptr12, align 4
30+
store float %load13, ptr %arg, align 4
31+
%getelementptr14 = getelementptr [7 x float], ptr null, i32 0, i32 %arg6
32+
%load15 = load float, ptr %getelementptr14, align 4
33+
store float %load15, ptr %arg1, align 4
34+
%add16 = add i32 %phi, 1
35+
%icmp17 = icmp ne i32 %phi, %arg2
36+
br i1 %icmp17, label %bb7, label %bb18
37+
38+
bb18: ; preds = %bb11
39+
ret void
40+
}
41+
; CHECK:Invalidating scop from further optimization as max operations exceeded

0 commit comments

Comments
 (0)