1; RUN: opt -S -instcombine -o - %s | FileCheck %s 2target datalayout = "e-p:32:32:32-p1:64:64:64-p2:8:8:8-p3:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:32" 3 4declare i32 @llvm.objectsize.i32.p0i8(i8*, i1) nounwind readonly 5declare i32 @llvm.objectsize.i32.p1i8(i8 addrspace(1)*, i1) nounwind readonly 6declare i32 @llvm.objectsize.i32.p2i8(i8 addrspace(2)*, i1) nounwind readonly 7declare i32 @llvm.objectsize.i32.p3i8(i8 addrspace(3)*, i1) nounwind readonly 8declare i16 @llvm.objectsize.i16.p3i8(i8 addrspace(3)*, i1) nounwind readonly 9 10@array_as2 = private addrspace(2) global [60 x i8] zeroinitializer, align 4 11 12@array_as1_pointers = private global [10 x i32 addrspace(1)*] zeroinitializer, align 4 13@array_as2_pointers = private global [24 x i32 addrspace(2)*] zeroinitializer, align 4 14@array_as3_pointers = private global [42 x i32 addrspace(3)*] zeroinitializer, align 4 15 16@array_as2_as1_pointer_pointers = private global [16 x i32 addrspace(2)* addrspace(1)*] zeroinitializer, align 4 17 18 19@a_as3 = private addrspace(3) global [60 x i8] zeroinitializer, align 1 20 21define i32 @foo_as3() nounwind { 22; CHECK-LABEL: @foo_as3( 23; CHECK-NEXT: ret i32 60 24 %1 = call i32 @llvm.objectsize.i32.p3i8(i8 addrspace(3)* getelementptr inbounds ([60 x i8], [60 x i8] addrspace(3)* @a_as3, i32 0, i32 0), i1 false) 25 ret i32 %1 26} 27 28define i16 @foo_as3_i16() nounwind { 29; CHECK-LABEL: @foo_as3_i16( 30; CHECK-NEXT: ret i16 60 31 %1 = call i16 @llvm.objectsize.i16.p3i8(i8 addrspace(3)* getelementptr inbounds ([60 x i8], [60 x i8] addrspace(3)* @a_as3, i32 0, i32 0), i1 false) 32 ret i16 %1 33} 34 35@a_alias = weak alias [60 x i8], [60 x i8] addrspace(3)* @a_as3 36define i32 @foo_alias() nounwind { 37 %1 = call i32 @llvm.objectsize.i32.p3i8(i8 addrspace(3)* getelementptr inbounds ([60 x i8], [60 x i8] addrspace(3)* @a_alias, i32 0, i32 0), i1 false) 38 ret i32 %1 39} 40 41define i32 @array_as2_size() { 42; CHECK-LABEL: @array_as2_size( 43; CHECK-NEXT: ret i32 60 44 %bc = bitcast [60 x i8] addrspace(2)* @array_as2 to i8 addrspace(2)* 45 %1 = call i32 @llvm.objectsize.i32.p2i8(i8 addrspace(2)* %bc, i1 false) 46 ret i32 %1 47} 48 49define i32 @pointer_array_as1() { 50; CHECK-LABEL: @pointer_array_as1( 51; CHECK-NEXT: ret i32 80 52 %bc = addrspacecast [10 x i32 addrspace(1)*]* @array_as1_pointers to i8 addrspace(1)* 53 %1 = call i32 @llvm.objectsize.i32.p1i8(i8 addrspace(1)* %bc, i1 false) 54 ret i32 %1 55} 56 57define i32 @pointer_array_as2() { 58; CHECK-LABEL: @pointer_array_as2( 59; CHECK-NEXT: ret i32 24 60 %bc = bitcast [24 x i32 addrspace(2)*]* @array_as2_pointers to i8* 61 %1 = call i32 @llvm.objectsize.i32.p0i8(i8* %bc, i1 false) 62 ret i32 %1 63} 64 65define i32 @pointer_array_as3() { 66; CHECK-LABEL: @pointer_array_as3( 67; CHECK-NEXT: ret i32 84 68 %bc = bitcast [42 x i32 addrspace(3)*]* @array_as3_pointers to i8* 69 %1 = call i32 @llvm.objectsize.i32.p0i8(i8* %bc, i1 false) 70 ret i32 %1 71} 72 73define i32 @pointer_pointer_array_as2_as1() { 74; CHECK-LABEL: @pointer_pointer_array_as2_as1( 75; CHECK-NEXT: ret i32 128 76 %bc = bitcast [16 x i32 addrspace(2)* addrspace(1)*]* @array_as2_as1_pointer_pointers to i8* 77 %1 = call i32 @llvm.objectsize.i32.p0i8(i8* %bc, i1 false) 78 ret i32 %1 79} 80 81