Skip to content

Commit 9b234b3

Browse files
committed
[Polly] Don't crash on invalid delinearization result.
In certain cases, it's possible for delinearization to decide one of the array dimensions should be some function of an induction variable inside the scop. Make sure if this happens, we refuse to use those dimensions for delinearization. Usually, we end up rejecting the scop before it actually crashes, but it looks like it's possible to slip past other checks in certain cases involving smax expressions. Fixes a crash that started showing up this week on the polly AOSP builder. As far as I can tell, this is a longstanding issue, though; it was just exposed by better SCEV analysis of smin expressions. Differential Revision: https://reviews.llvm.org/D61807 llvm-svn: 360708
1 parent 0cdd3b1 commit 9b234b3

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

polly/lib/Analysis/ScopDetection.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,9 @@ bool ScopDetection::hasValidArraySizes(DetectionContext &Context,
913913
Value *BaseValue = BasePointer->getValue();
914914
Region &CurRegion = Context.CurRegion;
915915
for (const SCEV *DelinearizedSize : Sizes) {
916-
if (!isAffine(DelinearizedSize, Scope, Context)) {
916+
// Don't pass down the scope to isAfffine; array dimensions must be
917+
// invariant across the entire scop.
918+
if (!isAffine(DelinearizedSize, nullptr, Context)) {
917919
Sizes.clear();
918920
break;
919921
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; RUN: opt %loadPolly -polly-scops -analyze < %s | FileCheck %s
2+
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
3+
target triple = "aarch64-unknown-linux-gnueabi"
4+
5+
; Make sure we don't crash trying delinearize the memory access
6+
; CHECK: region: 'bb4 => bb14'
7+
; CHECK-NEXT: Invalid Scop!
8+
define void @f(i8* %arg, i32 %arg1, i32 %arg2, i32 %arg3) {
9+
bb:
10+
br label %bb4
11+
12+
bb4:
13+
%tmp = phi i32 [ %arg2, %bb ], [ %tmp12, %bb4 ]
14+
%tmp5 = icmp sgt i32 %tmp, 0
15+
%tmp6 = select i1 %tmp5, i32 %tmp, i32 0
16+
%tmp7 = mul nsw i32 %tmp6, %arg3
17+
%tmp8 = sext i32 %tmp7 to i64
18+
%tmp9 = getelementptr inbounds i8, i8* %arg, i64 %tmp8
19+
%tmp10 = bitcast i8* %tmp9 to i32*
20+
%tmp11 = load i32, i32* %tmp10, align 4
21+
%tmp12 = add nsw i32 %tmp, 1
22+
%tmp13 = icmp slt i32 %tmp, %arg1
23+
br i1 %tmp13, label %bb4, label %bb14
24+
25+
bb14:
26+
ret void
27+
}

0 commit comments

Comments
 (0)