2009-10-18 04:41:36 +00:00
|
|
|
; RUN: opt < %s -basicaa -gvn -dse -S | FileCheck %s
|
2009-11-03 15:29:06 +00:00
|
|
|
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"
|
2009-10-17 23:59:51 +00:00
|
|
|
|
|
|
|
declare void @llvm.memset.i32(i8*, i8, i32, i32)
|
2009-10-18 04:41:36 +00:00
|
|
|
declare void @llvm.memset.i8(i8*, i8, i8, i32)
|
|
|
|
declare void @llvm.memcpy.i8(i8*, i8*, i8, i32)
|
2009-11-26 02:16:28 +00:00
|
|
|
declare void @llvm.memcpy.i32(i8*, i8*, i32, i32)
|
2009-10-18 04:41:36 +00:00
|
|
|
declare void @llvm.lifetime.end(i64, i8* nocapture)
|
2006-11-18 05:52:18 +00:00
|
|
|
|
2009-10-17 23:59:51 +00:00
|
|
|
declare void @external(i32*)
|
|
|
|
|
|
|
|
define i32 @test0(i8* %P) {
|
|
|
|
%A = alloca i32
|
|
|
|
call void @external(i32* %A)
|
|
|
|
|
|
|
|
store i32 0, i32* %A
|
|
|
|
|
|
|
|
call void @llvm.memset.i32(i8* %P, i8 0, i32 42, i32 1)
|
|
|
|
|
|
|
|
%B = load i32* %A
|
|
|
|
ret i32 %B
|
|
|
|
|
|
|
|
; CHECK: @test0
|
|
|
|
; CHECK: ret i32 0
|
2006-11-18 05:52:18 +00:00
|
|
|
}
|
2009-10-17 23:59:51 +00:00
|
|
|
|
2009-10-18 04:41:36 +00:00
|
|
|
declare void @llvm.memcpy.i8(i8*, i8*, i8, i32)
|
|
|
|
|
|
|
|
define i8 @test1() {
|
|
|
|
; CHECK: @test1
|
|
|
|
%A = alloca i8
|
|
|
|
%B = alloca i8
|
|
|
|
|
|
|
|
store i8 2, i8* %B ;; Not written to by memcpy
|
|
|
|
|
|
|
|
call void @llvm.memcpy.i8(i8* %A, i8* %B, i8 -1, i32 0)
|
|
|
|
|
|
|
|
%C = load i8* %B
|
|
|
|
ret i8 %C
|
|
|
|
; CHECK: ret i8 2
|
|
|
|
}
|
|
|
|
|
|
|
|
define i8 @test2(i8* %P) {
|
|
|
|
; CHECK: @test2
|
2009-10-18 04:50:18 +00:00
|
|
|
%P2 = getelementptr i8* %P, i32 127
|
2009-10-18 04:41:36 +00:00
|
|
|
store i8 1, i8* %P2 ;; Not dead across memset
|
|
|
|
call void @llvm.memset.i8(i8* %P, i8 2, i8 127, i32 0)
|
|
|
|
%A = load i8* %P2
|
|
|
|
ret i8 %A
|
|
|
|
; CHECK: ret i8 1
|
|
|
|
}
|
|
|
|
|
2009-10-18 04:50:18 +00:00
|
|
|
define i8 @test2a(i8* %P) {
|
|
|
|
; CHECK: @test2
|
|
|
|
%P2 = getelementptr i8* %P, i32 126
|
2009-10-18 04:55:26 +00:00
|
|
|
|
|
|
|
;; FIXME: DSE isn't zapping this dead store.
|
2009-10-18 04:50:18 +00:00
|
|
|
store i8 1, i8* %P2 ;; Dead, clobbered by memset.
|
2009-10-18 04:55:26 +00:00
|
|
|
|
2009-10-18 04:50:18 +00:00
|
|
|
call void @llvm.memset.i8(i8* %P, i8 2, i8 127, i32 0)
|
|
|
|
%A = load i8* %P2
|
|
|
|
ret i8 %A
|
2009-12-06 04:16:05 +00:00
|
|
|
; CHECK-NOT: load
|
|
|
|
; CHECK: ret i8 2
|
2009-10-18 04:50:18 +00:00
|
|
|
}
|
|
|
|
|
2009-10-18 04:55:26 +00:00
|
|
|
define void @test3(i8* %P, i8 %X) {
|
2009-10-18 04:41:36 +00:00
|
|
|
; CHECK: @test3
|
2009-10-18 04:55:26 +00:00
|
|
|
; CHECK-NOT: store
|
|
|
|
; CHECK-NOT: %Y
|
|
|
|
%Y = add i8 %X, 1 ;; Dead, because the only use (the store) is dead.
|
|
|
|
|
2009-10-18 04:41:36 +00:00
|
|
|
%P2 = getelementptr i8* %P, i32 2
|
2009-10-18 04:55:26 +00:00
|
|
|
store i8 %Y, i8* %P2 ;; Not read by lifetime.end, should be removed.
|
|
|
|
; CHECK: store i8 2, i8* %P2
|
2009-10-18 04:41:36 +00:00
|
|
|
call void @llvm.lifetime.end(i64 1, i8* %P)
|
|
|
|
store i8 2, i8* %P2
|
|
|
|
; CHECK-NOT: store
|
|
|
|
ret void
|
|
|
|
; CHECK: ret void
|
2009-10-18 04:55:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
define void @test3a(i8* %P, i8 %X) {
|
|
|
|
; CHECK: @test3a
|
|
|
|
%Y = add i8 %X, 1 ;; Dead, because the only use (the store) is dead.
|
|
|
|
|
|
|
|
%P2 = getelementptr i8* %P, i32 2
|
2010-11-30 23:25:01 +00:00
|
|
|
store i8 %Y, i8* %P2
|
|
|
|
; CHECK-NEXT: call void @llvm.lifetime.end
|
2009-10-18 04:55:26 +00:00
|
|
|
call void @llvm.lifetime.end(i64 10, i8* %P)
|
|
|
|
ret void
|
2010-11-30 23:25:01 +00:00
|
|
|
; CHECK-NEXT: ret void
|
2009-11-03 15:29:06 +00:00
|
|
|
}
|
2009-11-22 16:15:59 +00:00
|
|
|
|
|
|
|
@G1 = external global i32
|
|
|
|
@G2 = external global [4000 x i32]
|
|
|
|
|
2009-11-26 02:16:28 +00:00
|
|
|
define i32 @test4(i8* %P) {
|
2009-11-22 16:15:59 +00:00
|
|
|
%tmp = load i32* @G1
|
|
|
|
call void @llvm.memset.i32(i8* bitcast ([4000 x i32]* @G2 to i8*), i8 0, i32 4000, i32 1)
|
|
|
|
%tmp2 = load i32* @G1
|
|
|
|
%sub = sub i32 %tmp2, %tmp
|
|
|
|
ret i32 %sub
|
|
|
|
; CHECK: @test4
|
|
|
|
; CHECK: load i32* @G
|
Reapply address space patch after fixing an issue in MemCopyOptimizer.
Added support for address spaces and added a isVolatile field to memcpy, memmove, and memset,
e.g., llvm.memcpy.i32(i8*, i8*, i32, i32) -> llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100304 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-04 03:10:48 +00:00
|
|
|
; CHECK: memset.p0i8.i32
|
2009-11-22 16:15:59 +00:00
|
|
|
; CHECK-NOT: load
|
|
|
|
; CHECK: sub i32 %tmp, %tmp
|
|
|
|
}
|
|
|
|
|
2009-11-26 02:16:28 +00:00
|
|
|
; Verify that basicaa is handling variable length memcpy, knowing it doesn't
|
|
|
|
; write to G1.
|
|
|
|
define i32 @test5(i8* %P, i32 %Len) {
|
|
|
|
%tmp = load i32* @G1
|
|
|
|
call void @llvm.memcpy.i32(i8* bitcast ([4000 x i32]* @G2 to i8*), i8* bitcast (i32* @G1 to i8*), i32 %Len, i32 1)
|
|
|
|
%tmp2 = load i32* @G1
|
|
|
|
%sub = sub i32 %tmp2, %tmp
|
|
|
|
ret i32 %sub
|
|
|
|
; CHECK: @test5
|
|
|
|
; CHECK: load i32* @G
|
Reapply address space patch after fixing an issue in MemCopyOptimizer.
Added support for address spaces and added a isVolatile field to memcpy, memmove, and memset,
e.g., llvm.memcpy.i32(i8*, i8*, i32, i32) -> llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i32, i1)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100304 91177308-0d34-0410-b5e6-96231b3b80d8
2010-04-04 03:10:48 +00:00
|
|
|
; CHECK: memcpy.p0i8.p0i8.i32
|
2009-11-26 02:16:28 +00:00
|
|
|
; CHECK-NOT: load
|
|
|
|
; CHECK: sub i32 %tmp, %tmp
|
|
|
|
}
|
|
|
|
|
2010-08-06 18:24:38 +00:00
|
|
|
define i8 @test6(i8* %p, i8* noalias %a) {
|
|
|
|
%x = load i8* %a
|
|
|
|
%t = va_arg i8* %p, float
|
|
|
|
%y = load i8* %a
|
|
|
|
%z = add i8 %x, %y
|
|
|
|
ret i8 %z
|
|
|
|
; CHECK: @test6
|
|
|
|
; CHECK: load i8* %a
|
|
|
|
; CHECK-NOT: load
|
|
|
|
; CHECK: ret
|
|
|
|
}
|