1; RUN: opt < %s -data-layout="e-p:32:32:32-p1:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-n8:16:32" -basic-aa -newgvn -S -dce | FileCheck %s
2; RUN: opt < %s -data-layout="E-p:32:32:32-p1:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-n32"      -basic-aa -newgvn -S -dce | FileCheck %s
3; memset -> i16 forwarding.
4define signext i16 @memset_to_i16_local(i16* %A) nounwind ssp {
5entry:
6  %conv = bitcast i16* %A to i8*
7  tail call void @llvm.memset.p0i8.i64(i8* %conv, i8 1, i64 200, i1 false)
8  %arrayidx = getelementptr inbounds i16, i16* %A, i64 42
9  %tmp2 = load i16, i16* %arrayidx
10  ret i16 %tmp2
11; CHECK-LABEL: @memset_to_i16_local(
12; CHECK-NOT: load
13; CHECK: ret i16 257
14}
15
16@GCst = constant {i32, float, i32 } { i32 42, float 14., i32 97 }
17@GCst_as1 = addrspace(1) constant {i32, float, i32 } { i32 42, float 14., i32 97 }
18
19; memset -> float forwarding.
20define float @memcpy_to_float_local(float* %A) nounwind ssp {
21entry:
22  %conv = bitcast float* %A to i8*                ; <i8*> [#uses=1]
23  tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* %conv, i8* bitcast ({i32, float, i32 }* @GCst to i8*), i64 12, i1 false)
24  %arrayidx = getelementptr inbounds float, float* %A, i64 1 ; <float*> [#uses=1]
25  %tmp2 = load float, float* %arrayidx                   ; <float> [#uses=1]
26  ret float %tmp2
27; CHECK-LABEL: @memcpy_to_float_local(
28; CHECK-NOT: load
29; CHECK: ret float 1.400000e+01
30}
31; memcpy from address space 1
32define float @memcpy_to_float_local_as1(float* %A) nounwind ssp {
33entry:
34  %conv = bitcast float* %A to i8*                ; <i8*> [#uses=1]
35  tail call void @llvm.memcpy.p0i8.p1i8.i64(i8* %conv, i8 addrspace(1)* bitcast ({i32, float, i32 } addrspace(1)* @GCst_as1 to i8 addrspace(1)*), i64 12, i1 false)
36  %arrayidx = getelementptr inbounds float, float* %A, i64 1 ; <float*> [#uses=1]
37  %tmp2 = load float, float* %arrayidx                   ; <float> [#uses=1]
38  ret float %tmp2
39; CHECK-LABEL: @memcpy_to_float_local_as1(
40; CHECK-NOT: load
41; CHECK: ret float 1.400000e+01
42}
43
44; PR6642
45define i32 @memset_to_load() nounwind readnone {
46entry:
47  %x = alloca [256 x i32], align 4                ; <[256 x i32]*> [#uses=2]
48  %tmp = bitcast [256 x i32]* %x to i8*           ; <i8*> [#uses=1]
49  call void @llvm.memset.p0i8.i64(i8* align 4 %tmp, i8 0, i64 1024, i1 false)
50  %arraydecay = getelementptr inbounds [256 x i32], [256 x i32]* %x, i32 0, i32 0 ; <i32*>
51  %tmp1 = load i32, i32* %arraydecay                   ; <i32> [#uses=1]
52  ret i32 %tmp1
53; CHECK-LABEL: @memset_to_load(
54; CHECK: ret i32 0
55}
56declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind
57
58declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind
59declare void @llvm.memcpy.p0i8.p1i8.i64(i8* nocapture, i8 addrspace(1)* nocapture, i64, i1) nounwind
60