1; RUN: opt < %s -indvars -S "-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 "-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 15define i8 @testnullptrptr(i8* %buf, i8* %end) nounwind { 16 br label %loopguard 17 18loopguard: 19 %guard = icmp ult i8* null, %end 20 br i1 %guard, label %preheader, label %exit 21 22preheader: 23 br label %loop 24 25loop: 26 %p.01.us.us = phi i8* [ null, %preheader ], [ %gep, %loop ] 27 %s = phi i8 [0, %preheader], [%snext, %loop] 28 %gep = getelementptr inbounds i8, i8* %p.01.us.us, i64 1 29 %snext = load i8, i8* %gep 30 %cmp = icmp ult i8* %gep, %end 31 br i1 %cmp, label %loop, label %exit 32 33exit: 34 %ret = phi i8 [0, %loopguard], [%snext, %loop] 35 ret i8 %ret 36} 37 38; CHECK-LABEL: @testptrptr( 39; CHECK: loop: 40; CHECK: icmp ne 41define i8 @testptrptr(i8* %buf, i8* %end) nounwind { 42 br label %loopguard 43 44loopguard: 45 %guard = icmp ult i8* %buf, %end 46 br i1 %guard, label %preheader, label %exit 47 48preheader: 49 br label %loop 50 51loop: 52 %p.01.us.us = phi i8* [ %buf, %preheader ], [ %gep, %loop ] 53 %s = phi i8 [0, %preheader], [%snext, %loop] 54 %gep = getelementptr inbounds i8, i8* %p.01.us.us, i64 1 55 %snext = load i8, i8* %gep 56 %cmp = icmp ult i8* %gep, %end 57 br i1 %cmp, label %loop, label %exit 58 59exit: 60 %ret = phi i8 [0, %loopguard], [%snext, %loop] 61 ret i8 %ret 62} 63 64; CHECK-LABEL: @testnullptrint( 65; CHECK: loop: 66; CHECK: icmp ne 67define i8 @testnullptrint(i8* %buf, i8* %end) nounwind { 68 br label %loopguard 69 70loopguard: 71 %bi = ptrtoint i8* %buf to i32 72 %ei = ptrtoint i8* %end to i32 73 %cnt = sub i32 %ei, %bi 74 %guard = icmp ult i32 0, %cnt 75 br i1 %guard, label %preheader, label %exit 76 77preheader: 78 br label %loop 79 80loop: 81 %p.01.us.us = phi i8* [ null, %preheader ], [ %gep, %loop ] 82 %iv = phi i32 [ 0, %preheader ], [ %ivnext, %loop ] 83 %s = phi i8 [0, %preheader], [%snext, %loop] 84 %gep = getelementptr inbounds i8, i8* %p.01.us.us, i64 1 85 %snext = load i8, i8* %gep 86 %ivnext = add i32 %iv, 1 87 %cmp = icmp ult i32 %ivnext, %cnt 88 br i1 %cmp, label %loop, label %exit 89 90exit: 91 %ret = phi i8 [0, %loopguard], [%snext, %loop] 92 ret i8 %ret 93} 94 95; CHECK-LABEL: @testptrint( 96; CHECK: loop: 97; CHECK: icmp ne 98define i8 @testptrint(i8* %buf, i8* %end) nounwind { 99 br label %loopguard 100 101loopguard: 102 %bi = ptrtoint i8* %buf to i32 103 %ei = ptrtoint i8* %end to i32 104 %cnt = sub i32 %ei, %bi 105 %guard = icmp ult i32 %bi, %cnt 106 br i1 %guard, label %preheader, label %exit 107 108preheader: 109 br label %loop 110 111loop: 112 %p.01.us.us = phi i8* [ %buf, %preheader ], [ %gep, %loop ] 113 %iv = phi i32 [ %bi, %preheader ], [ %ivnext, %loop ] 114 %s = phi i8 [0, %preheader], [%snext, %loop] 115 %gep = getelementptr inbounds i8, i8* %p.01.us.us, i64 1 116 %snext = load i8, i8* %gep 117 %ivnext = add i32 %iv, 1 118 %cmp = icmp ult i32 %ivnext, %cnt 119 br i1 %cmp, label %loop, label %exit 120 121exit: 122 %ret = phi i8 [0, %loopguard], [%snext, %loop] 123 ret i8 %ret 124} 125 126; IV and BECount have two different pointer types here. 127define void @testnullptr([512 x i8]* %base) nounwind { 128entry: 129 %add.ptr1603 = getelementptr [512 x i8], [512 x i8]* %base, i64 0, i64 512 130 br label %preheader 131 132preheader: 133 %cmp1604192 = icmp ult i8* undef, %add.ptr1603 134 br i1 %cmp1604192, label %for.body, label %for.end1609 135 136for.body: 137 %r.17193 = phi i8* [ %incdec.ptr1608, %for.body ], [ null, %preheader ] 138 %incdec.ptr1608 = getelementptr i8, i8* %r.17193, i64 1 139 %cmp1604 = icmp ult i8* %incdec.ptr1608, %add.ptr1603 140 br i1 %cmp1604, label %for.body, label %for.end1609 141 142for.end1609: 143 unreachable 144} 145