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