1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=indvars -o - %s | FileCheck %s
3 target datalayout = "e-p:32:32:32-p1:64:64:64-p2:8:8:8-p3:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:32-n8:16:32:64"
5 ; Derived from ptriv in lftr-reuse.ll
6 define void @ptriv_as2(ptr addrspace(2) %base, i32 %n) nounwind {
7 ; CHECK-LABEL: @ptriv_as2(
9 ; CHECK-NEXT: [[IDX_TRUNC:%.*]] = trunc i32 [[N:%.*]] to i8
10 ; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i8, ptr addrspace(2) [[BASE:%.*]], i8 [[IDX_TRUNC]]
11 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ult ptr addrspace(2) [[BASE]], [[ADD_PTR]]
12 ; CHECK-NEXT: br i1 [[CMP1]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_END:%.*]]
13 ; CHECK: for.body.preheader:
14 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
16 ; CHECK-NEXT: [[P_02:%.*]] = phi ptr addrspace(2) [ [[INCDEC_PTR:%.*]], [[FOR_BODY]] ], [ [[BASE]], [[FOR_BODY_PREHEADER]] ]
17 ; CHECK-NEXT: [[SUB_PTR_LHS_CAST:%.*]] = ptrtoint ptr addrspace(2) [[P_02]] to i8
18 ; CHECK-NEXT: [[SUB_PTR_RHS_CAST:%.*]] = ptrtoint ptr addrspace(2) [[BASE]] to i8
19 ; CHECK-NEXT: [[SUB_PTR_SUB:%.*]] = sub i8 [[SUB_PTR_LHS_CAST]], [[SUB_PTR_RHS_CAST]]
20 ; CHECK-NEXT: store i8 [[SUB_PTR_SUB]], ptr addrspace(2) [[P_02]], align 1
21 ; CHECK-NEXT: [[INCDEC_PTR]] = getelementptr inbounds i8, ptr addrspace(2) [[P_02]], i32 1
22 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne ptr addrspace(2) [[INCDEC_PTR]], [[ADD_PTR]]
23 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]]
24 ; CHECK: for.end.loopexit:
25 ; CHECK-NEXT: br label [[FOR_END]]
27 ; CHECK-NEXT: ret void
30 %idx.trunc = trunc i32 %n to i8
31 %add.ptr = getelementptr inbounds i8, ptr addrspace(2) %base, i8 %idx.trunc
32 %cmp1 = icmp ult ptr addrspace(2) %base, %add.ptr
33 br i1 %cmp1, label %for.body, label %for.end
35 ; Make sure the added GEP has the right index type
38 %p.02 = phi ptr addrspace(2) [ %base, %entry ], [ %incdec.ptr, %for.body ]
39 ; cruft to make the IV useful
40 %sub.ptr.lhs.cast = ptrtoint ptr addrspace(2) %p.02 to i8
41 %sub.ptr.rhs.cast = ptrtoint ptr addrspace(2) %base to i8
42 %sub.ptr.sub = sub i8 %sub.ptr.lhs.cast, %sub.ptr.rhs.cast
43 store i8 %sub.ptr.sub, ptr addrspace(2) %p.02
44 %incdec.ptr = getelementptr inbounds i8, ptr addrspace(2) %p.02, i32 1
45 %cmp = icmp ult ptr addrspace(2) %incdec.ptr, %add.ptr
46 br i1 %cmp, label %for.body, label %for.end
52 define void @ptriv_as3(ptr addrspace(3) %base, i32 %n) nounwind {
53 ; CHECK-LABEL: @ptriv_as3(
55 ; CHECK-NEXT: [[IDX_TRUNC:%.*]] = trunc i32 [[N:%.*]] to i16
56 ; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i8, ptr addrspace(3) [[BASE:%.*]], i16 [[IDX_TRUNC]]
57 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ult ptr addrspace(3) [[BASE]], [[ADD_PTR]]
58 ; CHECK-NEXT: br i1 [[CMP1]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_END:%.*]]
59 ; CHECK: for.body.preheader:
60 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
62 ; CHECK-NEXT: [[P_02:%.*]] = phi ptr addrspace(3) [ [[INCDEC_PTR:%.*]], [[FOR_BODY]] ], [ [[BASE]], [[FOR_BODY_PREHEADER]] ]
63 ; CHECK-NEXT: [[SUB_PTR_LHS_CAST:%.*]] = ptrtoint ptr addrspace(3) [[P_02]] to i16
64 ; CHECK-NEXT: [[SUB_PTR_RHS_CAST:%.*]] = ptrtoint ptr addrspace(3) [[BASE]] to i16
65 ; CHECK-NEXT: [[SUB_PTR_SUB:%.*]] = sub i16 [[SUB_PTR_LHS_CAST]], [[SUB_PTR_RHS_CAST]]
66 ; CHECK-NEXT: [[CONV:%.*]] = trunc i16 [[SUB_PTR_SUB]] to i8
67 ; CHECK-NEXT: store i8 [[CONV]], ptr addrspace(3) [[P_02]], align 1
68 ; CHECK-NEXT: [[INCDEC_PTR]] = getelementptr inbounds i8, ptr addrspace(3) [[P_02]], i32 1
69 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp ne ptr addrspace(3) [[INCDEC_PTR]], [[ADD_PTR]]
70 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_BODY]], label [[FOR_END_LOOPEXIT:%.*]]
71 ; CHECK: for.end.loopexit:
72 ; CHECK-NEXT: br label [[FOR_END]]
74 ; CHECK-NEXT: ret void
77 %idx.trunc = trunc i32 %n to i16
78 %add.ptr = getelementptr inbounds i8, ptr addrspace(3) %base, i16 %idx.trunc
79 %cmp1 = icmp ult ptr addrspace(3) %base, %add.ptr
80 br i1 %cmp1, label %for.body, label %for.end
82 ; Make sure the added GEP has the right index type
85 %p.02 = phi ptr addrspace(3) [ %base, %entry ], [ %incdec.ptr, %for.body ]
86 ; cruft to make the IV useful
87 %sub.ptr.lhs.cast = ptrtoint ptr addrspace(3) %p.02 to i16
88 %sub.ptr.rhs.cast = ptrtoint ptr addrspace(3) %base to i16
89 %sub.ptr.sub = sub i16 %sub.ptr.lhs.cast, %sub.ptr.rhs.cast
90 %conv = trunc i16 %sub.ptr.sub to i8
91 store i8 %conv, ptr addrspace(3) %p.02
92 %incdec.ptr = getelementptr inbounds i8, ptr addrspace(3) %p.02, i32 1
93 %cmp = icmp ult ptr addrspace(3) %incdec.ptr, %add.ptr
94 br i1 %cmp, label %for.body, label %for.end