Skip to content

Commit d421080

Browse files
committed
[ConstraintElimination] Add tests for nested GEPs with multiple indices.
1 parent c68c19f commit d421080

File tree

1 file changed

+185
-0
lines changed

1 file changed

+185
-0
lines changed
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s
3+
4+
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
5+
6+
define i1 @test_outer_gep_last_index_no_overflow_all_inbounds(ptr %dst) {
7+
; CHECK-LABEL: @test_outer_gep_last_index_no_overflow_all_inbounds(
8+
; CHECK-NEXT: [[DST_0:%.*]] = getelementptr inbounds ptr, ptr [[DST:%.*]], i64 0
9+
; CHECK-NEXT: [[UPPER:%.*]] = getelementptr inbounds ptr, ptr [[DST]], i64 2
10+
; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST_0]], i64 1, i64 1
11+
; CHECK-NEXT: [[C_1:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
12+
; CHECK-NEXT: ret i1 true
13+
;
14+
%dst.0 = getelementptr inbounds ptr, ptr %dst, i64 0
15+
%upper = getelementptr inbounds ptr, ptr %dst, i64 2
16+
%gep.1 = getelementptr inbounds [2 x i32] , ptr %dst.0, i64 1, i64 1
17+
%c.1 = icmp ult ptr %gep.1, %upper
18+
ret i1 %c.1
19+
}
20+
21+
define i1 @test_outer_gep_last_index_overflow_all_inbounds(ptr %dst) {
22+
; CHECK-LABEL: @test_outer_gep_last_index_overflow_all_inbounds(
23+
; CHECK-NEXT: [[DST_0:%.*]] = getelementptr inbounds ptr, ptr [[DST:%.*]], i64 0
24+
; CHECK-NEXT: [[UPPER:%.*]] = getelementptr inbounds ptr, ptr [[DST]], i64 2
25+
; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST_0]], i64 1, i64 2
26+
; CHECK-NEXT: [[C:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
27+
; CHECK-NEXT: ret i1 true
28+
;
29+
%dst.0 = getelementptr inbounds ptr, ptr %dst, i64 0
30+
%upper = getelementptr inbounds ptr, ptr %dst, i64 2
31+
%gep.1 = getelementptr inbounds [2 x i32] , ptr %dst.0, i64 1, i64 2
32+
%c = icmp ult ptr %gep.1, %upper
33+
ret i1 %c
34+
}
35+
36+
define i1 @test_inner_gep_multiple_indices_ult_true_all_inbounds(ptr %dst) {
37+
; CHECK-LABEL: @test_inner_gep_multiple_indices_ult_true_all_inbounds(
38+
; CHECK-NEXT: [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 0, i64 0
39+
; CHECK-NEXT: [[UPPER:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST]], i64 0, i64 2
40+
; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr inbounds i32, ptr [[DST_0]], i64 1
41+
; CHECK-NEXT: [[C:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
42+
; CHECK-NEXT: [[C_2:%.*]] = icmp uge ptr [[GEP_1]], [[DST_0]]
43+
; CHECK-NEXT: ret i1 [[C]]
44+
;
45+
%dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 0
46+
%upper = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 2
47+
%gep.1 = getelementptr inbounds i32, ptr %dst.0, i64 1
48+
%c = icmp ult ptr %gep.1, %upper
49+
%c.2 = icmp uge ptr %gep.1, %dst.0
50+
ret i1 %c
51+
}
52+
53+
define i1 @test_inner_gep_multiple_indices_uge_true_all_inbounds(ptr %dst) {
54+
; CHECK-LABEL: @test_inner_gep_multiple_indices_uge_true_all_inbounds(
55+
; CHECK-NEXT: [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 0, i64 0
56+
; CHECK-NEXT: [[UPPER:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST]], i64 0, i64 2
57+
; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr inbounds i32, ptr [[DST_0]], i64 1
58+
; CHECK-NEXT: [[C:%.*]] = icmp uge ptr [[GEP_1]], [[DST_0]]
59+
; CHECK-NEXT: ret i1 [[C]]
60+
;
61+
%dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 0
62+
%upper = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 2
63+
%gep.1 = getelementptr inbounds i32, ptr %dst.0, i64 1
64+
%c = icmp uge ptr %gep.1, %dst.0
65+
ret i1 %c
66+
}
67+
68+
define i1 @test_inner_gep_multiple_indices_ult_false_all_inbounds(ptr %dst) {
69+
; CHECK-LABEL: @test_inner_gep_multiple_indices_ult_false_all_inbounds(
70+
; CHECK-NEXT: entry:
71+
; CHECK-NEXT: [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 0, i64 0
72+
; CHECK-NEXT: [[UPPER:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST]], i64 0, i64 2
73+
; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr inbounds i32, ptr [[DST_0]], i64 2
74+
; CHECK-NEXT: [[C:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
75+
; CHECK-NEXT: ret i1 [[C]]
76+
;
77+
entry:
78+
%dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 0
79+
%upper = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 2
80+
%gep.1 = getelementptr inbounds i32, ptr %dst.0, i64 2
81+
%c = icmp ult ptr %gep.1, %upper
82+
ret i1 %c
83+
}
84+
85+
define i1 @test_inner_gep_multiple_indices_uge_true_all_inbounds_2(ptr %dst) {
86+
; CHECK-LABEL: @test_inner_gep_multiple_indices_uge_true_all_inbounds_2(
87+
; CHECK-NEXT: entry:
88+
; CHECK-NEXT: [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 0, i64 0
89+
; CHECK-NEXT: [[UPPER:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST]], i64 0, i64 2
90+
; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr inbounds i32, ptr [[DST_0]], i64 2
91+
; CHECK-NEXT: [[C:%.*]] = icmp uge ptr [[GEP_1]], [[DST_0]]
92+
; CHECK-NEXT: ret i1 [[C]]
93+
;
94+
entry:
95+
%dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 0
96+
%upper = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 2
97+
%gep.1 = getelementptr inbounds i32, ptr %dst.0, i64 2
98+
%c = icmp uge ptr %gep.1, %dst.0
99+
ret i1 %c
100+
}
101+
102+
define i1 @test_inner_gep_multiple_indices_ult_true_inc_gep_all_inbounds_overflow(ptr %dst) {
103+
; CHECK-LABEL: @test_inner_gep_multiple_indices_ult_true_inc_gep_all_inbounds_overflow(
104+
; CHECK-NEXT: entry:
105+
; CHECK-NEXT: [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 0, i64 0
106+
; CHECK-NEXT: [[UPPER:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST]], i64 0, i64 6
107+
; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr i32, ptr [[DST_0]], i64 2
108+
; CHECK-NEXT: [[C:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
109+
; CHECK-NEXT: ret i1 [[C]]
110+
;
111+
entry:
112+
%dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 0
113+
%upper = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 6
114+
%gep.1 = getelementptr i32, i32* %dst.0, i64 2
115+
%c = icmp ult i32* %gep.1, %upper
116+
ret i1 %c
117+
}
118+
119+
define i1 @test_inner_gep_multiple_indices_ult_true_inc_gep_not_inbounds(ptr %dst) {
120+
; CHECK-LABEL: @test_inner_gep_multiple_indices_ult_true_inc_gep_not_inbounds(
121+
; CHECK-NEXT: entry:
122+
; CHECK-NEXT: [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 0, i64 0
123+
; CHECK-NEXT: [[UPPER:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST]], i64 0, i64 2
124+
; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr i32, ptr [[DST_0]], i64 1
125+
; CHECK-NEXT: [[C:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
126+
; CHECK-NEXT: ret i1 [[C]]
127+
;
128+
entry:
129+
%dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 0
130+
%upper = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 2
131+
%gep.1 = getelementptr i32, ptr %dst.0, i64 1
132+
%c = icmp ult i32* %gep.1, %upper
133+
ret i1 %c
134+
}
135+
136+
define i1 @test_inner_gep_multiple_indices_uge_true_inc_gep_not_inbounds(ptr %dst) {
137+
; CHECK-LABEL: @test_inner_gep_multiple_indices_uge_true_inc_gep_not_inbounds(
138+
; CHECK-NEXT: entry:
139+
; CHECK-NEXT: [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 0, i64 0
140+
; CHECK-NEXT: [[UPPER:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST]], i64 0, i64 2
141+
; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr i32, ptr [[DST_0]], i64 1
142+
; CHECK-NEXT: [[C:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
143+
; CHECK-NEXT: ret i1 [[C]]
144+
;
145+
entry:
146+
%dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 0
147+
%upper = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 2
148+
%gep.1 = getelementptr i32, ptr %dst.0, i64 1
149+
%c = icmp ult i32* %gep.1, %upper
150+
ret i1 %c
151+
}
152+
153+
define i1 @test_inner_gep_multiple_indices_ult_false_inc_gep_not_inbounds(ptr %dst) {
154+
; CHECK-LABEL: @test_inner_gep_multiple_indices_ult_false_inc_gep_not_inbounds(
155+
; CHECK-NEXT: entry:
156+
; CHECK-NEXT: [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 0, i64 0
157+
; CHECK-NEXT: [[UPPER:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST]], i64 0, i64 2
158+
; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr i32, ptr [[DST_0]], i64 2
159+
; CHECK-NEXT: [[C:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
160+
; CHECK-NEXT: ret i1 [[C]]
161+
;
162+
entry:
163+
%dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 0
164+
%upper = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 2
165+
%gep.1 = getelementptr i32, i32* %dst.0, i64 2
166+
%c = icmp ult i32* %gep.1, %upper
167+
ret i1 %c
168+
}
169+
170+
define i1 @test_inner_gep_multiple_indices_ult_true_inc_gep_not_inbounds_overflow(ptr %dst) {
171+
; CHECK-LABEL: @test_inner_gep_multiple_indices_ult_true_inc_gep_not_inbounds_overflow(
172+
; CHECK-NEXT: entry:
173+
; CHECK-NEXT: [[DST_0:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST:%.*]], i64 0, i64 0
174+
; CHECK-NEXT: [[UPPER:%.*]] = getelementptr inbounds [2 x i32], ptr [[DST]], i64 0, i64 5
175+
; CHECK-NEXT: [[GEP_1:%.*]] = getelementptr i32, ptr [[DST_0]], i64 2
176+
; CHECK-NEXT: [[C:%.*]] = icmp ult ptr [[GEP_1]], [[UPPER]]
177+
; CHECK-NEXT: ret i1 [[C]]
178+
;
179+
entry:
180+
%dst.0 = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 0
181+
%upper = getelementptr inbounds [2 x i32], ptr %dst, i64 0, i64 5
182+
%gep.1 = getelementptr i32, i32* %dst.0, i64 2
183+
%c = icmp ult i32* %gep.1, %upper
184+
ret i1 %c
185+
}

0 commit comments

Comments
 (0)