llvm-project
71 строка · 2.6 Кб
1; RUN: opt %loadPolly -polly-invariant-load-hoisting -polly-detect-full-functions -polly-print-scops -disable-output < %s | FileCheck %s
2;
3; This testcase checks for compatibility of the -detect-full-functions
4; flag in combination with the -invariant-load-hoisting option. More
5; specifically, ScopHelper.cpp::isHoistableLoad only gets called if
6; -invariant-load-hoisting is enabled. This function, however, had a bug
7; which caused a crash if the region argument was top-level. This test
8; is a minimal example that hits this specific code path.
9;
10; Also note that this file's IR is in no way optimized, i.e. it was
11; generated with clang -O0 from the following C-code:
12;
13; void test() {
14; int A[] = {1, 2, 3, 4, 5};
15; int len = (sizeof A) / sizeof(int);
16; for (int i = 0; i < len; ++i) {
17; A[i] = A[i] * 2;
18; }
19; }
20;
21; This is also the reason why polly does not detect any scops (the loop
22; variable i is loaded from and stored to memory in each iteration):
23;
24; CHECK: region: 'for.cond => for.end' in function 'test':
25; CHECK-NEXT: Invalid Scop!
26; CHECK-NEXT: region: 'entry => <Function Return>' in function 'test':
27; CHECK-NEXT: Invalid Scop!
28;
29target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
30
31@test.A = private unnamed_addr constant [5 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5], align 16
32
33define void @test() {
34entry:
35%A = alloca [5 x i32], align 16
36%len = alloca i32, align 4
37%i = alloca i32, align 4
38call void @llvm.memcpy.p0.p0.i64(ptr %A, ptr @test.A, i64 20, i32 16, i1 false)
39store i32 5, ptr %len, align 4
40store i32 0, ptr %i, align 4
41br label %for.cond
42
43for.cond: ; preds = %for.inc, %entry
44%0 = load i32, ptr %i, align 4
45%1 = load i32, ptr %len, align 4
46%cmp = icmp slt i32 %0, %1
47br i1 %cmp, label %for.body, label %for.end
48
49for.body: ; preds = %for.cond
50%2 = load i32, ptr %i, align 4
51%idxprom = sext i32 %2 to i64
52%arrayidx = getelementptr inbounds [5 x i32], ptr %A, i64 0, i64 %idxprom
53%3 = load i32, ptr %arrayidx, align 4
54%mul = mul nsw i32 %3, 2
55%4 = load i32, ptr %i, align 4
56%idxprom1 = sext i32 %4 to i64
57%arrayidx2 = getelementptr inbounds [5 x i32], ptr %A, i64 0, i64 %idxprom1
58store i32 %mul, ptr %arrayidx2, align 4
59br label %for.inc
60
61for.inc: ; preds = %for.body
62%5 = load i32, ptr %i, align 4
63%inc = add nsw i32 %5, 1
64store i32 %inc, ptr %i, align 4
65br label %for.cond
66
67for.end: ; preds = %for.cond
68ret void
69}
70
71declare void @llvm.memcpy.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i32, i1)
72