blob: 286ca1e8d773eb1e5a1f45c8cc0ab35c40b233da [file] [log] [blame]
Hal Finkelf5867a72014-07-25 21:45:17 +00001; RUN: opt < %s -instcombine -S | FileCheck %s
2target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
3target triple = "x86_64-unknown-linux-gnu"
4
Hal Finkel60db0582014-09-07 18:57:58 +00005; Function Attrs: nounwind uwtable
6define i32 @foo1(i32* %a) #0 {
7entry:
8 %0 = load i32* %a, align 4
9
10; Check that the alignment has been upgraded and that the assume has not
11; been removed:
12; CHECK-LABEL: @foo1
13; CHECK-DAG: load i32* %a, align 32
14; CHECK-DAG: call void @llvm.assume
15; CHECK: ret i32
16
17 %ptrint = ptrtoint i32* %a to i64
18 %maskedptr = and i64 %ptrint, 31
19 %maskcond = icmp eq i64 %maskedptr, 0
20 tail call void @llvm.assume(i1 %maskcond)
21
22 ret i32 %0
23}
24
25; Function Attrs: nounwind uwtable
26define i32 @foo2(i32* %a) #0 {
27entry:
28; Same check as in @foo1, but make sure it works if the assume is first too.
29; CHECK-LABEL: @foo2
30; CHECK-DAG: load i32* %a, align 32
31; CHECK-DAG: call void @llvm.assume
32; CHECK: ret i32
33
34 %ptrint = ptrtoint i32* %a to i64
35 %maskedptr = and i64 %ptrint, 31
36 %maskcond = icmp eq i64 %maskedptr, 0
37 tail call void @llvm.assume(i1 %maskcond)
38
39 %0 = load i32* %a, align 4
40 ret i32 %0
41}
42
Hal Finkelf5867a72014-07-25 21:45:17 +000043; Function Attrs: nounwind
44declare void @llvm.assume(i1) #1
45
46; Function Attrs: nounwind uwtable
47define i32 @can1(i1 %a, i1 %b, i1 %c) {
48entry:
49 %and1 = and i1 %a, %b
50 %and = and i1 %and1, %c
51 tail call void @llvm.assume(i1 %and)
52
53; CHECK-LABEL: @can1
54; CHECK: call void @llvm.assume(i1 %a)
55; CHECK: call void @llvm.assume(i1 %b)
56; CHECK: call void @llvm.assume(i1 %c)
57; CHECK: ret i32
58
59 ret i32 5
60}
61
62; Function Attrs: nounwind uwtable
63define i32 @can2(i1 %a, i1 %b, i1 %c) {
64entry:
65 %v = or i1 %a, %b
66 %w = xor i1 %v, 1
67 tail call void @llvm.assume(i1 %w)
68
69; CHECK-LABEL: @can2
70; CHECK: %[[V1:[^ ]+]] = xor i1 %a, true
71; CHECK: call void @llvm.assume(i1 %[[V1]])
72; CHECK: %[[V2:[^ ]+]] = xor i1 %b, true
73; CHECK: call void @llvm.assume(i1 %[[V2]])
74; CHECK: ret i32
75
76 ret i32 5
77}
78
Hal Finkel60db0582014-09-07 18:57:58 +000079define i32 @bar1(i32 %a) #0 {
80entry:
81 %and1 = and i32 %a, 3
82
83; CHECK-LABEL: @bar1
84; CHECK: call void @llvm.assume
85; CHECK: ret i32 1
86
87 %and = and i32 %a, 7
88 %cmp = icmp eq i32 %and, 1
89 tail call void @llvm.assume(i1 %cmp)
90
91 ret i32 %and1
92}
93
94; Function Attrs: nounwind uwtable
95define i32 @bar2(i32 %a) #0 {
96entry:
97; CHECK-LABEL: @bar2
98; CHECK: call void @llvm.assume
99; CHECK: ret i32 1
100
101 %and = and i32 %a, 7
102 %cmp = icmp eq i32 %and, 1
103 tail call void @llvm.assume(i1 %cmp)
104
105 %and1 = and i32 %a, 3
106 ret i32 %and1
107}
108
109; Function Attrs: nounwind uwtable
110define i32 @bar3(i32 %a, i1 %x, i1 %y) #0 {
111entry:
112 %and1 = and i32 %a, 3
113
114; Don't be fooled by other assumes around.
115; CHECK-LABEL: @bar3
116; CHECK: call void @llvm.assume
117; CHECK: ret i32 1
118
119 tail call void @llvm.assume(i1 %x)
120
121 %and = and i32 %a, 7
122 %cmp = icmp eq i32 %and, 1
123 tail call void @llvm.assume(i1 %cmp)
124
125 tail call void @llvm.assume(i1 %y)
126
127 ret i32 %and1
128}
129
130; Function Attrs: nounwind uwtable
131define i32 @bar4(i32 %a, i32 %b) {
132entry:
133 %and1 = and i32 %b, 3
134
135; CHECK-LABEL: @bar4
136; CHECK: call void @llvm.assume
137; CHECK: call void @llvm.assume
138; CHECK: ret i32 1
139
140 %and = and i32 %a, 7
141 %cmp = icmp eq i32 %and, 1
142 tail call void @llvm.assume(i1 %cmp)
143
144 %cmp2 = icmp eq i32 %a, %b
145 tail call void @llvm.assume(i1 %cmp2)
146
147 ret i32 %and1
148}
149
150define i32 @icmp1(i32 %a) #0 {
151entry:
152 %cmp = icmp sgt i32 %a, 5
153 tail call void @llvm.assume(i1 %cmp)
154 %conv = zext i1 %cmp to i32
155 ret i32 %conv
156
157; CHECK-LABEL: @icmp1
158; CHECK: call void @llvm.assume
159; CHECK: ret i32 1
160
161}
162
163; Function Attrs: nounwind uwtable
164define i32 @icmp2(i32 %a) #0 {
165entry:
166 %cmp = icmp sgt i32 %a, 5
167 tail call void @llvm.assume(i1 %cmp)
168 %0 = zext i1 %cmp to i32
169 %lnot.ext = xor i32 %0, 1
170 ret i32 %lnot.ext
171
172; CHECK-LABEL: @icmp2
173; CHECK: call void @llvm.assume
174; CHECK: ret i32 0
175}
176
Hal Finkelf5867a72014-07-25 21:45:17 +0000177attributes #0 = { nounwind uwtable }
178attributes #1 = { nounwind }
179