1; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
2 ; RUN: opt < %s -analyze -enable-new-pm=0 -scalar-evolution | FileCheck %s
3 ; RUN: opt < %s -disable-output "-passes=print<scalar-evolution>" 2>&1 | FileCheck %s
4
5target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64"
6
7; Collection of cases exercising range logic, mostly (but not exclusively)
8; involving SCEVUnknowns.
9
10declare void @llvm.assume(i1)
11
12define i32 @ashr(i32 %a) {
13; CHECK-LABEL: 'ashr'
14; CHECK-NEXT:  Classifying expressions for: @ashr
15; CHECK-NEXT:    %ashr = ashr i32 %a, 31
16; CHECK-NEXT:    --> %ashr U: [0,1) S: [0,1)
17; CHECK-NEXT:  Determining loop execution counts for: @ashr
18;
19  %ashr = ashr i32 %a, 31
20  %pos = icmp sge i32 %a, 0
21  call void @llvm.assume(i1 %pos)
22  ret i32 %ashr
23}
24
25; Highlight the fact that non-argument non-instructions are
26; also possible.
27@G = external global i8
28define i64 @ashr_global() {
29; CHECK-LABEL: 'ashr_global'
30; CHECK-NEXT:  Classifying expressions for: @ashr_global
31; CHECK-NEXT:    %ashr = ashr i64 ptrtoint (i8* @G to i64), 63
32; CHECK-NEXT:    --> %ashr U: [-1,1) S: [-1,1)
33; CHECK-NEXT:  Determining loop execution counts for: @ashr_global
34;
35  %ashr = ashr i64 ptrtoint (i8* @G to i64), 63
36  %pos = icmp sge i8* @G, null
37  call void @llvm.assume(i1 %pos)
38  ret i64 %ashr
39}
40
41
42define i32 @shl(i32 %a) {
43; CHECK-LABEL: 'shl'
44; CHECK-NEXT:  Classifying expressions for: @shl
45; CHECK-NEXT:    %res = shl i32 %a, 2
46; CHECK-NEXT:    --> (4 * %a) U: [0,-3) S: [-2147483648,2147483645)
47; CHECK-NEXT:  Determining loop execution counts for: @shl
48;
49  %res = shl i32 %a, 2
50  %pos = icmp ult i32 %a, 1024
51  call void @llvm.assume(i1 %pos)
52  ret i32 %res
53}
54
55define i32 @lshr(i32 %a) {
56; CHECK-LABEL: 'lshr'
57; CHECK-NEXT:  Classifying expressions for: @lshr
58; CHECK-NEXT:    %res = lshr i32 %a, 31
59; CHECK-NEXT:    --> (%a /u -2147483648) U: [0,2) S: [0,2)
60; CHECK-NEXT:  Determining loop execution counts for: @lshr
61;
62  %res = lshr i32 %a, 31
63  %pos = icmp sge i32 %a, 0
64  call void @llvm.assume(i1 %pos)
65  ret i32 %res
66}
67
68
69define i32 @udiv(i32 %a) {
70; CHECK-LABEL: 'udiv'
71; CHECK-NEXT:  Classifying expressions for: @udiv
72; CHECK-NEXT:    %res = udiv i32 %a, -2147483648
73; CHECK-NEXT:    --> (%a /u -2147483648) U: [0,2) S: [0,2)
74; CHECK-NEXT:  Determining loop execution counts for: @udiv
75;
76  %res = udiv i32 %a, 2147483648
77  %pos = icmp sge i32 %a, 0
78  call void @llvm.assume(i1 %pos)
79  ret i32 %res
80}
81
82define i64 @sext(i8 %a) {
83; CHECK-LABEL: 'sext'
84; CHECK-NEXT:  Classifying expressions for: @sext
85; CHECK-NEXT:    %res = sext i8 %a to i64
86; CHECK-NEXT:    --> (sext i8 %a to i64) U: [-128,128) S: [-128,128)
87; CHECK-NEXT:  Determining loop execution counts for: @sext
88;
89  %res = sext i8 %a to i64
90  %pos = icmp sge i8 %a, 0
91  call void @llvm.assume(i1 %pos)
92  ret i64 %res
93}
94
95define i64 @zext(i8 %a) {
96; CHECK-LABEL: 'zext'
97; CHECK-NEXT:  Classifying expressions for: @zext
98; CHECK-NEXT:    %res = zext i8 %a to i64
99; CHECK-NEXT:    --> (zext i8 %a to i64) U: [0,256) S: [0,256)
100; CHECK-NEXT:  Determining loop execution counts for: @zext
101;
102  %res = zext i8 %a to i64
103  %pos = icmp sge i8 %a, 0
104  call void @llvm.assume(i1 %pos)
105  ret i64 %res
106}
107