xref: /llvm-project/llvm/test/Transforms/InstCombine/builtin-object-size-ptr.ll (revision b0ac26a6326ff145f7c09ec55a5cb6f695b6a237)
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
31declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1
32declare i64 @llvm.objectsize.i64.p0i8(i8*, i1) #2
33declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1
34