1; RUN: opt %loadPolly -polly-codegen -S -verify-dom-info \
2; RUN:     < %s | FileCheck %s
3;
4; Check that we do not reuse the B[i-1] GEP created in block S again in
5; block Q. Hence, we create two GEPs for B[i-1]:
6;
7; CHECK:  %scevgep{{.}} = getelementptr i32, i32* %B, i64 -1
8; CHECK:  %scevgep{{.}} = getelementptr i32, i32* %B, i64 -1
9;
10;    void f(int *A, int *B) {
11;      int x = 0;
12;      for (int i = 0; i < 1024; i++) {
13;        if (A[i]) {
14;          if (i > 512)
15; S:         A[i] = B[i - 1];
16; Q:       A[i] += B[i - 1];
17;        }
18;      }
19;    }
20;
21target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
22
23define void @f(i32* %A, i32* %B) {
24bb:
25  br label %bb1
26
27bb1:                                              ; preds = %bb22, %bb
28  %indvars.iv = phi i64 [ %indvars.iv.next, %bb22 ], [ 0, %bb ]
29  %exitcond = icmp ne i64 %indvars.iv, 1024
30  br i1 %exitcond, label %bb2, label %bb23
31
32bb2:                                              ; preds = %bb1
33  %tmp = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
34  %tmp3 = load i32, i32* %tmp, align 4
35  %tmp4 = icmp eq i32 %tmp3, 0
36  br i1 %tmp4, label %bb21, label %bb5
37
38bb5:                                              ; preds = %bb2
39  %tmp6 = icmp sgt i64 %indvars.iv, 512
40  br i1 %tmp6, label %bb7, label %bb13
41
42bb7:                                              ; preds = %bb5
43  br label %bb8
44
45bb8:                                              ; preds = %bb7
46  %tmp9 = add nsw i64 %indvars.iv, -1
47  %tmp10 = getelementptr inbounds i32, i32* %B, i64 %tmp9
48  %tmp11 = load i32, i32* %tmp10, align 4
49  %tmp12 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
50  store i32 %tmp11, i32* %tmp12, align 4
51  br label %bb13
52
53bb13:                                             ; preds = %bb8, %bb5
54  br label %bb14
55
56bb14:                                             ; preds = %bb13
57  %tmp15 = add nsw i64 %indvars.iv, -1
58  %tmp16 = getelementptr inbounds i32, i32* %B, i64 %tmp15
59  %tmp17 = load i32, i32* %tmp16, align 4
60  %tmp18 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv
61  %tmp19 = load i32, i32* %tmp18, align 4
62  %tmp20 = add nsw i32 %tmp19, %tmp17
63  store i32 %tmp20, i32* %tmp18, align 4
64  br label %bb21
65
66bb21:                                             ; preds = %bb2, %bb14
67  br label %bb22
68
69bb22:                                             ; preds = %bb21
70  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
71  br label %bb1
72
73bb23:                                             ; preds = %bb1
74  ret void
75}
76