Home | History | Annotate | Download | only in IndVarSimplify
      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   %rem = srem i32 %i.01, 2
     11 ; CHECK-NOT: srem
     12 ; CHECK:     urem
     13   %idxprom = sext i32 %rem 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 @test2(i32* %a, i32 %d) {
     25 ; CHECK-LABEL: @test2(
     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   %mul = mul nsw i32 %i.01, 64
     32   %rem = srem i32 %mul, %d
     33 ; CHECK-NOT: urem
     34   %idxprom = sext i32 %rem 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 @test3(i32* %a) {
     46 ; CHECK-LABEL: @test3(
     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   %rem = srem i32 2048, %i.01
     53 ; CHECK:     urem
     54 ; CHECK-NOT: srem
     55   %idxprom = sext i32 %rem 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 @test4(i32* %a) {
     67 ; CHECK-LABEL: @test4(
     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   %mul = mul nsw i32 %i.01, 64
     74   %rem = srem i32 %mul, 7
     75 ; CHECK:     urem
     76 ; CHECK-NOT: srem
     77   %idxprom = sext i32 %rem to i64
     78   %arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom
     79   store i32 %i.01, i32* %arrayidx, align 4
     80   %inc = add nsw i32 %i.01, 1
     81   %cmp = icmp slt i32 %inc, 64
     82   br i1 %cmp, label %for.body, label %for.end
     83 
     84 for.end:                                          ; preds = %for.body
     85   ret void
     86 }
     87 
     88 define void @test5(i32* %a) {
     89 ; CHECK-LABEL: @test5(
     90 entry:
     91   br label %for.body
     92 
     93 for.body:                                         ; preds = %entry, %for.body
     94   %i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
     95   %mul = mul nsw i32 %i.01, 64
     96   %rem = srem i32 %mul, 6
     97 ; CHECK:     urem
     98 ; CHECK-NOT: srem
     99   %idxprom = sext i32 %rem to i64
    100   %arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom
    101   store i32 %i.01, i32* %arrayidx, align 4
    102   %inc = add nsw i32 %i.01, 1
    103   %cmp = icmp slt i32 %inc, 64
    104   br i1 %cmp, label %for.body, label %for.end
    105 
    106 for.end:                                          ; preds = %for.body
    107   ret void
    108 }
    109 
    110