Skip to content

Commit 256c672

Browse files
committed
[ConstraintElim] Add tests with GEP constant expressions.
1 parent f0111f2 commit 256c672

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s
3+
4+
declare void @llvm.assume(i1 noundef) #0
5+
6+
@arr1 = common global [3 x i16] zeroinitializer, align 2
7+
8+
define i1 @gep_constexpr_index_lt_upper(i32 noundef %i) {
9+
; CHECK-LABEL: @gep_constexpr_index_lt_upper(
10+
; CHECK-NEXT: entry:
11+
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[I:%.*]], 3
12+
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
13+
; CHECK-NEXT: [[IDXPROM:%.*]] = zext i32 [[I]] to i64
14+
; CHECK-NEXT: [[UPPER:%.*]] = getelementptr inbounds i16, ptr @arr1, i64 [[IDXPROM]]
15+
; CHECK-NEXT: [[C_1:%.*]] = icmp ult ptr [[UPPER]], getelementptr inbounds ([3 x i16], ptr @arr1, i64 1, i64 0)
16+
; CHECK-NEXT: ret i1 [[C_1]]
17+
;
18+
entry:
19+
%cmp = icmp ult i32 %i, 3
20+
call void @llvm.assume(i1 %cmp)
21+
%idxprom = zext i32 %i to i64
22+
%upper = getelementptr inbounds i16, ptr @arr1, i64 %idxprom
23+
%c.1 = icmp ult ptr %upper, getelementptr inbounds ([3 x i16], ptr @arr1, i64 1, i64 0)
24+
ret i1 %c.1
25+
}
26+
27+
define i1 @gep_constexpr_index_may_be_gt_upper(i32 noundef %i) {
28+
; CHECK-LABEL: @gep_constexpr_index_may_be_gt_upper(
29+
; CHECK-NEXT: entry:
30+
; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[I:%.*]], 3
31+
; CHECK-NEXT: call void @llvm.assume(i1 [[CMP]])
32+
; CHECK-NEXT: [[IDXPROM:%.*]] = zext i32 [[I]] to i64
33+
; CHECK-NEXT: [[UPPER:%.*]] = getelementptr inbounds i16, ptr @arr1, i64 [[IDXPROM]]
34+
; CHECK-NEXT: [[C_1:%.*]] = icmp ult ptr [[UPPER]], getelementptr inbounds ([3 x i16], ptr @arr1, i64 0, i64 2)
35+
; CHECK-NEXT: ret i1 [[C_1]]
36+
;
37+
entry:
38+
%cmp = icmp ult i32 %i, 3
39+
call void @llvm.assume(i1 %cmp)
40+
%idxprom = zext i32 %i to i64
41+
%upper = getelementptr inbounds i16, ptr @arr1, i64 %idxprom
42+
%c.1 = icmp ult ptr %upper, getelementptr inbounds ([3 x i16], ptr @arr1, i64 0, i64 2)
43+
ret i1 %c.1
44+
}

0 commit comments

Comments
 (0)