1 ; RUN: opt < %s -indvars -S "-default-data-layout=e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" | FileCheck %s 2 ; RUN: opt < %s -indvars -S "-default-data-layout=e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32" | FileCheck %s 3 ; 4 ; PR11279: Assertion !IVLimit->getType()->isPointerTy() 5 ; 6 ; Test LinearFunctionTestReplace of a pointer-type loop counter. Note 7 ; that BECount may or may not be a pointer type. A pointer type 8 ; BECount doesn't really make sense, but that's what falls out of 9 ; SCEV. Since it's an i8*, it has unit stride so we never adjust the 10 ; SCEV expression in a way that would convert it to an integer type. 11 12 ; CHECK-LABEL: @testnullptrptr( 13 ; CHECK: loop: 14 ; CHECK: icmp ne 15 define i8 @testnullptrptr(i8* %buf, i8* %end) nounwind { 16 br label %loopguard 17 18 loopguard: 19 %guard = icmp ult i8* null, %end 20 br i1 %guard, label %preheader, label %exit 21 22 preheader: 23 br label %loop 24 25 loop: 26 %p.01.us.us = phi i8* [ null, %preheader ], [ %gep, %loop ] 27 %s = phi i8 [0, %preheader], [%snext, %loop] 28 %gep = getelementptr inbounds i8* %p.01.us.us, i64 1 29 %snext = load i8* %gep 30 %cmp = icmp ult i8* %gep, %end 31 br i1 %cmp, label %loop, label %exit 32 33 exit: 34 ret i8 %snext 35 } 36 37 ; CHECK-LABEL: @testptrptr( 38 ; CHECK: loop: 39 ; CHECK: icmp ne 40 define i8 @testptrptr(i8* %buf, i8* %end) nounwind { 41 br label %loopguard 42 43 loopguard: 44 %guard = icmp ult i8* %buf, %end 45 br i1 %guard, label %preheader, label %exit 46 47 preheader: 48 br label %loop 49 50 loop: 51 %p.01.us.us = phi i8* [ %buf, %preheader ], [ %gep, %loop ] 52 %s = phi i8 [0, %preheader], [%snext, %loop] 53 %gep = getelementptr inbounds i8* %p.01.us.us, i64 1 54 %snext = load i8* %gep 55 %cmp = icmp ult i8* %gep, %end 56 br i1 %cmp, label %loop, label %exit 57 58 exit: 59 ret i8 %snext 60 } 61 62 ; CHECK-LABEL: @testnullptrint( 63 ; CHECK: loop: 64 ; CHECK: icmp ne 65 define i8 @testnullptrint(i8* %buf, i8* %end) nounwind { 66 br label %loopguard 67 68 loopguard: 69 %bi = ptrtoint i8* %buf to i32 70 %ei = ptrtoint i8* %end to i32 71 %cnt = sub i32 %ei, %bi 72 %guard = icmp ult i32 0, %cnt 73 br i1 %guard, label %preheader, label %exit 74 75 preheader: 76 br label %loop 77 78 loop: 79 %p.01.us.us = phi i8* [ null, %preheader ], [ %gep, %loop ] 80 %iv = phi i32 [ 0, %preheader ], [ %ivnext, %loop ] 81 %s = phi i8 [0, %preheader], [%snext, %loop] 82 %gep = getelementptr inbounds i8* %p.01.us.us, i64 1 83 %snext = load i8* %gep 84 %ivnext = add i32 %iv, 1 85 %cmp = icmp ult i32 %ivnext, %cnt 86 br i1 %cmp, label %loop, label %exit 87 88 exit: 89 ret i8 %snext 90 } 91 92 ; CHECK-LABEL: @testptrint( 93 ; CHECK: loop: 94 ; CHECK: icmp ne 95 define i8 @testptrint(i8* %buf, i8* %end) nounwind { 96 br label %loopguard 97 98 loopguard: 99 %bi = ptrtoint i8* %buf to i32 100 %ei = ptrtoint i8* %end to i32 101 %cnt = sub i32 %ei, %bi 102 %guard = icmp ult i32 %bi, %cnt 103 br i1 %guard, label %preheader, label %exit 104 105 preheader: 106 br label %loop 107 108 loop: 109 %p.01.us.us = phi i8* [ %buf, %preheader ], [ %gep, %loop ] 110 %iv = phi i32 [ %bi, %preheader ], [ %ivnext, %loop ] 111 %s = phi i8 [0, %preheader], [%snext, %loop] 112 %gep = getelementptr inbounds i8* %p.01.us.us, i64 1 113 %snext = load i8* %gep 114 %ivnext = add i32 %iv, 1 115 %cmp = icmp ult i32 %ivnext, %cnt 116 br i1 %cmp, label %loop, label %exit 117 118 exit: 119 ret i8 %snext 120 } 121 122 ; IV and BECount have two different pointer types here. 123 define void @testnullptr([512 x i8]* %base) nounwind { 124 entry: 125 %add.ptr1603 = getelementptr [512 x i8]* %base, i64 0, i64 512 126 br label %preheader 127 128 preheader: 129 %cmp1604192 = icmp ult i8* undef, %add.ptr1603 130 br i1 %cmp1604192, label %for.body, label %for.end1609 131 132 for.body: 133 %r.17193 = phi i8* [ %incdec.ptr1608, %for.body ], [ null, %preheader ] 134 %incdec.ptr1608 = getelementptr i8* %r.17193, i64 1 135 %cmp1604 = icmp ult i8* %incdec.ptr1608, %add.ptr1603 136 br i1 %cmp1604, label %for.body, label %for.end1609 137 138 for.end1609: 139 unreachable 140 } 141