1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; Test lib call simplification of __memcpy_chk calls with various values 3; for dstlen and len. 4; 5; RUN: opt < %s -passes=instcombine -S | FileCheck %s 6 7target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" 8 9%struct.T1 = type { [100 x i32], [100 x i32], [1024 x i8] } 10%struct.T2 = type { [100 x i32], [100 x i32], [1024 x i8] } 11%struct.T3 = type { [100 x i32], [100 x i32], [2048 x i8] } 12 13@t1 = common global %struct.T1 zeroinitializer 14@t2 = common global %struct.T2 zeroinitializer 15@t3 = common global %struct.T3 zeroinitializer 16 17; Check cases where dstlen >= len. 18 19define ptr @test_simplify1() { 20; CHECK-LABEL: @test_simplify1( 21; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(1824) @t1, ptr noundef nonnull align 4 dereferenceable(1824) @t2, i64 1824, i1 false) 22; CHECK-NEXT: ret ptr @t1 23; 24 %ret = call ptr @__memcpy_chk(ptr @t1, ptr @t2, i64 1824, i64 1824) 25 ret ptr %ret 26} 27 28define ptr @test_simplify2() { 29; CHECK-LABEL: @test_simplify2( 30; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(1824) @t1, ptr noundef nonnull align 4 dereferenceable(1824) @t3, i64 1824, i1 false) 31; CHECK-NEXT: ret ptr @t1 32; 33 %ret = call ptr @__memcpy_chk(ptr @t1, ptr @t3, i64 1824, i64 2848) 34 ret ptr %ret 35} 36 37; Same as test_simplify1 but with a tail call rather than vanilla call. 38define ptr @test_simplify3() { 39; CHECK-LABEL: @test_simplify3( 40; CHECK-NEXT: tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(1824) @t1, ptr noundef nonnull align 4 dereferenceable(1824) @t2, i64 1824, i1 false) 41; CHECK-NEXT: ret ptr @t1 42; 43 %ret = tail call ptr @__memcpy_chk(ptr @t1, ptr @t2, i64 1824, i64 1824) 44 ret ptr %ret 45} 46 47; Check cases where dstlen < len. 48 49define ptr @test_no_simplify1() { 50; CHECK-LABEL: @test_no_simplify1( 51; CHECK-NEXT: [[RET:%.*]] = call ptr @__memcpy_chk(ptr nonnull @t3, ptr nonnull @t1, i64 2848, i64 1824) 52; CHECK-NEXT: ret ptr [[RET]] 53; 54 %ret = call ptr @__memcpy_chk(ptr @t3, ptr @t1, i64 2848, i64 1824) 55 ret ptr %ret 56} 57 58define ptr @test_no_simplify2() { 59; CHECK-LABEL: @test_no_simplify2( 60; CHECK-NEXT: [[RET:%.*]] = call ptr @__memcpy_chk(ptr nonnull @t1, ptr nonnull @t2, i64 1024, i64 0) 61; CHECK-NEXT: ret ptr [[RET]] 62; 63 %ret = call ptr @__memcpy_chk(ptr @t1, ptr @t2, i64 1024, i64 0) 64 ret ptr %ret 65} 66 67define ptr @test_no_simplify3(ptr %dst, ptr %src, i64 %a, i64 %b) { 68; CHECK-LABEL: @test_no_simplify3( 69; CHECK-NEXT: [[RET:%.*]] = musttail call ptr @__memcpy_chk(ptr [[DST:%.*]], ptr [[SRC:%.*]], i64 1824, i64 1824) 70; CHECK-NEXT: ret ptr [[RET]] 71; 72 %ret = musttail call ptr @__memcpy_chk(ptr %dst, ptr %src, i64 1824, i64 1824) 73 ret ptr %ret 74} 75 76define ptr @test_simplify_return_indcall(ptr %alloc) { 77; CHECK-LABEL: @test_simplify_return_indcall( 78; CHECK-NEXT: [[DST:%.*]] = call ptr [[ALLOC:%.*]]() 79; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(1824) [[DST]], ptr noundef nonnull align 4 dereferenceable(1824) @t2, i64 1824, i1 false) 80; CHECK-NEXT: ret ptr [[DST]] 81; 82 %dst = call ptr %alloc() 83 %ret = call ptr @__memcpy_chk(ptr %dst, ptr @t2, i64 1824, i64 1824) 84 ret ptr %ret 85} 86 87define ptr @test_no_incompatible_attr(ptr %mem, i32 %val, i32 %size) { 88; CHECK-LABEL: @test_no_incompatible_attr( 89; CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(1824) @t1, ptr noundef nonnull align 4 dereferenceable(1824) @t2, i64 1824, i1 false) 90; CHECK-NEXT: ret ptr @t1 91; 92 %ret = call dereferenceable(1) ptr @__memcpy_chk(ptr @t1, ptr @t2, i64 1824, i64 1824) 93 ret ptr %ret 94} 95 96declare ptr @__memcpy_chk(ptr, ptr, i64, i64) 97