• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 @div(i32 %val) nounwind {
7; CHECK-LABEL: 'div'
8; CHECK-NEXT:  Classifying expressions for: @div
9; CHECK-NEXT:    %tmp1 = udiv i32 %val, 16
10; CHECK-NEXT:    -->  (%val /u 16) U: [0,268435456) S: [0,268435456)
11; CHECK-NEXT:    %tmp2 = mul i32 %tmp1, 16
12; CHECK-NEXT:    -->  (16 * (%val /u 16))<nuw> U: [0,-15) S: [-2147483648,2147483633)
13; CHECK-NEXT:  Determining loop execution counts for: @div
14;
15  %tmp1 = udiv i32 %val, 16
16  %tmp2 = mul i32 %tmp1, 16
17  ret i32 %tmp2
18}
19
20define i32 @sdiv(i32 %val) nounwind {
21; CHECK-LABEL: 'sdiv'
22; CHECK-NEXT:  Classifying expressions for: @sdiv
23; CHECK-NEXT:    %tmp1 = sdiv i32 %val, 16
24; CHECK-NEXT:    -->  %tmp1 U: full-set S: [-134217728,134217728)
25; CHECK-NEXT:    %tmp2 = mul i32 %tmp1, 16
26; CHECK-NEXT:    -->  (16 * %tmp1)<nsw> U: [0,-15) S: [-2147483648,2147483633)
27; CHECK-NEXT:  Determining loop execution counts for: @sdiv
28;
29  %tmp1 = sdiv i32 %val, 16
30  %tmp2 = mul i32 %tmp1, 16
31  ret i32 %tmp2
32}
33
34; Or, it could be a number of equivalent patterns with mask:
35;   b) x &  (-1 << nbits)
36;   d) x >> nbits << nbits
37
38define i32 @mask_b(i32 %val) nounwind {
39; CHECK-LABEL: 'mask_b'
40; CHECK-NEXT:  Classifying expressions for: @mask_b
41; CHECK-NEXT:    %masked = and i32 %val, -16
42; CHECK-NEXT:    -->  (16 * (%val /u 16))<nuw> U: [0,-15) S: [-2147483648,2147483633)
43; CHECK-NEXT:  Determining loop execution counts for: @mask_b
44;
45  %masked = and i32 %val, -16
46  ret i32 %masked
47}
48
49define i32 @mask_d(i32 %val) nounwind {
50; CHECK-LABEL: 'mask_d'
51; CHECK-NEXT:  Classifying expressions for: @mask_d
52; CHECK-NEXT:    %lowbitscleared = lshr i32 %val, 4
53; CHECK-NEXT:    -->  (%val /u 16) U: [0,268435456) S: [0,268435456)
54; CHECK-NEXT:    %masked = shl i32 %lowbitscleared, 4
55; CHECK-NEXT:    -->  (16 * (%val /u 16))<nuw> U: [0,-15) S: [-2147483648,2147483633)
56; CHECK-NEXT:  Determining loop execution counts for: @mask_d
57;
58  %lowbitscleared = lshr i32 %val, 4
59  %masked = shl i32 %lowbitscleared, 4
60  ret i32 %masked
61}
62