1; RUN: opt < %s -analyze -enable-new-pm=0 -scalar-evolution | FileCheck %s
2; RUN: opt < %s -disable-output "-passes=print<scalar-evolution>" 2>&1 | FileCheck %s
3
4; Check that we convert
5;   trunc(C * a) -> trunc(C) * trunc(a)
6; if C is a constant.
7; CHECK-LABEL: @trunc_of_mul
8define i8 @trunc_of_mul(i32 %a) {
9  %b = mul i32 %a, 100
10  ; CHECK: %c
11  ; CHECK-NEXT: --> (100 * (trunc i32 %a to i8))
12  %c = trunc i32 %b to i8
13  ret i8 %c
14}
15
16; Check that we convert
17;   trunc(C + a) -> trunc(C) + trunc(a)
18; if C is a constant.
19; CHECK-LABEL: @trunc_of_add
20define i8 @trunc_of_add(i32 %a) {
21  %b = add i32 %a, 100
22  ; CHECK: %c
23  ; CHECK-NEXT: --> (100 + (trunc i32 %a to i8))
24  %c = trunc i32 %b to i8
25  ret i8 %c
26}
27
28; Check that we truncate to zero values assumed to have at least as many
29; trailing zeros as the target type.
30; CHECK-LABEL: @trunc_to_assumed_zeros
31define i8 @trunc_to_assumed_zeros(i32* %p) {
32  %a = load i32, i32* %p
33  %and = and i32 %a, 255
34  %cmp = icmp eq i32 %and, 0
35  tail call void @llvm.assume(i1 %cmp)
36  ; CHECK: %c
37  ; CHECK-NEXT: --> 0
38  %c = trunc i32 %a to i8
39  ; CHECK: %d
40  ; CHECK-NEXT: --> false
41  %d = trunc i32 %a to i1
42  ; CHECK: %e
43  ; CHECK-NEXT: --> (trunc i32 %a to i16)
44  %e = trunc i32 %a to i16
45  ret i8 %c
46}
47
48declare void @llvm.assume(i1 noundef) nofree nosync nounwind willreturn
49