1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
4 ; Memcpy is copying known-undef, and is thus removable
5 define void @test(ptr %dest) {
10 call void @llvm.memcpy.p0.p0.i64(ptr %dest, ptr %a, i64 7, i1 false)
14 ; Some non-undef elements
15 define void @test2(ptr %dest) {
16 ; CHECK-LABEL: @test2(
17 ; CHECK-NEXT: [[A:%.*]] = alloca [7 x i8], align 1
18 ; CHECK-NEXT: store i8 0, ptr [[A]], align 1
19 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(7) [[DEST:%.*]], ptr noundef nonnull align 1 dereferenceable(7) [[A]], i64 7, i1 false)
20 ; CHECK-NEXT: ret void
24 call void @llvm.memcpy.p0.p0.i64(ptr %dest, ptr %a, i64 7, i1 false)
28 ; Volatile write is still required
29 define void @test3(ptr %dest) {
30 ; CHECK-LABEL: @test3(
31 ; CHECK-NEXT: [[A:%.*]] = alloca [7 x i8], align 1
32 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr [[DEST:%.*]], ptr [[A]], i64 7, i1 true)
33 ; CHECK-NEXT: ret void
36 call void @llvm.memcpy.p0.p0.i64(ptr %dest, ptr %a, i64 7, i1 true)
40 define void @test4(ptr %dest) {
41 ; CHECK-LABEL: @test4(
42 ; CHECK-NEXT: ret void
45 call void @llvm.memcpy.p0.p0.i64(ptr %dest, ptr %a, i64 7, i1 false)
49 define void @test5(ptr %dest) {
50 ; CHECK-LABEL: @test5(
51 ; CHECK-NEXT: ret void
54 %p2 = getelementptr i32, ptr %a, i32 1
55 call void @llvm.memcpy.p0.p0.i64(ptr %dest, ptr %p2, i64 3, i1 false)
59 define void @test6(ptr %dest) {
60 ; CHECK-LABEL: @test6(
61 ; CHECK-NEXT: [[A:%.*]] = alloca [7 x i8], align 1
62 ; CHECK-NEXT: [[P2:%.*]] = getelementptr inbounds i16, ptr [[A]], i64 1
63 ; CHECK-NEXT: store i16 42, ptr [[P2]], align 2
64 ; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(7) [[DEST:%.*]], ptr noundef nonnull align 1 dereferenceable(7) [[P2]], i64 7, i1 false)
65 ; CHECK-NEXT: ret void
68 %p2 = getelementptr i16, ptr %a, i32 1
70 call void @llvm.memcpy.p0.p0.i64(ptr %dest, ptr %p2, i64 7, i1 false)
74 declare void @llvm.memcpy.p0.p0.i64(ptr, ptr, i64, i1)