llvm-project
57 строк · 2.3 Кб
1; RUN: opt %loadNPMPolly '-passes=print<polly-function-scops>' -disable-output < %s 2>&1 | FileCheck %s
2; RUN: opt %loadNPMPolly -passes=polly-codegen -S < %s | FileCheck %s --check-prefix=IR
3;
4; Check that we guard the divisions because we moved them and thereby increased
5; their domain.
6;
7; CHECK: Invalid Context:
8; CHECK-NEXT: [p_0] -> { : false }
9; CHECK: p0: (((zext i32 %a to i64) /u (zext i32 %b to i64)) /u ((zext i32 %c to i64) /u (zext i32 %d to i64)))
10;
11; void f(unsigned *A, unsigned a, unsigned b, unsigned c, unsigned d) {
12; for (unsigned i; i < 100; i++)
13; A[i] += A[(a / b) / (c / d)];
14; }
15;
16; IR: %[[A:[.a-zA-Z0-9]*]] = zext i32 %a to i64
17; IR-NEXT: %[[B:[.a-zA-Z0-9]*]] = zext i32 %b to i64
18; IR-NEXT: %[[R1:[.a-zA-Z0-9]*]] = call i64 @llvm.umax.i64(i64 %[[B]], i64 1)
19; IR-NEXT: %[[R2:[.a-zA-Z0-9]*]] = udiv i64 %[[A]], %[[R1]]
20; IR-NEXT: %[[C:[.a-zA-Z0-9]*]] = zext i32 %c to i64
21; IR-NEXT: %[[D:[.a-zA-Z0-9]*]] = zext i32 %d to i64
22; IR-NEXT: %[[R6:[.a-zA-Z0-9]*]] = call i64 @llvm.umax.i64(i64 %[[D]], i64 1)
23; IR-NEXT: %[[R7:[.a-zA-Z0-9]*]] = udiv i64 %[[C]], %[[R6]]
24; IR-NEXT: %[[R4:[.a-zA-Z0-9]*]] = call i64 @llvm.umax.i64(i64 %[[R7]], i64 1)
25; IR-NEXT: %[[R8:[.a-zA-Z0-9]*]] = udiv i64 %[[R2]], %[[R4]]
26;
27target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
28
29define void @f(ptr %A, i32 %a, i32 %b, i32 %c, i32 %d) {
30entry:
31br label %for.cond
32
33for.cond: ; preds = %for.inc, %entry
34%indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
35%cmp = icmp ult i64 %indvars.iv, 100
36br i1 %cmp, label %for.body, label %for.end
37
38for.body: ; preds = %for.cond
39%div = udiv i32 %a, %b
40%div1 = udiv i32 %c, %d
41%div2 = udiv i32 %div, %div1
42%idxprom = zext i32 %div2 to i64
43%arrayidx = getelementptr inbounds i32, ptr %A, i64 %idxprom
44%tmp = load i32, ptr %arrayidx, align 4
45%arrayidx4 = getelementptr inbounds i32, ptr %A, i64 %indvars.iv
46%tmp1 = load i32, ptr %arrayidx4, align 4
47%add = add i32 %tmp1, %tmp
48store i32 %add, ptr %arrayidx4, align 4
49br label %for.inc
50
51for.inc: ; preds = %for.body
52%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
53br label %for.cond
54
55for.end: ; preds = %for.cond
56ret void
57}
58