1; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
2; RUN: opt -S -analyze -enable-new-pm=0 -scalar-evolution < %s | FileCheck %s
3; RUN: opt -S -disable-output "-passes=print<scalar-evolution>" < %s 2>&1 | FileCheck %s
4
5; The obvious case.
6define i32 @mul(i32 %val) nounwind {
7; CHECK-LABEL: 'mul'
8; CHECK-NEXT:  Classifying expressions for: @mul
9; CHECK-NEXT:    %tmp1 = mul i32 %val, 16
10; CHECK-NEXT:    -->  (16 * %val) U: [0,-15) S: [-2147483648,2147483633)
11; CHECK-NEXT:    %tmp2 = udiv i32 %tmp1, 16
12; CHECK-NEXT:    -->  ((16 * %val) /u 16) U: [0,268435456) S: [0,268435456)
13; CHECK-NEXT:  Determining loop execution counts for: @mul
14;
15  %tmp1 = mul i32 %val, 16
16  %tmp2 = udiv i32 %tmp1, 16
17  ret i32 %tmp2
18}
19
20; Or, it could be any number of equivalent patterns with mask:
21;   a) x &  (1 << nbits) - 1
22;   b) x & ~(-1 << nbits)
23;   c) x &  (-1 >> (32 - y))
24;   d) x << (32 - y) >> (32 - y)
25
26define i32 @mask_abc(i32 %val) nounwind {
27; CHECK-LABEL: 'mask_abc'
28; CHECK-NEXT:  Classifying expressions for: @mask_abc
29; CHECK-NEXT:    %masked = and i32 %val, 15
30; CHECK-NEXT:    -->  (zext i4 (trunc i32 %val to i4) to i32) U: [0,16) S: [0,16)
31; CHECK-NEXT:  Determining loop execution counts for: @mask_abc
32;
33  %masked = and i32 %val, 15
34  ret i32 %masked
35}
36
37define i32 @mask_d(i32 %val) nounwind {
38; CHECK-LABEL: 'mask_d'
39; CHECK-NEXT:  Classifying expressions for: @mask_d
40; CHECK-NEXT:    %highbitscleared = shl i32 %val, 4
41; CHECK-NEXT:    -->  (16 * %val) U: [0,-15) S: [-2147483648,2147483633)
42; CHECK-NEXT:    %masked = lshr i32 %highbitscleared, 4
43; CHECK-NEXT:    -->  ((16 * %val) /u 16) U: [0,268435456) S: [0,268435456)
44; CHECK-NEXT:  Determining loop execution counts for: @mask_d
45;
46  %highbitscleared = shl i32 %val, 4
47  %masked = lshr i32 %highbitscleared, 4
48  ret i32 %masked
49}
50