1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -instcombine -S < %s | FileCheck %s 3 4; int foo() { 5; struct V { char buf1[10]; 6; int b; 7; char buf2[10]; 8; } var; 9; 10; char *p = &var.buf1[1]; 11; return __builtin_object_size (p, 0); 12; } 13 14%struct.V = type { [10 x i8], i32, [10 x i8] } 15 16define i32 @foo() #0 { 17; CHECK-LABEL: @foo( 18; CHECK-NEXT: ret i32 27 19; 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 28 ret i32 %conv 29} 30 31; This used to crash while erasing instructions: 32; https://bugs.llvm.org/show_bug.cgi?id=43723 33 34define void @PR43723() { 35; CHECK-LABEL: @PR43723( 36; CHECK-NEXT: ret void 37; 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) 43 ret void 44 45 uselistorder i8* %t0, { 1, 0, 2 } 46} 47 48define void @unknown_use_of_invariant_start({}** %p) { 49; CHECK-LABEL: @unknown_use_of_invariant_start( 50; CHECK-NEXT: ret void 51; 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 58 ret void 59} 60 61define {}* @minimal_invariant_start_use(i8 %x) { 62; CHECK-LABEL: @minimal_invariant_start_use( 63; CHECK-NEXT: ret {}* undef 64; 65 %a = alloca i8 66 %i = call {}* @llvm.invariant.start.p0i8(i64 1, i8* %a) 67 ret {}* %i 68} 69 70declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1 71declare i64 @llvm.objectsize.i64.p0i8(i8*, i1) #2 72declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1 73declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg) #0 74declare {}* @llvm.invariant.start.p0i8(i64 immarg, i8* nocapture) #0 75declare void @llvm.invariant.end.p0i8({}*, i64 immarg, i8* nocapture) #0 76