1 ; RUN: opt < %s -passes=bounds-checking -S | FileCheck %s
2 target datalayout = "e-p:64:64:64-p1:16:16:16-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-S128"
4 @global = private unnamed_addr constant [10 x i8] c"ola\00mundo\00", align 1
7 ; no checks are possible here
9 define void @f1(ptr nocapture %c) {
11 %0 = load i8, ptr %c, align 1
12 %tobool1 = icmp eq i8 %0, 0
13 br i1 %tobool1, label %while.end, label %while.body
16 %c.addr.02 = phi ptr [ %incdec.ptr, %while.body ], [ %c, %entry ]
17 %incdec.ptr = getelementptr inbounds i8, ptr %c.addr.02, i64 -1
18 store i8 100, ptr %c.addr.02, align 1
19 %1 = load i8, ptr %incdec.ptr, align 1
20 %tobool = icmp eq i8 %1, 0
21 br i1 %tobool, label %while.end, label %while.body
30 while.body.i.preheader:
31 %addr = getelementptr inbounds [10 x i8], ptr @global, i64 0, i64 9
32 br label %while.body.i
38 %c.addr.02.i = phi ptr [ %incdec.ptr.i, %while.body.i ], [ %addr, %while.body.i.preheader ]
39 %incdec.ptr.i = getelementptr inbounds i8, ptr %c.addr.02.i, i64 -1
40 ; CHECK: sub i64 10, %0
41 ; CHECK-NEXT: icmp ult i64 10, %0
42 ; CHECK-NEXT: icmp ult i64 {{.*}}, 1
44 ; CHECK-NEXT: br {{.*}}, label %trap
45 store i8 100, ptr %c.addr.02.i, align 1
46 %0 = load i8, ptr %incdec.ptr.i, align 1
47 %tobool.i = icmp eq i8 %0, 0
48 br i1 %tobool.i, label %fn.exit, label %while.body.i
55 @global_as1 = private unnamed_addr addrspace(1) constant [10 x i8] c"ola\00mundo\00", align 1
57 define void @f1_as1(ptr addrspace(1) nocapture %c) {
59 ; no checks are possible here
62 %0 = load i8, ptr addrspace(1) %c, align 1
63 %tobool1 = icmp eq i8 %0, 0
64 br i1 %tobool1, label %while.end, label %while.body
67 %c.addr.02 = phi ptr addrspace(1) [ %incdec.ptr, %while.body ], [ %c, %entry ]
68 %incdec.ptr = getelementptr inbounds i8, ptr addrspace(1) %c.addr.02, i64 -1
69 store i8 100, ptr addrspace(1) %c.addr.02, align 1
70 %1 = load i8, ptr addrspace(1) %incdec.ptr, align 1
71 %tobool = icmp eq i8 %1, 0
72 br i1 %tobool, label %while.end, label %while.body
79 define void @f2_as1() {
81 while.body.i.preheader:
82 %addr = getelementptr inbounds [10 x i8], ptr addrspace(1) @global_as1, i16 0, i16 9
83 br label %while.body.i
89 %c.addr.02.i = phi ptr addrspace(1) [ %incdec.ptr.i, %while.body.i ], [ %addr, %while.body.i.preheader ]
90 %incdec.ptr.i = getelementptr inbounds i8, ptr addrspace(1) %c.addr.02.i, i16 -1
91 ; CHECK: sub i16 10, %0
92 ; CHECK-NEXT: icmp ult i16 10, %0
93 ; CHECK-NEXT: icmp ult i16 {{.*}}, 1
95 ; CHECK-NEXT: br {{.*}}, label %trap
96 store i8 100, ptr addrspace(1) %c.addr.02.i, align 1
97 %0 = load i8, ptr addrspace(1) %incdec.ptr.i, align 1
98 %tobool.i = icmp eq i8 %0, 0
99 br i1 %tobool.i, label %fn.exit, label %while.body.i