Eric Christopher | cee313d | 2019-04-17 04:52:47 +0000 | [diff] [blame] | 1 | target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128" |
| 2 | ; RUN: opt < %s -alignment-from-assumptions -S | FileCheck %s |
| 3 | ; RUN: opt < %s -passes=alignment-from-assumptions -S | FileCheck %s |
| 4 | |
| 5 | define i32 @foo(i32* nocapture %a) nounwind uwtable readonly { |
| 6 | entry: |
Eric Christopher | 7bfaa40 | 2020-07-16 11:40:43 -0700 | [diff] [blame^] | 7 | %ptrint = ptrtoint i32* %a to i64 |
| 8 | %maskedptr = and i64 %ptrint, 31 |
| 9 | %maskcond = icmp eq i64 %maskedptr, 0 |
| 10 | tail call void @llvm.assume(i1 %maskcond) |
Eric Christopher | cee313d | 2019-04-17 04:52:47 +0000 | [diff] [blame] | 11 | %0 = load i32, i32* %a, align 4 |
| 12 | ret i32 %0 |
| 13 | |
| 14 | ; CHECK-LABEL: @foo |
| 15 | ; CHECK: load i32, i32* {{[^,]+}}, align 32 |
| 16 | ; CHECK: ret i32 |
| 17 | } |
| 18 | |
| 19 | define i32 @foo2(i32* nocapture %a) nounwind uwtable readonly { |
| 20 | entry: |
Eric Christopher | 7bfaa40 | 2020-07-16 11:40:43 -0700 | [diff] [blame^] | 21 | %ptrint = ptrtoint i32* %a to i64 |
| 22 | %offsetptr = add i64 %ptrint, 24 |
| 23 | %maskedptr = and i64 %offsetptr, 31 |
| 24 | %maskcond = icmp eq i64 %maskedptr, 0 |
| 25 | tail call void @llvm.assume(i1 %maskcond) |
Eric Christopher | cee313d | 2019-04-17 04:52:47 +0000 | [diff] [blame] | 26 | %arrayidx = getelementptr inbounds i32, i32* %a, i64 2 |
| 27 | %0 = load i32, i32* %arrayidx, align 4 |
| 28 | ret i32 %0 |
| 29 | |
| 30 | ; CHECK-LABEL: @foo2 |
| 31 | ; CHECK: load i32, i32* {{[^,]+}}, align 16 |
| 32 | ; CHECK: ret i32 |
| 33 | } |
| 34 | |
| 35 | define i32 @foo2a(i32* nocapture %a) nounwind uwtable readonly { |
| 36 | entry: |
Eric Christopher | 7bfaa40 | 2020-07-16 11:40:43 -0700 | [diff] [blame^] | 37 | %ptrint = ptrtoint i32* %a to i64 |
| 38 | %offsetptr = add i64 %ptrint, 28 |
| 39 | %maskedptr = and i64 %offsetptr, 31 |
| 40 | %maskcond = icmp eq i64 %maskedptr, 0 |
| 41 | tail call void @llvm.assume(i1 %maskcond) |
Eric Christopher | cee313d | 2019-04-17 04:52:47 +0000 | [diff] [blame] | 42 | %arrayidx = getelementptr inbounds i32, i32* %a, i64 -1 |
| 43 | %0 = load i32, i32* %arrayidx, align 4 |
| 44 | ret i32 %0 |
| 45 | |
| 46 | ; CHECK-LABEL: @foo2a |
| 47 | ; CHECK: load i32, i32* {{[^,]+}}, align 32 |
| 48 | ; CHECK: ret i32 |
| 49 | } |
| 50 | |
| 51 | define i32 @goo(i32* nocapture %a) nounwind uwtable readonly { |
| 52 | entry: |
Eric Christopher | 7bfaa40 | 2020-07-16 11:40:43 -0700 | [diff] [blame^] | 53 | %ptrint = ptrtoint i32* %a to i64 |
| 54 | %maskedptr = and i64 %ptrint, 31 |
| 55 | %maskcond = icmp eq i64 %maskedptr, 0 |
| 56 | tail call void @llvm.assume(i1 %maskcond) |
Eric Christopher | cee313d | 2019-04-17 04:52:47 +0000 | [diff] [blame] | 57 | %0 = load i32, i32* %a, align 4 |
| 58 | ret i32 %0 |
| 59 | |
| 60 | ; CHECK-LABEL: @goo |
| 61 | ; CHECK: load i32, i32* {{[^,]+}}, align 32 |
| 62 | ; CHECK: ret i32 |
| 63 | } |
| 64 | |
| 65 | define i32 @hoo(i32* nocapture %a) nounwind uwtable readonly { |
| 66 | entry: |
Eric Christopher | 7bfaa40 | 2020-07-16 11:40:43 -0700 | [diff] [blame^] | 67 | %ptrint = ptrtoint i32* %a to i64 |
| 68 | %maskedptr = and i64 %ptrint, 31 |
| 69 | %maskcond = icmp eq i64 %maskedptr, 0 |
| 70 | tail call void @llvm.assume(i1 %maskcond) |
Eric Christopher | cee313d | 2019-04-17 04:52:47 +0000 | [diff] [blame] | 71 | br label %for.body |
| 72 | |
| 73 | for.body: ; preds = %entry, %for.body |
| 74 | %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ] |
| 75 | %r.06 = phi i32 [ 0, %entry ], [ %add, %for.body ] |
| 76 | %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv |
| 77 | %0 = load i32, i32* %arrayidx, align 4 |
| 78 | %add = add nsw i32 %0, %r.06 |
| 79 | %indvars.iv.next = add i64 %indvars.iv, 8 |
| 80 | %1 = trunc i64 %indvars.iv.next to i32 |
| 81 | %cmp = icmp slt i32 %1, 2048 |
| 82 | br i1 %cmp, label %for.body, label %for.end |
| 83 | |
| 84 | for.end: ; preds = %for.body |
| 85 | %add.lcssa = phi i32 [ %add, %for.body ] |
| 86 | ret i32 %add.lcssa |
| 87 | |
| 88 | ; CHECK-LABEL: @hoo |
| 89 | ; CHECK: load i32, i32* %arrayidx, align 32 |
| 90 | ; CHECK: ret i32 %add.lcssa |
| 91 | } |
| 92 | |
Fangrui Song | 3fc933a | 2019-08-23 02:17:04 +0000 | [diff] [blame] | 93 | ; test D66575 |
| 94 | ; def hoo2(a, id, num): |
| 95 | ; for i0 in range(id*64, 4096, num*64): |
| 96 | ; for i1 in range(0, 4096, 32): |
| 97 | ; for i2 in range(0, 4096, 32): |
| 98 | ; load(a, i0+i1+i2+32) |
| 99 | define void @hoo2(i32* nocapture %a, i64 %id, i64 %num) nounwind uwtable readonly { |
| 100 | entry: |
Eric Christopher | 7bfaa40 | 2020-07-16 11:40:43 -0700 | [diff] [blame^] | 101 | %ptrint = ptrtoint i32* %a to i64 |
| 102 | %maskedptr = and i64 %ptrint, 31 |
| 103 | %maskcond = icmp eq i64 %maskedptr, 0 |
| 104 | tail call void @llvm.assume(i1 %maskcond) |
Fangrui Song | 3fc933a | 2019-08-23 02:17:04 +0000 | [diff] [blame] | 105 | %id.mul = shl nsw i64 %id, 6 |
| 106 | %num.mul = shl nsw i64 %num, 6 |
| 107 | br label %for0.body |
| 108 | |
| 109 | for0.body: |
| 110 | %i0 = phi i64 [ %id.mul, %entry ], [ %i0.next, %for0.end ] |
| 111 | br label %for1.body |
| 112 | |
| 113 | for1.body: |
| 114 | %i1 = phi i64 [ 0, %for0.body ], [ %i1.next, %for1.end ] |
| 115 | br label %for2.body |
| 116 | |
| 117 | for2.body: |
| 118 | %i2 = phi i64 [ 0, %for1.body ], [ %i2.next, %for2.body ] |
| 119 | |
| 120 | %t1 = add nuw nsw i64 %i0, %i1 |
| 121 | %t2 = add nuw nsw i64 %t1, %i2 |
| 122 | %t3 = add nuw nsw i64 %t2, 32 |
| 123 | %arrayidx = getelementptr inbounds i32, i32* %a, i64 %t3 |
| 124 | %x = load i32, i32* %arrayidx, align 4 |
| 125 | |
| 126 | %i2.next = add nuw nsw i64 %i2, 32 |
| 127 | %cmp2 = icmp ult i64 %i2.next, 4096 |
| 128 | br i1 %cmp2, label %for2.body, label %for1.end |
| 129 | |
| 130 | for1.end: |
| 131 | %i1.next = add nuw nsw i64 %i1, 32 |
| 132 | %cmp1 = icmp ult i64 %i1.next, 4096 |
| 133 | br i1 %cmp1, label %for1.body, label %for0.end |
| 134 | |
| 135 | for0.end: |
| 136 | %i0.next = add nuw nsw i64 %i0, %num.mul |
| 137 | %cmp0 = icmp ult i64 %i0.next, 4096 |
| 138 | br i1 %cmp0, label %for0.body, label %return |
| 139 | |
| 140 | return: |
| 141 | ret void |
| 142 | |
| 143 | ; CHECK-LABEL: @hoo2 |
| 144 | ; CHECK: load i32, i32* %arrayidx, align 32 |
| 145 | ; CHECK: ret void |
| 146 | } |
| 147 | |
Eric Christopher | cee313d | 2019-04-17 04:52:47 +0000 | [diff] [blame] | 148 | define i32 @joo(i32* nocapture %a) nounwind uwtable readonly { |
| 149 | entry: |
Eric Christopher | 7bfaa40 | 2020-07-16 11:40:43 -0700 | [diff] [blame^] | 150 | %ptrint = ptrtoint i32* %a to i64 |
| 151 | %maskedptr = and i64 %ptrint, 31 |
| 152 | %maskcond = icmp eq i64 %maskedptr, 0 |
| 153 | tail call void @llvm.assume(i1 %maskcond) |
Eric Christopher | cee313d | 2019-04-17 04:52:47 +0000 | [diff] [blame] | 154 | br label %for.body |
| 155 | |
| 156 | for.body: ; preds = %entry, %for.body |
| 157 | %indvars.iv = phi i64 [ 4, %entry ], [ %indvars.iv.next, %for.body ] |
| 158 | %r.06 = phi i32 [ 0, %entry ], [ %add, %for.body ] |
| 159 | %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv |
| 160 | %0 = load i32, i32* %arrayidx, align 4 |
| 161 | %add = add nsw i32 %0, %r.06 |
| 162 | %indvars.iv.next = add i64 %indvars.iv, 8 |
| 163 | %1 = trunc i64 %indvars.iv.next to i32 |
| 164 | %cmp = icmp slt i32 %1, 2048 |
| 165 | br i1 %cmp, label %for.body, label %for.end |
| 166 | |
| 167 | for.end: ; preds = %for.body |
| 168 | %add.lcssa = phi i32 [ %add, %for.body ] |
| 169 | ret i32 %add.lcssa |
| 170 | |
| 171 | ; CHECK-LABEL: @joo |
| 172 | ; CHECK: load i32, i32* %arrayidx, align 16 |
| 173 | ; CHECK: ret i32 %add.lcssa |
| 174 | } |
| 175 | |
| 176 | define i32 @koo(i32* nocapture %a) nounwind uwtable readonly { |
| 177 | entry: |
Eric Christopher | 7bfaa40 | 2020-07-16 11:40:43 -0700 | [diff] [blame^] | 178 | %ptrint = ptrtoint i32* %a to i64 |
| 179 | %maskedptr = and i64 %ptrint, 31 |
| 180 | %maskcond = icmp eq i64 %maskedptr, 0 |
| 181 | tail call void @llvm.assume(i1 %maskcond) |
Eric Christopher | cee313d | 2019-04-17 04:52:47 +0000 | [diff] [blame] | 182 | br label %for.body |
| 183 | |
| 184 | for.body: ; preds = %entry, %for.body |
| 185 | %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ] |
| 186 | %r.06 = phi i32 [ 0, %entry ], [ %add, %for.body ] |
| 187 | %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv |
| 188 | %0 = load i32, i32* %arrayidx, align 4 |
| 189 | %add = add nsw i32 %0, %r.06 |
| 190 | %indvars.iv.next = add i64 %indvars.iv, 4 |
| 191 | %1 = trunc i64 %indvars.iv.next to i32 |
| 192 | %cmp = icmp slt i32 %1, 2048 |
| 193 | br i1 %cmp, label %for.body, label %for.end |
| 194 | |
| 195 | for.end: ; preds = %for.body |
| 196 | %add.lcssa = phi i32 [ %add, %for.body ] |
| 197 | ret i32 %add.lcssa |
| 198 | |
| 199 | ; CHECK-LABEL: @koo |
| 200 | ; CHECK: load i32, i32* %arrayidx, align 16 |
| 201 | ; CHECK: ret i32 %add.lcssa |
| 202 | } |
| 203 | |
| 204 | define i32 @koo2(i32* nocapture %a) nounwind uwtable readonly { |
| 205 | entry: |
Eric Christopher | 7bfaa40 | 2020-07-16 11:40:43 -0700 | [diff] [blame^] | 206 | %ptrint = ptrtoint i32* %a to i64 |
| 207 | %maskedptr = and i64 %ptrint, 31 |
| 208 | %maskcond = icmp eq i64 %maskedptr, 0 |
| 209 | tail call void @llvm.assume(i1 %maskcond) |
Eric Christopher | cee313d | 2019-04-17 04:52:47 +0000 | [diff] [blame] | 210 | br label %for.body |
| 211 | |
| 212 | for.body: ; preds = %entry, %for.body |
| 213 | %indvars.iv = phi i64 [ -4, %entry ], [ %indvars.iv.next, %for.body ] |
| 214 | %r.06 = phi i32 [ 0, %entry ], [ %add, %for.body ] |
| 215 | %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv |
| 216 | %0 = load i32, i32* %arrayidx, align 4 |
| 217 | %add = add nsw i32 %0, %r.06 |
| 218 | %indvars.iv.next = add i64 %indvars.iv, 4 |
| 219 | %1 = trunc i64 %indvars.iv.next to i32 |
| 220 | %cmp = icmp slt i32 %1, 2048 |
| 221 | br i1 %cmp, label %for.body, label %for.end |
| 222 | |
| 223 | for.end: ; preds = %for.body |
| 224 | %add.lcssa = phi i32 [ %add, %for.body ] |
| 225 | ret i32 %add.lcssa |
| 226 | |
| 227 | ; CHECK-LABEL: @koo2 |
| 228 | ; CHECK: load i32, i32* %arrayidx, align 16 |
| 229 | ; CHECK: ret i32 %add.lcssa |
| 230 | } |
| 231 | |
| 232 | define i32 @moo(i32* nocapture %a) nounwind uwtable { |
| 233 | entry: |
Eric Christopher | 7bfaa40 | 2020-07-16 11:40:43 -0700 | [diff] [blame^] | 234 | %ptrint = ptrtoint i32* %a to i64 |
| 235 | %maskedptr = and i64 %ptrint, 31 |
| 236 | %maskcond = icmp eq i64 %maskedptr, 0 |
| 237 | tail call void @llvm.assume(i1 %maskcond) |
Eric Christopher | cee313d | 2019-04-17 04:52:47 +0000 | [diff] [blame] | 238 | %0 = bitcast i32* %a to i8* |
| 239 | tail call void @llvm.memset.p0i8.i64(i8* align 4 %0, i8 0, i64 64, i1 false) |
| 240 | ret i32 undef |
| 241 | |
| 242 | ; CHECK-LABEL: @moo |
| 243 | ; CHECK: @llvm.memset.p0i8.i64(i8* align 32 %0, i8 0, i64 64, i1 false) |
| 244 | ; CHECK: ret i32 undef |
| 245 | } |
| 246 | |
| 247 | define i32 @moo2(i32* nocapture %a, i32* nocapture %b) nounwind uwtable { |
| 248 | entry: |
Eric Christopher | 7bfaa40 | 2020-07-16 11:40:43 -0700 | [diff] [blame^] | 249 | %ptrint = ptrtoint i32* %a to i64 |
| 250 | %maskedptr = and i64 %ptrint, 31 |
| 251 | %maskcond = icmp eq i64 %maskedptr, 0 |
| 252 | tail call void @llvm.assume(i1 %maskcond) |
| 253 | %ptrint1 = ptrtoint i32* %b to i64 |
| 254 | %maskedptr3 = and i64 %ptrint1, 127 |
| 255 | %maskcond4 = icmp eq i64 %maskedptr3, 0 |
| 256 | tail call void @llvm.assume(i1 %maskcond4) |
Eric Christopher | cee313d | 2019-04-17 04:52:47 +0000 | [diff] [blame] | 257 | %0 = bitcast i32* %a to i8* |
Eric Christopher | cee313d | 2019-04-17 04:52:47 +0000 | [diff] [blame] | 258 | %1 = bitcast i32* %b to i8* |
| 259 | tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %0, i8* align 4 %1, i64 64, i1 false) |
| 260 | ret i32 undef |
| 261 | |
| 262 | ; CHECK-LABEL: @moo2 |
| 263 | ; CHECK: @llvm.memcpy.p0i8.p0i8.i64(i8* align 32 %0, i8* align 128 %1, i64 64, i1 false) |
| 264 | ; CHECK: ret i32 undef |
| 265 | } |
| 266 | |
Eric Christopher | cee313d | 2019-04-17 04:52:47 +0000 | [diff] [blame] | 267 | declare void @llvm.assume(i1) nounwind |
| 268 | |
| 269 | declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind |
| 270 | declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind |
| 271 | |