1 target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128" 2 3 ; RUN: opt < %s -instcombine -S | FileCheck %s 4 ; END. 5 6 declare void @use(...) 7 8 @int = global i32 zeroinitializer 9 10 ; Zero byte allocas should be merged if they can't be deleted. 11 ; CHECK-LABEL: @test( 12 ; CHECK: alloca 13 ; CHECK-NOT: alloca 14 define void @test() { 15 %X = alloca [0 x i32] ; <[0 x i32]*> [#uses=1] 16 call void (...)* @use( [0 x i32]* %X ) 17 %Y = alloca i32, i32 0 ; <i32*> [#uses=1] 18 call void (...)* @use( i32* %Y ) 19 %Z = alloca { } ; <{ }*> [#uses=1] 20 call void (...)* @use( { }* %Z ) 21 %size = load i32* @int 22 %A = alloca {{}}, i32 %size 23 call void (...)* @use( {{}}* %A ) 24 ret void 25 } 26 27 ; Zero byte allocas should be deleted. 28 ; CHECK-LABEL: @test2( 29 ; CHECK-NOT: alloca 30 define void @test2() { 31 %A = alloca i32 ; <i32*> [#uses=1] 32 store i32 123, i32* %A 33 ret void 34 } 35 36 ; Zero byte allocas should be deleted. 37 ; CHECK-LABEL: @test3( 38 ; CHECK-NOT: alloca 39 define void @test3() { 40 %A = alloca { i32 } ; <{ i32 }*> [#uses=1] 41 %B = getelementptr { i32 }* %A, i32 0, i32 0 ; <i32*> [#uses=1] 42 store i32 123, i32* %B 43 ret void 44 } 45 46 ; CHECK-LABEL: @test4( 47 ; CHECK: = zext i32 %n to i64 48 ; CHECK: %A = alloca i32, i64 % 49 define i32* @test4(i32 %n) { 50 %A = alloca i32, i32 %n 51 ret i32* %A 52 } 53 54 ; Allocas which are only used by GEPs, bitcasts, and stores (transitively) 55 ; should be deleted. 56 define void @test5() { 57 ; CHECK-LABEL: @test5( 58 ; CHECK-NOT: alloca 59 ; CHECK-NOT: store 60 ; CHECK: ret 61 62 entry: 63 %a = alloca { i32 } 64 %b = alloca i32* 65 %a.1 = getelementptr { i32 }* %a, i32 0, i32 0 66 store i32 123, i32* %a.1 67 store i32* %a.1, i32** %b 68 %b.1 = bitcast i32** %b to i32* 69 store i32 123, i32* %b.1 70 %a.2 = getelementptr { i32 }* %a, i32 0, i32 0 71 store atomic i32 2, i32* %a.2 unordered, align 4 72 %a.3 = getelementptr { i32 }* %a, i32 0, i32 0 73 store atomic i32 3, i32* %a.3 release, align 4 74 %a.4 = getelementptr { i32 }* %a, i32 0, i32 0 75 store atomic i32 4, i32* %a.4 seq_cst, align 4 76 ret void 77 } 78 79 declare void @f(i32* %p) 80 81 ; Check that we don't delete allocas in some erroneous cases. 82 define void @test6() { 83 ; CHECK-LABEL: @test6( 84 ; CHECK-NOT: ret 85 ; CHECK: alloca 86 ; CHECK-NEXT: alloca 87 ; CHECK: ret 88 89 entry: 90 %a = alloca { i32 } 91 %b = alloca i32 92 %a.1 = getelementptr { i32 }* %a, i32 0, i32 0 93 store volatile i32 123, i32* %a.1 94 tail call void @f(i32* %b) 95 ret void 96 } 97 98 ; PR14371 99 %opaque_type = type opaque 100 %real_type = type { { i32, i32* } } 101 102 @opaque_global = external constant %opaque_type, align 4 103 104 define void @test7() { 105 entry: 106 %0 = alloca %real_type, align 4 107 %1 = bitcast %real_type* %0 to i8* 108 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %1, i8* bitcast (%opaque_type* @opaque_global to i8*), i32 8, i32 1, i1 false) 109 ret void 110 } 111 112 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind 113