blob: 6d670c84c481a458e9dbc8d57c5164ea4410447f [file] [log] [blame]
Dan Gohman3268e4d2011-05-18 21:02:18 +00001; RUN: opt -loop-reduce -S < %s | FileCheck %s
2; PR9939
3
Andrew Trickcbf2fe02012-01-07 00:29:20 +00004; LSR should properly handle the post-inc offset when folding the
Dan Gohman3268e4d2011-05-18 21:02:18 +00005; non-IV operand of an icmp into the IV.
6
Wei Mia49559b2016-02-04 01:27:38 +00007; CHECK: [[r1:%[a-z0-9\.]+]] = sub i64 %sub.ptr.lhs.cast, %sub.ptr.rhs.cast
8; CHECK: [[r2:%[a-z0-9\.]+]] = lshr exact i64 [[r1]], 1
Serguei Katkov6a7a4c62018-01-09 06:47:14 +00009; CHECK: [[r3:%[a-z0-9\.]+]] = bitcast i64 [[r2]] to i64
Wei Mia49559b2016-02-04 01:27:38 +000010; CHECK: for.body.lr.ph:
Serguei Katkov6a7a4c62018-01-09 06:47:14 +000011; CHECK: [[r4:%[a-z0-9]+]] = shl i64 [[r3]], 1
Dan Gohman3268e4d2011-05-18 21:02:18 +000012; CHECK: br label %for.body
13; CHECK: for.body:
Serguei Katkov6a7a4c62018-01-09 06:47:14 +000014; CHECK: %lsr.iv2 = phi i64 [ %lsr.iv.next, %for.body ], [ [[r4]], %for.body.lr.ph ]
Benjamin Kramer547b6c52011-09-27 20:39:19 +000015; CHECK: %lsr.iv.next = add i64 %lsr.iv2, -2
16; CHECK: %lsr.iv.next3 = inttoptr i64 %lsr.iv.next to i16*
17; CHECK: %cmp27 = icmp eq i16* %lsr.iv.next3, null
Dan Gohman3268e4d2011-05-18 21:02:18 +000018
19target 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"
Dan Gohman3268e4d2011-05-18 21:02:18 +000020
21%struct.Vector2 = type { i16*, [64 x i16], i32 }
22
23@.str = private unnamed_addr constant [37 x i8] c"0123456789abcdefghijklmnopqrstuvwxyz\00"
24
25define void @_Z15IntegerToStringjjR7Vector2(i32 %i, i32 %radix, %struct.Vector2* nocapture %result) nounwind noinline {
26entry:
27 %buffer = alloca [33 x i16], align 16
David Blaikie79e6c742015-02-27 19:29:02 +000028 %add.ptr = getelementptr inbounds [33 x i16], [33 x i16]* %buffer, i64 0, i64 33
Max Kazantsev41450322017-05-26 06:47:04 +000029 %sub.ptr.lhs.cast = ptrtoint i16* %add.ptr to i64
30 %sub.ptr.rhs.cast = ptrtoint i16* %add.ptr to i64
Dan Gohman3268e4d2011-05-18 21:02:18 +000031 br label %do.body
32
33do.body: ; preds = %do.body, %entry
34 %0 = phi i64 [ %indvar.next44, %do.body ], [ 0, %entry ]
35 %i.addr.0 = phi i32 [ %div, %do.body ], [ %i, %entry ]
36 %tmp51 = sub i64 32, %0
David Blaikie79e6c742015-02-27 19:29:02 +000037 %incdec.ptr = getelementptr [33 x i16], [33 x i16]* %buffer, i64 0, i64 %tmp51
Dan Gohman3268e4d2011-05-18 21:02:18 +000038 %rem = urem i32 %i.addr.0, 10
39 %div = udiv i32 %i.addr.0, 10
40 %idxprom = zext i32 %rem to i64
David Blaikie79e6c742015-02-27 19:29:02 +000041 %arrayidx = getelementptr inbounds [37 x i8], [37 x i8]* @.str, i64 0, i64 %idxprom
David Blaikiea79ac142015-02-27 21:17:42 +000042 %tmp5 = load i8, i8* %arrayidx, align 1
Dan Gohman3268e4d2011-05-18 21:02:18 +000043 %conv = sext i8 %tmp5 to i16
44 store i16 %conv, i16* %incdec.ptr, align 2
45 %1 = icmp ugt i32 %i.addr.0, 9
46 %indvar.next44 = add i64 %0, 1
47 br i1 %1, label %do.body, label %do.end
48
49do.end: ; preds = %do.body
50 %xap.0 = inttoptr i64 %0 to i1*
51 %cap.0 = ptrtoint i1* %xap.0 to i64
Dan Gohman3268e4d2011-05-18 21:02:18 +000052 %sub.ptr.sub = sub i64 %sub.ptr.lhs.cast, %sub.ptr.rhs.cast
53 %sub.ptr.div39 = lshr exact i64 %sub.ptr.sub, 1
54 %conv11 = trunc i64 %sub.ptr.div39 to i32
David Blaikie79e6c742015-02-27 19:29:02 +000055 %mLength = getelementptr inbounds %struct.Vector2, %struct.Vector2* %result, i64 0, i32 2
Dan Gohman3268e4d2011-05-18 21:02:18 +000056 %idx.ext21 = bitcast i64 %sub.ptr.div39 to i64
57 %incdec.ptr.sum = add i64 %idx.ext21, -1
58 %cp.0.sum = sub i64 %incdec.ptr.sum, %0
David Blaikie79e6c742015-02-27 19:29:02 +000059 %add.ptr22 = getelementptr [33 x i16], [33 x i16]* %buffer, i64 1, i64 %cp.0.sum
Dan Gohman3268e4d2011-05-18 21:02:18 +000060 %cmp2740 = icmp eq i64 %idx.ext21, 0
61 br i1 %cmp2740, label %for.end, label %for.body.lr.ph
62
63for.body.lr.ph: ; preds = %do.end
David Blaikiea79ac142015-02-27 21:17:42 +000064 %tmp16 = load i32, i32* %mLength, align 4
David Blaikie79e6c742015-02-27 19:29:02 +000065 %mBegin = getelementptr inbounds %struct.Vector2, %struct.Vector2* %result, i64 0, i32 0
David Blaikiea79ac142015-02-27 21:17:42 +000066 %tmp14 = load i16*, i16** %mBegin, align 8
Dan Gohman3268e4d2011-05-18 21:02:18 +000067 %tmp48 = zext i32 %tmp16 to i64
68 br label %for.body
69
70for.body: ; preds = %for.body, %for.body.lr.ph
71 %indvar = phi i64 [ 0, %for.body.lr.ph ], [ %indvar.next, %for.body ]
72 %tmp46 = add i64 %tmp51, %indvar
David Blaikie79e6c742015-02-27 19:29:02 +000073 %p.042 = getelementptr [33 x i16], [33 x i16]* %buffer, i64 0, i64 %tmp46
Dan Gohman3268e4d2011-05-18 21:02:18 +000074 %tmp47 = sub i64 %indvar, %0
David Blaikie79e6c742015-02-27 19:29:02 +000075 %incdec.ptr32 = getelementptr [33 x i16], [33 x i16]* %buffer, i64 1, i64 %tmp47
Dan Gohman3268e4d2011-05-18 21:02:18 +000076 %tmp49 = add i64 %tmp48, %indvar
David Blaikie79e6c742015-02-27 19:29:02 +000077 %dst.041 = getelementptr i16, i16* %tmp14, i64 %tmp49
David Blaikiea79ac142015-02-27 21:17:42 +000078 %tmp29 = load i16, i16* %p.042, align 2
Dan Gohman3268e4d2011-05-18 21:02:18 +000079 store i16 %tmp29, i16* %dst.041, align 2
80 %cmp27 = icmp eq i16* %incdec.ptr32, %add.ptr22
81 %indvar.next = add i64 %indvar, 1
82 br i1 %cmp27, label %for.end.loopexit, label %for.body
83
84for.end.loopexit: ; preds = %for.body
85 br label %for.end
86
87for.end: ; preds = %for.end.loopexit, %do.end
David Blaikiea79ac142015-02-27 21:17:42 +000088 %tmp38 = load i32, i32* %mLength, align 4
Dan Gohman3268e4d2011-05-18 21:02:18 +000089 %add = add i32 %tmp38, %conv11
90 store i32 %add, i32* %mLength, align 4
91 ret void
92}