1 ; RUN: opt < %s -indvars -S | FileCheck %s 2 3 define void @test0(i32* %a) { 4 ; CHECK-LABEL: @test0( 5 entry: 6 br label %for.body 7 8 for.body: ; preds = %entry, %for.body 9 %i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ] 10 %div = sdiv i32 %i.01, 2 11 ; CHECK-NOT: sdiv 12 ; CHECK: udiv 13 %idxprom = sext i32 %div to i64 14 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom 15 store i32 %i.01, i32* %arrayidx, align 4 16 %inc = add nsw i32 %i.01, 1 17 %cmp = icmp slt i32 %inc, 64 18 br i1 %cmp, label %for.body, label %for.end 19 20 for.end: ; preds = %for.body 21 ret void 22 } 23 24 define void @test1(i32* %a) { 25 ; CHECK-LABEL: @test1( 26 entry: 27 br label %for.body 28 29 for.body: ; preds = %entry, %for.body 30 %i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ] 31 %div = sdiv exact i32 %i.01, 2 32 ; CHECK-NOT: sdiv 33 ; CHECK: udiv exact 34 %idxprom = sext i32 %div to i64 35 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom 36 store i32 %i.01, i32* %arrayidx, align 4 37 %inc = add nsw i32 %i.01, 1 38 %cmp = icmp slt i32 %inc, 64 39 br i1 %cmp, label %for.body, label %for.end 40 41 for.end: ; preds = %for.body 42 ret void 43 } 44 45 define void @test2(i32* %a, i32 %d) { 46 ; CHECK-LABEL: @test2( 47 entry: 48 br label %for.body 49 50 for.body: ; preds = %entry, %for.body 51 %i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ] 52 %mul = mul nsw i32 %i.01, 64 53 %div = sdiv i32 %mul, %d 54 ; CHECK-NOT: udiv 55 %idxprom = sext i32 %div to i64 56 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom 57 store i32 %i.01, i32* %arrayidx, align 4 58 %inc = add nsw i32 %i.01, 1 59 %cmp = icmp slt i32 %inc, 64 60 br i1 %cmp, label %for.body, label %for.end 61 62 for.end: ; preds = %for.body 63 ret void 64 } 65 66 define void @test3(i32* %a) { 67 ; CHECK-LABEL: @test3( 68 entry: 69 br label %for.body 70 71 for.body: ; preds = %entry, %for.body 72 %i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ] 73 %div = sdiv i32 2048, %i.01 74 ; CHECK: udiv 75 ; CHECK-NOT: sdiv 76 %idxprom = sext i32 %div to i64 77 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom 78 store i32 %i.01, i32* %arrayidx, align 4 79 %inc = add nsw i32 %i.01, 1 80 %cmp = icmp slt i32 %inc, 64 81 br i1 %cmp, label %for.body, label %for.end 82 83 for.end: ; preds = %for.body 84 ret void 85 } 86 87 define void @test4(i32* %a) { 88 ; CHECK-LABEL: @test4( 89 entry: 90 br label %for.body 91 92 for.body: ; preds = %entry, %for.body 93 %i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ] 94 %mul = mul nsw i32 %i.01, 64 95 %div = sdiv i32 %mul, 8 96 ; CHECK: udiv 97 ; CHECK-NOT: sdiv 98 %idxprom = sext i32 %div to i64 99 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom 100 store i32 %i.01, i32* %arrayidx, align 4 101 %inc = add nsw i32 %i.01, 1 102 %cmp = icmp slt i32 %inc, 64 103 br i1 %cmp, label %for.body, label %for.end 104 105 for.end: ; preds = %for.body 106 ret void 107 } 108 109 define void @test5(i32* %a) { 110 ; CHECK-LABEL: @test5( 111 entry: 112 br label %for.body 113 114 for.body: ; preds = %entry, %for.body 115 %i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ] 116 %mul = mul nsw i32 %i.01, 64 117 %div = sdiv i32 %mul, 6 118 ; CHECK: udiv 119 ; CHECK-NOT: sdiv 120 %idxprom = sext i32 %div to i64 121 %arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom 122 store i32 %i.01, i32* %arrayidx, align 4 123 %inc = add nsw i32 %i.01, 1 124 %cmp = icmp slt i32 %inc, 64 125 br i1 %cmp, label %for.body, label %for.end 126 127 for.end: ; preds = %for.body 128 ret void 129 } 130 131