1; RUN: opt -S -basicaa -objc-arc < %s | FileCheck %s 2 3target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" 4target triple = "x86_64-apple-darwin11.0.0" 5 6%0 = type { i64, i64, i8*, i8*, i8*, i8* } 7%1 = type <{ i8*, i32, i32, i8*, %struct.__block_descriptor*, i8* }> 8%struct.__block_descriptor = type { i64, i64 } 9 10@_NSConcreteStackBlock = external global i8* 11@.str = private unnamed_addr constant [6 x i8] c"v8@?0\00" 12@"\01L_OBJC_CLASS_NAME_" = internal global [3 x i8] c"\01@\00", section "__TEXT,__objc_classname,cstring_literals", align 1 13@__block_descriptor_tmp = internal constant %0 { i64 0, i64 40, i8* bitcast (void (i8*, i8*)* @__copy_helper_block_ to i8*), i8* bitcast (void (i8*)* @__destroy_helper_block_ to i8*), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @"\01L_OBJC_CLASS_NAME_", i32 0, i32 0) } 14@"\01L_OBJC_IMAGE_INFO" = internal constant [2 x i32] [i32 0, i32 16], section "__DATA, __objc_imageinfo, regular, no_dead_strip" 15@llvm.used = appending global [2 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @"\01L_OBJC_CLASS_NAME_", i32 0, i32 0), i8* bitcast ([2 x i32]* @"\01L_OBJC_IMAGE_INFO" to i8*)], section "llvm.metadata" 16 17; Eliminate unnecessary weak pointer copies. 18 19; CHECK: define void @foo() { 20; CHECK-NEXT: entry: 21; CHECK-NEXT: %call = call i8* @bar() 22; CHECK-NEXT: call void @use(i8* %call) [[NUW:#[0-9]+]] 23; CHECK-NEXT: ret void 24; CHECK-NEXT: } 25define void @foo() { 26entry: 27 %w = alloca i8*, align 8 28 %x = alloca i8*, align 8 29 %call = call i8* @bar() 30 %0 = call i8* @objc_initWeak(i8** %w, i8* %call) nounwind 31 %1 = call i8* @objc_loadWeak(i8** %w) nounwind 32 %2 = call i8* @objc_initWeak(i8** %x, i8* %1) nounwind 33 %3 = call i8* @objc_loadWeak(i8** %x) nounwind 34 call void @use(i8* %3) nounwind 35 call void @objc_destroyWeak(i8** %x) nounwind 36 call void @objc_destroyWeak(i8** %w) nounwind 37 ret void 38} 39 40; Eliminate unnecessary weak pointer copies in a block initialization. 41 42; CHECK: define void @qux(i8* %me) #0 { 43; CHECK-NEXT: entry: 44; CHECK-NEXT: %block = alloca %1, align 8 45; CHECK-NOT: alloca 46; CHECK: } 47define void @qux(i8* %me) nounwind { 48entry: 49 %w = alloca i8*, align 8 50 %block = alloca %1, align 8 51 %0 = call i8* @objc_retain(i8* %me) nounwind 52 %1 = call i8* @objc_initWeak(i8** %w, i8* %0) nounwind 53 %block.isa = getelementptr inbounds %1, %1* %block, i64 0, i32 0 54 store i8* bitcast (i8** @_NSConcreteStackBlock to i8*), i8** %block.isa, align 8 55 %block.flags = getelementptr inbounds %1, %1* %block, i64 0, i32 1 56 store i32 1107296256, i32* %block.flags, align 8 57 %block.reserved = getelementptr inbounds %1, %1* %block, i64 0, i32 2 58 store i32 0, i32* %block.reserved, align 4 59 %block.invoke = getelementptr inbounds %1, %1* %block, i64 0, i32 3 60 store i8* bitcast (void (i8*)* @__qux_block_invoke_0 to i8*), i8** %block.invoke, align 8 61 %block.descriptor = getelementptr inbounds %1, %1* %block, i64 0, i32 4 62 store %struct.__block_descriptor* bitcast (%0* @__block_descriptor_tmp to %struct.__block_descriptor*), %struct.__block_descriptor** %block.descriptor, align 8 63 %block.captured = getelementptr inbounds %1, %1* %block, i64 0, i32 5 64 %2 = call i8* @objc_loadWeak(i8** %w) nounwind 65 %3 = call i8* @objc_initWeak(i8** %block.captured, i8* %2) nounwind 66 %4 = bitcast %1* %block to void ()* 67 call void @use_block(void ()* %4) nounwind 68 call void @objc_destroyWeak(i8** %block.captured) nounwind 69 call void @objc_destroyWeak(i8** %w) nounwind 70 call void @objc_release(i8* %0) nounwind, !clang.imprecise_release !0 71 ret void 72} 73 74declare i8* @objc_retain(i8*) 75declare void @use_block(void ()*) nounwind 76declare void @__qux_block_invoke_0(i8* %.block_descriptor) nounwind 77declare void @__copy_helper_block_(i8*, i8*) nounwind 78declare void @objc_copyWeak(i8**, i8**) 79declare void @__destroy_helper_block_(i8*) nounwind 80declare void @objc_release(i8*) 81declare i8* @bar() 82declare i8* @objc_initWeak(i8**, i8*) 83declare i8* @objc_loadWeak(i8**) 84declare void @use(i8*) nounwind 85declare void @objc_destroyWeak(i8**) 86 87; CHECK: attributes [[NUW]] = { nounwind } 88 89!0 = !{} 90