Dan Gohman | 673968a | 2011-05-18 21:02:18 +0000 | [diff] [blame] | 1 | ; RUN: opt -loop-reduce -S < %s | FileCheck %s |
| 2 | ; PR9939 |
| 3 | |
| 4 | ; LSR should property handle the post-inc offset when folding the |
| 5 | ; non-IV operand of an icmp into the IV. |
| 6 | |
| 7 | ; CHECK: %tmp2 = sub i64 %sub.ptr.lhs.cast, %sub.ptr.rhs.cast |
| 8 | ; CHECK: %tmp3 = lshr i64 %tmp2, 1 |
| 9 | ; CHECK: %tmp4 = mul i64 %tmp3, 2 |
| 10 | ; CHECK: br label %for.body |
| 11 | ; CHECK: for.body: |
| 12 | ; CHECK: %lsr.iv5 = phi i64 [ %lsr.iv.next, %for.body ], [ %tmp4, %for.body.lr.ph ] |
| 13 | ; CHECK: %lsr.iv.next = add i64 %lsr.iv5, -2 |
| 14 | ; CHECK: %lsr.iv.next6 = inttoptr i64 %lsr.iv.next to i16* |
| 15 | ; CHECK: %cmp27 = icmp eq i16* %lsr.iv.next6, null |
| 16 | |
| 17 | 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" |
| 18 | target triple = "x86_64-unknown-linux-gnu" |
| 19 | |
| 20 | %struct.Vector2 = type { i16*, [64 x i16], i32 } |
| 21 | |
| 22 | @.str = private unnamed_addr constant [37 x i8] c"0123456789abcdefghijklmnopqrstuvwxyz\00" |
| 23 | |
| 24 | define void @_Z15IntegerToStringjjR7Vector2(i32 %i, i32 %radix, %struct.Vector2* nocapture %result) nounwind noinline { |
| 25 | entry: |
| 26 | %buffer = alloca [33 x i16], align 16 |
| 27 | %add.ptr = getelementptr inbounds [33 x i16]* %buffer, i64 0, i64 33 |
| 28 | br label %do.body |
| 29 | |
| 30 | do.body: ; preds = %do.body, %entry |
| 31 | %0 = phi i64 [ %indvar.next44, %do.body ], [ 0, %entry ] |
| 32 | %i.addr.0 = phi i32 [ %div, %do.body ], [ %i, %entry ] |
| 33 | %tmp51 = sub i64 32, %0 |
| 34 | %incdec.ptr = getelementptr [33 x i16]* %buffer, i64 0, i64 %tmp51 |
| 35 | %rem = urem i32 %i.addr.0, 10 |
| 36 | %div = udiv i32 %i.addr.0, 10 |
| 37 | %idxprom = zext i32 %rem to i64 |
| 38 | %arrayidx = getelementptr inbounds [37 x i8]* @.str, i64 0, i64 %idxprom |
| 39 | %tmp5 = load i8* %arrayidx, align 1 |
| 40 | %conv = sext i8 %tmp5 to i16 |
| 41 | store i16 %conv, i16* %incdec.ptr, align 2 |
| 42 | %1 = icmp ugt i32 %i.addr.0, 9 |
| 43 | %indvar.next44 = add i64 %0, 1 |
| 44 | br i1 %1, label %do.body, label %do.end |
| 45 | |
| 46 | do.end: ; preds = %do.body |
| 47 | %xap.0 = inttoptr i64 %0 to i1* |
| 48 | %cap.0 = ptrtoint i1* %xap.0 to i64 |
| 49 | %sub.ptr.lhs.cast = ptrtoint i16* %add.ptr to i64 |
| 50 | %sub.ptr.rhs.cast = ptrtoint i16* %incdec.ptr to i64 |
| 51 | %sub.ptr.sub = sub i64 %sub.ptr.lhs.cast, %sub.ptr.rhs.cast |
| 52 | %sub.ptr.div39 = lshr exact i64 %sub.ptr.sub, 1 |
| 53 | %conv11 = trunc i64 %sub.ptr.div39 to i32 |
| 54 | %mLength = getelementptr inbounds %struct.Vector2* %result, i64 0, i32 2 |
| 55 | %idx.ext21 = bitcast i64 %sub.ptr.div39 to i64 |
| 56 | %incdec.ptr.sum = add i64 %idx.ext21, -1 |
| 57 | %cp.0.sum = sub i64 %incdec.ptr.sum, %0 |
| 58 | %add.ptr22 = getelementptr [33 x i16]* %buffer, i64 1, i64 %cp.0.sum |
| 59 | %cmp2740 = icmp eq i64 %idx.ext21, 0 |
| 60 | br i1 %cmp2740, label %for.end, label %for.body.lr.ph |
| 61 | |
| 62 | for.body.lr.ph: ; preds = %do.end |
| 63 | %tmp16 = load i32* %mLength, align 4 |
| 64 | %mBegin = getelementptr inbounds %struct.Vector2* %result, i64 0, i32 0 |
| 65 | %tmp14 = load i16** %mBegin, align 8 |
| 66 | %tmp48 = zext i32 %tmp16 to i64 |
| 67 | br label %for.body |
| 68 | |
| 69 | for.body: ; preds = %for.body, %for.body.lr.ph |
| 70 | %indvar = phi i64 [ 0, %for.body.lr.ph ], [ %indvar.next, %for.body ] |
| 71 | %tmp46 = add i64 %tmp51, %indvar |
| 72 | %p.042 = getelementptr [33 x i16]* %buffer, i64 0, i64 %tmp46 |
| 73 | %tmp47 = sub i64 %indvar, %0 |
| 74 | %incdec.ptr32 = getelementptr [33 x i16]* %buffer, i64 1, i64 %tmp47 |
| 75 | %tmp49 = add i64 %tmp48, %indvar |
| 76 | %dst.041 = getelementptr i16* %tmp14, i64 %tmp49 |
| 77 | %tmp29 = load i16* %p.042, align 2 |
| 78 | store i16 %tmp29, i16* %dst.041, align 2 |
| 79 | %cmp27 = icmp eq i16* %incdec.ptr32, %add.ptr22 |
| 80 | %indvar.next = add i64 %indvar, 1 |
| 81 | br i1 %cmp27, label %for.end.loopexit, label %for.body |
| 82 | |
| 83 | for.end.loopexit: ; preds = %for.body |
| 84 | br label %for.end |
| 85 | |
| 86 | for.end: ; preds = %for.end.loopexit, %do.end |
| 87 | %tmp38 = load i32* %mLength, align 4 |
| 88 | %add = add i32 %tmp38, %conv11 |
| 89 | store i32 %add, i32* %mLength, align 4 |
| 90 | ret void |
| 91 | } |