1 ; RUN: opt -mem2reg -S -o - < %s | FileCheck %s 2 3 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-n8:16:32:64" 4 5 declare void @llvm.lifetime.start(i64 %size, i8* nocapture %ptr) 6 declare void @llvm.lifetime.end(i64 %size, i8* nocapture %ptr) 7 8 define void @test1() { 9 ; Ensure we can look through a bitcast to i8* and the addition of lifetime 10 ; markers. 11 ; 12 ; CHECK-LABEL: @test1( 13 ; CHECK-NOT: alloca 14 ; CHECK: ret void 15 16 %A = alloca i32 17 %B = bitcast i32* %A to i8* 18 call void @llvm.lifetime.start(i64 2, i8* %B) 19 store i32 1, i32* %A 20 call void @llvm.lifetime.end(i64 2, i8* %B) 21 ret void 22 } 23 24 define void @test2() { 25 ; Ensure we can look through a GEP to i8* and the addition of lifetime 26 ; markers. 27 ; 28 ; CHECK-LABEL: @test2( 29 ; CHECK-NOT: alloca 30 ; CHECK: ret void 31 32 %A = alloca {i8, i16} 33 %B = getelementptr {i8, i16}* %A, i32 0, i32 0 34 call void @llvm.lifetime.start(i64 2, i8* %B) 35 store {i8, i16} zeroinitializer, {i8, i16}* %A 36 call void @llvm.lifetime.end(i64 2, i8* %B) 37 ret void 38 } 39 40 define i32 @test3(i32 %x) { 41 ; CHECK-LABEL: @test3( 42 ; 43 ; Check that we recursively walk the uses of the alloca and thus can see 44 ; through round trip bitcasts, dead bitcasts, GEPs, multiple GEPs, and lifetime 45 ; markers. 46 entry: 47 %a = alloca i32 48 ; CHECK-NOT: alloca 49 50 %b = bitcast i32* %a to i8* 51 %b2 = getelementptr inbounds i8* %b, i32 0 52 %b3 = getelementptr inbounds i8* %b2, i32 0 53 call void @llvm.lifetime.start(i64 -1, i8* %b3) 54 ; CHECK-NOT: call void @llvm.lifetime.start 55 56 store i32 %x, i32* %a 57 ; CHECK-NOT: store 58 59 %dead = bitcast i32* %a to i4096* 60 %dead1 = bitcast i4096* %dead to i42* 61 %dead2 = getelementptr inbounds i32* %a, i32 %x 62 ; CHECK-NOT: bitcast 63 ; CHECK-NOT: getelementptr 64 65 %ret = load i32* %a 66 ; CHECK-NOT: load 67 68 ret i32 %ret 69 ; CHECK: ret i32 %x 70 } 71