Andreas Bolka | 0dcde10 | 2009-07-23 15:56:53 +0000 | [diff] [blame] | 1 | ; RUN: llvm-as < %s | opt -disable-output -analyze -lda | FileCheck %s |
| 2 | |
| 3 | @x = common global [256 x i32] zeroinitializer, align 4 |
| 4 | @y = common global [256 x i32] zeroinitializer, align 4 |
| 5 | |
Andreas Bolka | 7b43f5c | 2009-07-28 23:40:40 +0000 | [diff] [blame] | 6 | ;; for (i = 0; i < 256; i++) |
Andreas Bolka | c20a6fd | 2009-08-02 23:28:14 +0000 | [diff] [blame] | 7 | ;; x[i] = x[255 - i] + y[i] |
Andreas Bolka | 0dcde10 | 2009-07-23 15:56:53 +0000 | [diff] [blame] | 8 | |
| 9 | define void @f1(...) nounwind { |
| 10 | entry: |
| 11 | br label %for.body |
| 12 | |
| 13 | for.body: |
| 14 | %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ] |
Andreas Bolka | c20a6fd | 2009-08-02 23:28:14 +0000 | [diff] [blame] | 15 | %i.255 = sub i64 255, %i |
Andreas Bolka | 7cf8503 | 2009-08-05 04:03:29 +0000 | [diff] [blame^] | 16 | %y.ld.addr = getelementptr [256 x i32]* @y, i64 0, i64 %i |
| 17 | %x.ld.addr = getelementptr [256 x i32]* @x, i64 0, i64 %i.255 |
Andreas Bolka | 0dcde10 | 2009-07-23 15:56:53 +0000 | [diff] [blame] | 18 | %x.st.addr = getelementptr [256 x i32]* @x, i64 0, i64 %i |
| 19 | %x = load i32* %x.ld.addr ; 0 |
| 20 | %y = load i32* %y.ld.addr ; 1 |
| 21 | %r = add i32 %y, %x |
| 22 | store i32 %r, i32* %x.st.addr ; 2 |
| 23 | ; CHECK: 0,2: dep |
| 24 | ; CHECK: 1,2: ind |
| 25 | %i.next = add i64 %i, 1 |
| 26 | %exitcond = icmp eq i64 %i.next, 256 |
| 27 | br i1 %exitcond, label %for.end, label %for.body |
| 28 | |
| 29 | for.end: |
| 30 | ret void |
| 31 | } |
| 32 | |
Andreas Bolka | c20a6fd | 2009-08-02 23:28:14 +0000 | [diff] [blame] | 33 | ;; for (i = 0; i < 100; i++) |
| 34 | ;; x[i] = x[255 - i] + y[i] |
Andreas Bolka | 0dcde10 | 2009-07-23 15:56:53 +0000 | [diff] [blame] | 35 | |
| 36 | define void @f2(...) nounwind { |
| 37 | entry: |
| 38 | br label %for.body |
| 39 | |
| 40 | for.body: |
| 41 | %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ] |
Andreas Bolka | 7cf8503 | 2009-08-05 04:03:29 +0000 | [diff] [blame^] | 42 | %i.255 = sub i64 255, %i |
Andreas Bolka | 0dcde10 | 2009-07-23 15:56:53 +0000 | [diff] [blame] | 43 | %y.ld.addr = getelementptr [256 x i32]* @y, i64 0, i64 %i |
Andreas Bolka | 7cf8503 | 2009-08-05 04:03:29 +0000 | [diff] [blame^] | 44 | %x.ld.addr = getelementptr [256 x i32]* @x, i64 0, i64 %i.255 |
Andreas Bolka | 0dcde10 | 2009-07-23 15:56:53 +0000 | [diff] [blame] | 45 | %x.st.addr = getelementptr [256 x i32]* @x, i64 0, i64 %i |
| 46 | %x = load i32* %x.ld.addr ; 0 |
| 47 | %y = load i32* %y.ld.addr ; 1 |
| 48 | %r = add i32 %y, %x |
| 49 | store i32 %r, i32* %x.st.addr ; 2 |
| 50 | ; CHECK: 0,2: dep |
| 51 | ; CHECK: 1,2: ind |
| 52 | %i.next = add i64 %i, 1 |
Andreas Bolka | c20a6fd | 2009-08-02 23:28:14 +0000 | [diff] [blame] | 53 | %exitcond = icmp eq i64 %i.next, 100 |
Andreas Bolka | 0dcde10 | 2009-07-23 15:56:53 +0000 | [diff] [blame] | 54 | br i1 %exitcond, label %for.end, label %for.body |
| 55 | |
| 56 | for.end: |
| 57 | ret void |
| 58 | } |
| 59 | |
Andreas Bolka | c20a6fd | 2009-08-02 23:28:14 +0000 | [diff] [blame] | 60 | ;; // the first iteration (i=0) leads to an out-of-bounds access of x. as the |
| 61 | ;; // result of this access is undefined, _any_ dependence result is safe. |
| 62 | ;; for (i = 0; i < 256; i++) |
Andreas Bolka | 7b43f5c | 2009-07-28 23:40:40 +0000 | [diff] [blame] | 63 | ;; x[i] = x[256 - i] + y[i] |
Andreas Bolka | 0dcde10 | 2009-07-23 15:56:53 +0000 | [diff] [blame] | 64 | |
| 65 | define void @f3(...) nounwind { |
| 66 | entry: |
| 67 | br label %for.body |
| 68 | |
| 69 | for.body: |
| 70 | %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ] |
| 71 | %i.256 = sub i64 0, %i |
| 72 | %y.ld.addr = getelementptr [256 x i32]* @y, i64 0, i64 %i |
| 73 | %x.ld.addr = getelementptr [256 x i32]* @x, i64 1, i64 %i.256 |
| 74 | %x.st.addr = getelementptr [256 x i32]* @x, i64 0, i64 %i |
| 75 | %x = load i32* %x.ld.addr ; 0 |
| 76 | %y = load i32* %y.ld.addr ; 1 |
| 77 | %r = add i32 %y, %x |
| 78 | store i32 %r, i32* %x.st.addr ; 2 |
| 79 | ; CHECK: 0,2: dep |
Andreas Bolka | c20a6fd | 2009-08-02 23:28:14 +0000 | [diff] [blame] | 80 | ; CHECK: 1,2: |
| 81 | %i.next = add i64 %i, 1 |
| 82 | %exitcond = icmp eq i64 %i.next, 256 |
| 83 | br i1 %exitcond, label %for.end, label %for.body |
| 84 | |
| 85 | for.end: |
| 86 | ret void |
| 87 | } |
| 88 | |
| 89 | ;; // slightly contrived but valid IR for the following loop, where all |
| 90 | ;; // accesses in all iterations are within bounds. while this example's first |
| 91 | ;; // (ZIV-)subscript is (0, 1), accesses are dependent. |
| 92 | ;; for (i = 1; i < 256; i++) |
| 93 | ;; x[i] = x[256 - i] + y[i] |
| 94 | |
| 95 | define void @f4(...) nounwind { |
| 96 | entry: |
| 97 | br label %for.body |
| 98 | |
| 99 | for.body: |
| 100 | %i = phi i64 [ 0, %entry ], [ %i.next, %for.body ] |
| 101 | %i.1 = add i64 1, %i |
| 102 | %i.256 = sub i64 -1, %i |
| 103 | %y.ld.addr = getelementptr [256 x i32]* @y, i64 0, i64 %i.1 |
| 104 | %x.ld.addr = getelementptr [256 x i32]* @x, i64 1, i64 %i.256 |
| 105 | %x.st.addr = getelementptr [256 x i32]* @x, i64 0, i64 %i.1 |
| 106 | %x = load i32* %x.ld.addr ; 0 |
| 107 | %y = load i32* %y.ld.addr ; 1 |
| 108 | %r = add i32 %y, %x |
| 109 | store i32 %r, i32* %x.st.addr ; 2 |
| 110 | ; CHECK: 0,2: dep |
Andreas Bolka | 0dcde10 | 2009-07-23 15:56:53 +0000 | [diff] [blame] | 111 | ; CHECK: 1,2: ind |
| 112 | %i.next = add i64 %i, 1 |
Andreas Bolka | c20a6fd | 2009-08-02 23:28:14 +0000 | [diff] [blame] | 113 | %exitcond = icmp eq i64 %i.next, 256 |
Andreas Bolka | 0dcde10 | 2009-07-23 15:56:53 +0000 | [diff] [blame] | 114 | br i1 %exitcond, label %for.end, label %for.body |
| 115 | |
| 116 | for.end: |
| 117 | ret void |
| 118 | } |