Anna Thomas | 2d33ce7 | 2018-08-21 13:02:09 +0000 | [diff] [blame^] | 1 | ; RUN: opt < %s -loop-vectorize -force-vector-width=4 -dce -instcombine -S | FileCheck %s |
| 2 | |
| 3 | target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" |
| 4 | |
| 5 | ; tests skipping iterations within a VF through break/continue/gotos. |
| 6 | |
| 7 | ; int test(int *A, int Length) { |
| 8 | ; for (int i = 0; i < Length; i++) { |
| 9 | ; if (A[i] > 10.0) goto end; |
| 10 | ; A[i] = 0; |
| 11 | ; } |
| 12 | ; end: |
| 13 | ; return 0; |
| 14 | ; } |
| 15 | ; CHECK-LABEL: test1( |
| 16 | ; CHECK-NOT: <4 x i32> |
| 17 | define i32 @test1(i32* nocapture %A, i32 %Length) { |
| 18 | entry: |
| 19 | %cmp8 = icmp sgt i32 %Length, 0 |
| 20 | br i1 %cmp8, label %for.body.preheader, label %end |
| 21 | |
| 22 | for.body.preheader: ; preds = %entry |
| 23 | br label %for.body |
| 24 | |
| 25 | for.body: ; preds = %for.body.preheader, %if.else |
| 26 | %indvars.iv = phi i64 [ %indvars.iv.next, %if.else ], [ 0, %for.body.preheader ] |
| 27 | %arrayidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv |
| 28 | %0 = load i32, i32* %arrayidx, align 4, !tbaa !15 |
| 29 | %cmp1 = icmp sgt i32 %0, 10 |
| 30 | br i1 %cmp1, label %end.loopexit, label %if.else |
| 31 | |
| 32 | if.else: ; preds = %for.body |
| 33 | store i32 0, i32* %arrayidx, align 4, !tbaa !15 |
| 34 | %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 |
| 35 | %1 = trunc i64 %indvars.iv.next to i32 |
| 36 | %cmp = icmp slt i32 %1, %Length |
| 37 | br i1 %cmp, label %for.body, label %end.loopexit |
| 38 | |
| 39 | end.loopexit: ; preds = %if.else, %for.body |
| 40 | br label %end |
| 41 | |
| 42 | end: ; preds = %end.loopexit, %entry |
| 43 | ret i32 0 |
| 44 | } |
| 45 | |
| 46 | ; We don't use anything from within the loop at the early exit path |
| 47 | ; so we do not need to know which iteration caused the early exit path. |
| 48 | ; bool test2(int *A, int Length, int K) { |
| 49 | ; for (int i = 0; i < Length; i++) { |
| 50 | ; if (A[i] == K) return true; |
| 51 | ; } |
| 52 | ; return false; |
| 53 | ; } |
| 54 | ; TODO: Today we do not vectorize this, but we could teach the vectorizer. |
| 55 | ; CHECK-LABEL: test2( |
| 56 | ; CHECK-NOT: <4 x i32> |
| 57 | define i32 @test2(i32* nocapture %A, i32 %Length, i32 %K) { |
| 58 | entry: |
| 59 | %cmp8 = icmp sgt i32 %Length, 0 |
| 60 | br i1 %cmp8, label %for.body.preheader, label %end |
| 61 | |
| 62 | for.body.preheader: ; preds = %entry |
| 63 | br label %for.body |
| 64 | |
| 65 | for.body: ; preds = %for.body.preheader, %if.else |
| 66 | %indvars.iv = phi i64 [ %indvars.iv.next, %if.else ], [ 0, %for.body.preheader ] |
| 67 | %arrayidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv |
| 68 | %ld = load i32, i32* %arrayidx, align 4 |
| 69 | %cmp1 = icmp eq i32 %ld, %K |
| 70 | br i1 %cmp1, label %end.loopexit, label %if.else |
| 71 | |
| 72 | if.else: ; preds = %for.body |
| 73 | %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 |
| 74 | %trunc = trunc i64 %indvars.iv.next to i32 |
| 75 | %cmp = icmp slt i32 %trunc, %Length |
| 76 | br i1 %cmp, label %for.body, label %end.loopexit |
| 77 | |
| 78 | end.loopexit: ; preds = %if.else, %for.body |
| 79 | %result.lcssa = phi i32 [ 1, %for.body ], [ 0, %if.else ] |
| 80 | br label %end |
| 81 | |
| 82 | end: ; preds = %end.loopexit, %entry |
| 83 | %result = phi i32 [ %result.lcssa, %end.loopexit ], [ 0, %entry ] |
| 84 | ret i32 %result |
| 85 | } |
| 86 | |
| 87 | ; We use the IV in the early exit |
| 88 | ; so we need to know which iteration caused the early exit path. |
| 89 | ; int test3(int *A, int Length, int K) { |
| 90 | ; for (int i = 0; i < Length; i++) { |
| 91 | ; if (A[i] == K) return i; |
| 92 | ; } |
| 93 | ; return -1; |
| 94 | ; } |
| 95 | ; TODO: Today we do not vectorize this, but we could teach the vectorizer. |
| 96 | ; CHECK-LABEL: test3( |
| 97 | ; CHECK-NOT: <4 x i32> |
| 98 | define i32 @test3(i32* nocapture %A, i32 %Length, i32 %K) { |
| 99 | entry: |
| 100 | %cmp8 = icmp sgt i32 %Length, 0 |
| 101 | br i1 %cmp8, label %for.body.preheader, label %end |
| 102 | |
| 103 | for.body.preheader: ; preds = %entry |
| 104 | br label %for.body |
| 105 | |
| 106 | for.body: ; preds = %for.body.preheader, %if.else |
| 107 | %indvars.iv = phi i64 [ %indvars.iv.next, %if.else ], [ 0, %for.body.preheader ] |
| 108 | %arrayidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv |
| 109 | %ld = load i32, i32* %arrayidx, align 4 |
| 110 | %cmp1 = icmp eq i32 %ld, %K |
| 111 | br i1 %cmp1, label %end.loopexit, label %if.else |
| 112 | |
| 113 | if.else: ; preds = %for.body |
| 114 | %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 |
| 115 | %trunc = trunc i64 %indvars.iv.next to i32 |
| 116 | %cmp = icmp slt i32 %trunc, %Length |
| 117 | br i1 %cmp, label %for.body, label %end.loopexit |
| 118 | |
| 119 | end.loopexit: ; preds = %if.else, %for.body |
| 120 | %result.lcssa = phi i64 [ %indvars.iv, %for.body ], [ -1, %if.else ] |
| 121 | %res.trunc = trunc i64 %result.lcssa to i32 |
| 122 | br label %end |
| 123 | |
| 124 | end: ; preds = %end.loopexit, %entry |
| 125 | %result = phi i32 [ %res.trunc, %end.loopexit ], [ -1, %entry ] |
| 126 | ret i32 %result |
| 127 | } |
| 128 | |
| 129 | ; bool test4(int *A, int Length, int K, int J) { |
| 130 | ; for (int i = 0; i < Length; i++) { |
| 131 | ; if (A[i] == K) continue; |
| 132 | ; A[i] = J; |
| 133 | ; } |
| 134 | ; } |
| 135 | ; For this test, we vectorize and generate predicated stores to A[i]. |
| 136 | ; CHECK-LABEL: test4( |
| 137 | ; CHECK: <4 x i32> |
| 138 | define void @test4(i32* nocapture %A, i32 %Length, i32 %K, i32 %J) { |
| 139 | entry: |
| 140 | %cmp8 = icmp sgt i32 %Length, 0 |
| 141 | br i1 %cmp8, label %for.body.preheader, label %end.loopexit |
| 142 | |
| 143 | for.body.preheader: ; preds = %entry |
| 144 | br label %for.body |
| 145 | |
| 146 | for.body: ; preds = %for.body.preheader, %if.else |
| 147 | %indvars.iv = phi i64 [ %indvars.iv.next, %latch ], [ 0, %for.body.preheader ] |
| 148 | %arrayidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv |
| 149 | %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 |
| 150 | %trunc = trunc i64 %indvars.iv.next to i32 |
| 151 | %ld = load i32, i32* %arrayidx, align 4 |
| 152 | %cmp1 = icmp eq i32 %ld, %K |
| 153 | br i1 %cmp1, label %latch, label %if.else |
| 154 | |
| 155 | if.else: |
| 156 | store i32 %J, i32* %arrayidx, align 4 |
| 157 | br label %latch |
| 158 | |
| 159 | latch: ; preds = %for.body |
| 160 | %cmp = icmp slt i32 %trunc, %Length |
| 161 | br i1 %cmp, label %for.body, label %end.loopexit |
| 162 | |
| 163 | end.loopexit: ; preds = %if.else, %for.body |
| 164 | ret void |
| 165 | } |
| 166 | !15 = !{!16, !16, i64 0} |
| 167 | !16 = !{!"int", !17, i64 0} |
| 168 | !17 = !{!"omnipotent char", !18, i64 0} |
| 169 | !18 = !{!"Simple C/C++ TBAA"} |