1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=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 call void @llvm.lifetime.start.p0(i64 28, ptr %var) #3
22 %arrayidx = getelementptr inbounds [10 x i8], ptr %var, i64 0, i64 1
23 %t1 = call i64 @llvm.objectsize.i64.p0(ptr %arrayidx, i1 false)
24 %conv = trunc i64 %t1 to i32
25 call void @llvm.lifetime.end.p0(i64 28, ptr %var) #3
29 ; This used to crash while erasing instructions:
30 ; https://bugs.llvm.org/show_bug.cgi?id=43723
32 define void @PR43723() {
33 ; CHECK-LABEL: @PR43723(
34 ; CHECK-NEXT: ret void
36 %tab = alloca [10 x i8], align 16
37 call void @llvm.memset.p0.i64(ptr align 16 %tab, i8 9, i64 10, i1 false)
38 %t1 = call ptr @llvm.invariant.start.p0(i64 10, ptr align 16 %tab)
39 call void @llvm.invariant.end.p0(ptr %t1, i64 10, ptr align 16 %tab)
42 uselistorder ptr %tab, { 1, 0, 2 }
45 define void @unknown_use_of_invariant_start(ptr %p) {
46 ; CHECK-LABEL: @unknown_use_of_invariant_start(
47 ; CHECK-NEXT: ret void
49 %tab = alloca [10 x i8], align 16
50 call void @llvm.memset.p0.i64(ptr align 16 %tab, i8 9, i64 10, i1 false)
51 %t1 = call ptr @llvm.invariant.start.p0(i64 10, ptr align 16 %tab)
52 call void @llvm.invariant.end.p0(ptr %t1, i64 10, ptr align 16 %tab)
57 define ptr @minimal_invariant_start_use(i8 %x) {
58 ; CHECK-LABEL: @minimal_invariant_start_use(
59 ; CHECK-NEXT: ret ptr poison
62 %i = call ptr @llvm.invariant.start.p0(i64 1, ptr %a)
66 declare void @llvm.lifetime.start.p0(i64, ptr nocapture) #1
67 declare i64 @llvm.objectsize.i64.p0(ptr, i1) #2
68 declare void @llvm.lifetime.end.p0(i64, ptr nocapture) #1
69 declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #0
70 declare ptr @llvm.invariant.start.p0(i64 immarg, ptr nocapture) #0
71 declare void @llvm.invariant.end.p0(ptr, i64 immarg, ptr nocapture) #0