1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -instcombine -S < %s | FileCheck %s
5 ; struct V { char buf1[10];
10 ; char *p = &var.buf1[1];
11 ; return __builtin_object_size (p, 0);
14 %struct.V = type { [10 x i8], i32, [10 x i8] }
16 define i32 @foo() #0 {
18 ; CHECK-NEXT: ret i32 27
20 %var = alloca %struct.V, align 4
21 %t0 = bitcast %struct.V* %var to i8*
22 call void @llvm.lifetime.start.p0i8(i64 28, i8* %t0) #3
23 %buf1 = getelementptr inbounds %struct.V, %struct.V* %var, i32 0, i32 0
24 %arrayidx = getelementptr inbounds [10 x i8], [10 x i8]* %buf1, i64 0, i64 1
25 %t1 = call i64 @llvm.objectsize.i64.p0i8(i8* %arrayidx, i1 false)
26 %conv = trunc i64 %t1 to i32
27 call void @llvm.lifetime.end.p0i8(i64 28, i8* %t0) #3
31 ; This used to crash while erasing instructions:
32 ; https://bugs.llvm.org/show_bug.cgi?id=43723
34 define void @PR43723() {
35 ; CHECK-LABEL: @PR43723(
36 ; CHECK-NEXT: ret void
38 %tab = alloca [10 x i8], align 16
39 %t0 = bitcast [10 x i8]* %tab to i8*
40 call void @llvm.memset.p0i8.i64(i8* align 16 %t0, i8 9, i64 10, i1 false)
41 %t1 = call {}* @llvm.invariant.start.p0i8(i64 10, i8* align 16 %t0)
42 call void @llvm.invariant.end.p0i8({}* %t1, i64 10, i8* align 16 %t0)
45 uselistorder i8* %t0, { 1, 0, 2 }
48 define void @unknown_use_of_invariant_start({}** %p) {
49 ; CHECK-LABEL: @unknown_use_of_invariant_start(
50 ; CHECK-NEXT: ret void
52 %tab = alloca [10 x i8], align 16
53 %t0 = bitcast [10 x i8]* %tab to i8*
54 call void @llvm.memset.p0i8.i64(i8* align 16 %t0, i8 9, i64 10, i1 false)
55 %t1 = call {}* @llvm.invariant.start.p0i8(i64 10, i8* align 16 %t0)
56 call void @llvm.invariant.end.p0i8({}* %t1, i64 10, i8* align 16 %t0)
57 store {}* %t1, {}** %p
61 define {}* @minimal_invariant_start_use(i8 %x) {
62 ; CHECK-LABEL: @minimal_invariant_start_use(
63 ; CHECK-NEXT: ret {}* poison
66 %i = call {}* @llvm.invariant.start.p0i8(i64 1, i8* %a)
70 declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1
71 declare i64 @llvm.objectsize.i64.p0i8(i8*, i1) #2
72 declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1
73 declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg) #0
74 declare {}* @llvm.invariant.start.p0i8(i64 immarg, i8* nocapture) #0
75 declare void @llvm.invariant.end.p0i8({}*, i64 immarg, i8* nocapture) #0