equality-assume.ll
4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -S -gvn < %s | FileCheck %s
define i32 @test(i32* %p, i32 %v) {
; CHECK-LABEL: @test(
; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[P:%.*]]
; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[LOAD]], [[V:%.*]]
; CHECK-NEXT: call void @llvm.assume(i1 [[C]])
; CHECK-NEXT: ret i32 [[V]]
;
%load = load i32, i32* %p
%c = icmp eq i32 %load, %v
call void @llvm.assume(i1 %c)
ret i32 %load
}
define i32 @reverse(i32* %p, i32 %v) {
; CHECK-LABEL: @reverse(
; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[P:%.*]]
; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[LOAD]], [[V:%.*]]
; CHECK-NEXT: call void @llvm.assume(i1 [[C]])
; CHECK-NEXT: ret i32 [[V]]
;
%load = load i32, i32* %p
%c = icmp eq i32 %load, %v
call void @llvm.assume(i1 %c)
ret i32 %v
}
; Lack of equivalance due to +0.0 vs -0.0
define float @neg_float_oeq(float* %p, float %v) {
; CHECK-LABEL: @neg_float_oeq(
; CHECK-NEXT: [[LOAD:%.*]] = load float, float* [[P:%.*]]
; CHECK-NEXT: [[C:%.*]] = fcmp oeq float [[LOAD]], [[V:%.*]]
; CHECK-NEXT: call void @llvm.assume(i1 [[C]])
; CHECK-NEXT: ret float [[LOAD]]
;
%load = load float, float* %p
%c = fcmp oeq float %load, %v
call void @llvm.assume(i1 %c)
ret float %load
}
; Lack of equivalance due to +0.0 vs -0.0
define float @neg_float_ueq(float* %p, float %v) {
; CHECK-LABEL: @neg_float_ueq(
; CHECK-NEXT: [[LOAD:%.*]] = load float, float* [[P:%.*]]
; CHECK-NEXT: [[C:%.*]] = fcmp ueq float [[LOAD]], [[V:%.*]]
; CHECK-NEXT: call void @llvm.assume(i1 [[C]])
; CHECK-NEXT: ret float [[LOAD]]
;
%load = load float, float* %p
%c = fcmp ueq float %load, %v
call void @llvm.assume(i1 %c)
ret float %load
}
define float @float_oeq_constant(float* %p) {
; CHECK-LABEL: @float_oeq_constant(
; CHECK-NEXT: [[LOAD:%.*]] = load float, float* [[P:%.*]]
; CHECK-NEXT: [[C:%.*]] = fcmp oeq float [[LOAD]], 5.000000e+00
; CHECK-NEXT: call void @llvm.assume(i1 [[C]])
; CHECK-NEXT: ret float 5.000000e+00
;
%load = load float, float* %p
%c = fcmp oeq float %load, 5.0
call void @llvm.assume(i1 %c)
ret float %load
}
; Lack of equivalance due to Nan
define float @neq_float_ueq_constant(float* %p) {
; CHECK-LABEL: @neq_float_ueq_constant(
; CHECK-NEXT: [[LOAD:%.*]] = load float, float* [[P:%.*]]
; CHECK-NEXT: [[C:%.*]] = fcmp ueq float [[LOAD]], 5.000000e+00
; CHECK-NEXT: call void @llvm.assume(i1 [[C]])
; CHECK-NEXT: ret float [[LOAD]]
;
%load = load float, float* %p
%c = fcmp ueq float %load, 5.0
call void @llvm.assume(i1 %c)
ret float %load
}
define float @float_ueq_constant_nnas(float* %p) {
; CHECK-LABEL: @float_ueq_constant_nnas(
; CHECK-NEXT: [[LOAD:%.*]] = load float, float* [[P:%.*]]
; CHECK-NEXT: [[C:%.*]] = fcmp nnan ueq float [[LOAD]], 5.000000e+00
; CHECK-NEXT: call void @llvm.assume(i1 [[C]])
; CHECK-NEXT: ret float 5.000000e+00
;
%load = load float, float* %p
%c = fcmp nnan ueq float %load, 5.0
call void @llvm.assume(i1 %c)
ret float %load
}
define i32 @test2(i32* %p, i32 %v) {
; CHECK-LABEL: @test2(
; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[P:%.*]]
; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[LOAD]], [[V:%.*]]
; CHECK-NEXT: call void @llvm.assume(i1 [[C]])
; CHECK-NEXT: ret i32 [[V]]
;
%load = load i32, i32* %p
%c = icmp eq i32 %load, %v
call void @llvm.assume(i1 %c)
%load2 = load i32, i32* %p
ret i32 %load2
}
define i32 @test3(i32* %p, i32 %v) {
; CHECK-LABEL: @test3(
; CHECK-NEXT: [[LOAD:%.*]] = load i32, i32* [[P:%.*]]
; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[LOAD]], [[V:%.*]]
; CHECK-NEXT: call void @llvm.assume(i1 [[C]])
; CHECK-NEXT: br i1 undef, label [[TAKEN:%.*]], label [[MERGE:%.*]]
; CHECK: taken:
; CHECK-NEXT: br label [[MERGE]]
; CHECK: merge:
; CHECK-NEXT: ret i32 [[V]]
;
%load = load i32, i32* %p
%c = icmp eq i32 %load, %v
call void @llvm.assume(i1 %c)
br i1 undef, label %taken, label %merge
taken:
br label %merge
merge:
ret i32 %load
}
define i32 @trivial_constants(i32* %p) {
; CHECK-LABEL: @trivial_constants(
; CHECK-NEXT: br i1 undef, label [[TAKEN:%.*]], label [[MERGE:%.*]]
; CHECK: taken:
; CHECK-NEXT: br label [[MERGE]]
; CHECK: merge:
; CHECK-NEXT: ret i32 0
;
%c = icmp eq i32 0, 0
call void @llvm.assume(i1 %c)
br i1 undef, label %taken, label %merge
taken:
br label %merge
merge:
ret i32 0
}
define i32 @conflicting_constants(i32* %p) {
; CHECK-LABEL: @conflicting_constants(
; CHECK-NEXT: store i8 undef, i8* null
; CHECK-NEXT: br i1 undef, label [[TAKEN:%.*]], label [[MERGE:%.*]]
; CHECK: taken:
; CHECK-NEXT: br label [[MERGE]]
; CHECK: merge:
; CHECK-NEXT: ret i32 1
;
%c = icmp eq i32 0, 5
call void @llvm.assume(i1 %c)
br i1 undef, label %taken, label %merge
taken:
br label %merge
merge:
ret i32 1
}
declare void @llvm.assume(i1)