1; RUN: opt < %s -indvars -S | FileCheck %s 2; RUN: opt < %s -indvars -enable-iv-rewrite=false -S | FileCheck %s 3; 4; PR1301 5 6; Do a bunch of analysis and prove that the loops can use an i32 trip 7; count without casting. 8; 9; Note that all four functions should actually be converted to 10; memset. However, this test case validates indvars behavior. We 11; don't check that phis are "folded together" because that is a job 12; for loop strength reduction. But indvars must remove sext, zext, and add i8. 13; 14; CHECK-NOT: {{sext|zext|add i8}} 15 16; ModuleID = 'ada.bc' 17target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-n8:16:32" 18target triple = "i686-pc-linux-gnu" 19 20define void @kinds__sbytezero([256 x i32]* nocapture %a) nounwind { 21bb.thread: 22 %tmp46 = getelementptr [256 x i32]* %a, i32 0, i32 0 ; <i32*> [#uses=1] 23 store i32 0, i32* %tmp46 24 br label %bb 25 26bb: ; preds = %bb, %bb.thread 27 %i.0.reg2mem.0 = phi i8 [ -128, %bb.thread ], [ %tmp8, %bb ] ; <i8> [#uses=1] 28 %tmp8 = add i8 %i.0.reg2mem.0, 1 ; <i8> [#uses=3] 29 %tmp1 = sext i8 %tmp8 to i32 ; <i32> [#uses=1] 30 %tmp3 = add i32 %tmp1, 128 ; <i32> [#uses=1] 31 %tmp4 = getelementptr [256 x i32]* %a, i32 0, i32 %tmp3 ; <i32*> [#uses=1] 32 store i32 0, i32* %tmp4 33 %0 = icmp eq i8 %tmp8, 127 ; <i1> [#uses=1] 34 br i1 %0, label %return, label %bb 35 36return: ; preds = %bb 37 ret void 38} 39 40define void @kinds__ubytezero([256 x i32]* nocapture %a) nounwind { 41bb.thread: 42 %tmp35 = getelementptr [256 x i32]* %a, i32 0, i32 0 ; <i32*> [#uses=1] 43 store i32 0, i32* %tmp35 44 br label %bb 45 46bb: ; preds = %bb, %bb.thread 47 %i.0.reg2mem.0 = phi i8 [ 0, %bb.thread ], [ %tmp7, %bb ] ; <i8> [#uses=1] 48 %tmp7 = add i8 %i.0.reg2mem.0, 1 ; <i8> [#uses=3] 49 %tmp1 = zext i8 %tmp7 to i32 ; <i32> [#uses=1] 50 %tmp3 = getelementptr [256 x i32]* %a, i32 0, i32 %tmp1 ; <i32*> [#uses=1] 51 store i32 0, i32* %tmp3 52 %0 = icmp eq i8 %tmp7, -1 ; <i1> [#uses=1] 53 br i1 %0, label %return, label %bb 54 55return: ; preds = %bb 56 ret void 57} 58 59define void @kinds__srangezero([21 x i32]* nocapture %a) nounwind { 60bb.thread: 61 br label %bb 62 63bb: ; preds = %bb, %bb.thread 64 %i.0.reg2mem.0 = phi i8 [ -10, %bb.thread ], [ %tmp7, %bb ] ; <i8> [#uses=2] 65 %tmp12 = sext i8 %i.0.reg2mem.0 to i32 ; <i32> [#uses=1] 66 %tmp4 = add i32 %tmp12, 10 ; <i32> [#uses=1] 67 %tmp5 = getelementptr [21 x i32]* %a, i32 0, i32 %tmp4 ; <i32*> [#uses=1] 68 store i32 0, i32* %tmp5 69 %tmp7 = add i8 %i.0.reg2mem.0, 1 ; <i8> [#uses=2] 70 %0 = icmp sgt i8 %tmp7, 10 ; <i1> [#uses=1] 71 br i1 %0, label %return, label %bb 72 73return: ; preds = %bb 74 ret void 75} 76 77define void @kinds__urangezero([21 x i32]* nocapture %a) nounwind { 78bb.thread: 79 br label %bb 80 81bb: ; preds = %bb, %bb.thread 82 %i.0.reg2mem.0 = phi i8 [ 10, %bb.thread ], [ %tmp7, %bb ] ; <i8> [#uses=2] 83 %tmp12 = sext i8 %i.0.reg2mem.0 to i32 ; <i32> [#uses=1] 84 %tmp4 = add i32 %tmp12, -10 ; <i32> [#uses=1] 85 %tmp5 = getelementptr [21 x i32]* %a, i32 0, i32 %tmp4 ; <i32*> [#uses=1] 86 store i32 0, i32* %tmp5 87 %tmp7 = add i8 %i.0.reg2mem.0, 1 ; <i8> [#uses=2] 88 %0 = icmp sgt i8 %tmp7, 30 ; <i1> [#uses=1] 89 br i1 %0, label %return, label %bb 90 91return: ; preds = %bb 92 ret void 93} 94