1; RUN: opt -analyze -enable-new-pm=0 -scalar-evolution -S < %s | FileCheck %s
2; RUN: opt -disable-output "-passes=print<scalar-evolution>" -S < %s 2>&1 | FileCheck %s
3
4define i64 @test1(i32 %a, i32 %b) {
5; CHECK-LABEL: @test1
6  %div = udiv i32 %a, %b
7  %zext = zext i32 %div to i64
8; CHECK: %zext
9; CHECK-NEXT: -->  ((zext i32 %a to i64) /u (zext i32 %b to i64))
10  ret i64 %zext
11}
12
13define i64 @test2(i32 %a, i32 %b) {
14; CHECK-LABEL: @test2
15  %rem = urem i32 %a, %b
16  %zext = zext i32 %rem to i64
17; CHECK: %zext
18; CHECK-NEXT: -->  ((zext i32 %a to i64) + (-1 * (zext i32 %b to i64) * ((zext i32 %a to i64) /u (zext i32 %b to i64))))
19  ret i64 %zext
20}
21
22define i64 @test3(i32 %a, i32 %b) {
23; CHECK-LABEL: @test3
24  %div = udiv i32 %a, %b
25  %mul = mul i32 %div, %b
26  %sub = sub i32 %a, %mul
27  %zext = zext i32 %sub to i64
28; CHECK: %zext
29; CHECK-NEXT: -->  ((zext i32 %a to i64) + (-1 * (zext i32 %b to i64) * ((zext i32 %a to i64) /u (zext i32 %b to i64))))
30  ret i64 %zext
31}
32
33define i64 @test4(i32 %t) {
34; CHECK-LABEL: @test4
35  %a = udiv i32 %t, 2
36  %div = udiv i32 %t, 112
37  %mul = mul i32 %div, 56
38  %sub = sub i32 %a, %mul
39  %zext = zext i32 %sub to i64
40; CHECK: %zext
41; CHECK-NEXT: -->  ((-56 * ((zext i32 %t to i64) /u 112))<nsw> + ((zext i32 %t to i64) /u 2))
42  ret i64 %zext
43}
44