1 ; RUN: opt < %s -basicaa -gvn -dse -S | FileCheck %s
2 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"
4 declare void @llvm.memset.i32(i8*, i8, i32, i32)
5 declare void @llvm.memset.i8(i8*, i8, i8, i32)
6 declare void @llvm.memcpy.i8(i8*, i8*, i8, i32)
7 declare void @llvm.memcpy.i32(i8*, i8*, i32, i32)
8 declare void @llvm.lifetime.end(i64, i8* nocapture)
10 declare void @external(i32*)
12 define i32 @test0(i8* %P) {
14 call void @external(i32* %A)
18 call void @llvm.memset.i32(i8* %P, i8 0, i32 42, i32 1)
27 declare void @llvm.memcpy.i8(i8*, i8*, i8, i32)
34 store i8 2, i8* %B ;; Not written to by memcpy
36 call void @llvm.memcpy.i8(i8* %A, i8* %B, i8 -1, i32 0)
43 define i8 @test2(i8* %P) {
45 %P2 = getelementptr i8* %P, i32 127
46 store i8 1, i8* %P2 ;; Not dead across memset
47 call void @llvm.memset.i8(i8* %P, i8 2, i8 127, i32 0)
53 define i8 @test2a(i8* %P) {
55 %P2 = getelementptr i8* %P, i32 126
57 ;; FIXME: DSE isn't zapping this dead store.
58 store i8 1, i8* %P2 ;; Dead, clobbered by memset.
60 call void @llvm.memset.i8(i8* %P, i8 2, i8 127, i32 0)
67 define void @test3(i8* %P, i8 %X) {
71 %Y = add i8 %X, 1 ;; Dead, because the only use (the store) is dead.
73 %P2 = getelementptr i8* %P, i32 2
74 store i8 %Y, i8* %P2 ;; Not read by lifetime.end, should be removed.
75 ; CHECK: store i8 2, i8* %P2
76 call void @llvm.lifetime.end(i64 1, i8* %P)
83 define void @test3a(i8* %P, i8 %X) {
85 %Y = add i8 %X, 1 ;; Dead, because the only use (the store) is dead.
87 %P2 = getelementptr i8* %P, i32 2
89 ; CHECK-NEXT: call void @llvm.lifetime.end
90 call void @llvm.lifetime.end(i64 10, i8* %P)
92 ; CHECK-NEXT: ret void
95 @G1 = external global i32
96 @G2 = external global [4000 x i32]
98 define i32 @test4(i8* %P) {
100 call void @llvm.memset.i32(i8* bitcast ([4000 x i32]* @G2 to i8*), i8 0, i32 4000, i32 1)
101 %tmp2 = load i32* @G1
102 %sub = sub i32 %tmp2, %tmp
106 ; CHECK: memset.p0i8.i32
111 ; Verify that basicaa is handling variable length memcpy, knowing it doesn't
113 define i32 @test5(i8* %P, i32 %Len) {
115 call void @llvm.memcpy.i32(i8* bitcast ([4000 x i32]* @G2 to i8*), i8* bitcast (i32* @G1 to i8*), i32 %Len, i32 1)
116 %tmp2 = load i32* @G1
117 %sub = sub i32 %tmp2, %tmp
121 ; CHECK: memcpy.p0i8.p0i8.i32
126 define i8 @test6(i8* %p, i8* noalias %a) {
128 %t = va_arg i8* %p, float