1; RUN: opt -S -indvars -o - %s | FileCheck %s 2target 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" 3 4; Derived from ptriv in lftr-reuse.ll 5define void @ptriv_as2(i8 addrspace(2)* %base, i32 %n) nounwind { 6; CHECK-LABEL: @ptriv_as2( 7entry: 8 %idx.trunc = trunc i32 %n to i8 9 %add.ptr = getelementptr inbounds i8, i8 addrspace(2)* %base, i8 %idx.trunc 10 %cmp1 = icmp ult i8 addrspace(2)* %base, %add.ptr 11 br i1 %cmp1, label %for.body, label %for.end 12 13; Make sure the added GEP has the right index type 14; CHECK: %lftr.limit = getelementptr i8, i8 addrspace(2)* %base, i8 %idx.trunc 15 16; CHECK: for.body: 17; CHECK: phi i8 addrspace(2)* 18; CHECK-NOT: phi 19; CHECK-NOT: add{{^rspace}} 20; CHECK: icmp ne i8 addrspace(2)* 21; CHECK: br i1 22for.body: 23 %p.02 = phi i8 addrspace(2)* [ %base, %entry ], [ %incdec.ptr, %for.body ] 24 ; cruft to make the IV useful 25 %sub.ptr.lhs.cast = ptrtoint i8 addrspace(2)* %p.02 to i8 26 %sub.ptr.rhs.cast = ptrtoint i8 addrspace(2)* %base to i8 27 %sub.ptr.sub = sub i8 %sub.ptr.lhs.cast, %sub.ptr.rhs.cast 28 store i8 %sub.ptr.sub, i8 addrspace(2)* %p.02 29 %incdec.ptr = getelementptr inbounds i8, i8 addrspace(2)* %p.02, i32 1 30 %cmp = icmp ult i8 addrspace(2)* %incdec.ptr, %add.ptr 31 br i1 %cmp, label %for.body, label %for.end 32 33for.end: 34 ret void 35} 36 37define void @ptriv_as3(i8 addrspace(3)* %base, i32 %n) nounwind { 38; CHECK-LABEL: @ptriv_as3( 39entry: 40 %idx.trunc = trunc i32 %n to i16 41 %add.ptr = getelementptr inbounds i8, i8 addrspace(3)* %base, i16 %idx.trunc 42 %cmp1 = icmp ult i8 addrspace(3)* %base, %add.ptr 43 br i1 %cmp1, label %for.body, label %for.end 44 45; Make sure the added GEP has the right index type 46; CHECK: %lftr.limit = getelementptr i8, i8 addrspace(3)* %base, i16 %idx.trunc 47 48; CHECK: for.body: 49; CHECK: phi i8 addrspace(3)* 50; CHECK-NOT: phi 51; CHECK-NOT: add{{^rspace}} 52; CHECK: icmp ne i8 addrspace(3)* 53; CHECK: br i1 54for.body: 55 %p.02 = phi i8 addrspace(3)* [ %base, %entry ], [ %incdec.ptr, %for.body ] 56 ; cruft to make the IV useful 57 %sub.ptr.lhs.cast = ptrtoint i8 addrspace(3)* %p.02 to i16 58 %sub.ptr.rhs.cast = ptrtoint i8 addrspace(3)* %base to i16 59 %sub.ptr.sub = sub i16 %sub.ptr.lhs.cast, %sub.ptr.rhs.cast 60 %conv = trunc i16 %sub.ptr.sub to i8 61 store i8 %conv, i8 addrspace(3)* %p.02 62 %incdec.ptr = getelementptr inbounds i8, i8 addrspace(3)* %p.02, i32 1 63 %cmp = icmp ult i8 addrspace(3)* %incdec.ptr, %add.ptr 64 br i1 %cmp, label %for.body, label %for.end 65 66for.end: 67 ret void 68} 69 70