1; RUN: opt -instcombine -S < %s | FileCheck %s 2 3; #include <stdlib.h> 4; #include <stdio.h> 5; 6; int foo1(int N) { 7; char Big[20]; 8; char Small[10]; 9; char *Ptr = N ? Big + 10 : Small; 10; return __builtin_object_size(Ptr, 0); 11; } 12; 13; void foo() { 14; size_t ret; 15; ret = foo1(0); 16; printf("\n %d", ret); 17; } 18 19target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 20target triple = "x86_64-unknown-linux-gnu" 21 22@.str = private unnamed_addr constant [5 x i8] c"\0A %d\00", align 1 23 24define i32 @foo1(i32 %N) { 25entry: 26 %Big = alloca [20 x i8], align 16 27 %Small = alloca [10 x i8], align 1 28 %0 = getelementptr inbounds [20 x i8], [20 x i8]* %Big, i64 0, i64 0 29 call void @llvm.lifetime.start(i64 20, i8* %0) 30 %1 = getelementptr inbounds [10 x i8], [10 x i8]* %Small, i64 0, i64 0 31 call void @llvm.lifetime.start(i64 10, i8* %1) 32 %tobool = icmp ne i32 %N, 0 33 %add.ptr = getelementptr inbounds [20 x i8], [20 x i8]* %Big, i64 0, i64 10 34 %cond = select i1 %tobool, i8* %add.ptr, i8* %1 35 %2 = call i64 @llvm.objectsize.i64.p0i8(i8* %cond, i1 false) 36 %conv = trunc i64 %2 to i32 37 call void @llvm.lifetime.end(i64 10, i8* %1) 38 call void @llvm.lifetime.end(i64 20, i8* %0) 39 ret i32 %conv 40; CHECK: ret i32 10 41} 42 43declare void @llvm.lifetime.start(i64, i8* nocapture) 44 45declare i64 @llvm.objectsize.i64.p0i8(i8*, i1) 46 47declare void @llvm.lifetime.end(i64, i8* nocapture) 48 49define void @foo() { 50entry: 51 %call = tail call i32 @foo1(i32 0) 52 %conv = sext i32 %call to i64 53 %call1 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %conv) 54 ret void 55} 56 57declare i32 @printf(i8* nocapture readonly, ...) 58 59