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