1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; Test lib call simplification of __memmove_chk calls with various values
5 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
7 target 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"
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] }
13 @t1 = common global %struct.T1 zeroinitializer
14 @t2 = common global %struct.T2 zeroinitializer
15 @t3 = common global %struct.T3 zeroinitializer
17 ; Check cases where dstlen >= len.
19 define ptr @test_simplify1() {
20 ; CHECK-LABEL: @test_simplify1(
21 ; CHECK-NEXT: call void @llvm.memmove.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
25 %ret = call ptr @__memmove_chk(ptr @t1, ptr @t2, i64 1824, i64 1824)
29 define ptr @test_simplify2() {
30 ; CHECK-LABEL: @test_simplify2(
31 ; CHECK-NEXT: call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(1824) @t1, ptr noundef nonnull align 4 dereferenceable(1824) @t3, i64 1824, i1 false)
32 ; CHECK-NEXT: ret ptr @t1
35 %ret = call ptr @__memmove_chk(ptr @t1, ptr @t3, i64 1824, i64 2848)
39 define ptr @test_simplify3() {
40 ; CHECK-LABEL: @test_simplify3(
41 ; CHECK-NEXT: tail call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(1824) @t1, ptr noundef nonnull align 4 dereferenceable(1824) @t2, i64 1824, i1 false)
42 ; CHECK-NEXT: ret ptr @t1
45 %ret = tail call ptr @__memmove_chk(ptr @t1, ptr @t2, i64 1824, i64 1824)
49 ; Check cases where dstlen < len.
51 define ptr @test_no_simplify1() {
52 ; CHECK-LABEL: @test_no_simplify1(
53 ; CHECK-NEXT: [[RET:%.*]] = call ptr @__memmove_chk(ptr nonnull @t3, ptr nonnull @t1, i64 2848, i64 1824)
54 ; CHECK-NEXT: ret ptr [[RET]]
57 %ret = call ptr @__memmove_chk(ptr @t3, ptr @t1, i64 2848, i64 1824)
61 define ptr @test_no_simplify2() {
62 ; CHECK-LABEL: @test_no_simplify2(
63 ; CHECK-NEXT: [[RET:%.*]] = call ptr @__memmove_chk(ptr nonnull @t1, ptr nonnull @t2, i64 1024, i64 0)
64 ; CHECK-NEXT: ret ptr [[RET]]
67 %ret = call ptr @__memmove_chk(ptr @t1, ptr @t2, i64 1024, i64 0)
71 define ptr @test_no_simplify3(ptr %dst, ptr %src, i64 %a, i64 %b) {
72 ; CHECK-LABEL: @test_no_simplify3(
73 ; CHECK-NEXT: [[RET:%.*]] = musttail call ptr @__memmove_chk(ptr [[DST:%.*]], ptr [[SRC:%.*]], i64 1824, i64 1824)
74 ; CHECK-NEXT: ret ptr [[RET]]
76 %ret = musttail call ptr @__memmove_chk(ptr %dst, ptr %src, i64 1824, i64 1824)
80 define ptr @test_no_incompatible_attr(ptr %mem, i32 %val, i32 %size) {
81 ; CHECK-LABEL: @test_no_incompatible_attr(
82 ; CHECK-NEXT: call void @llvm.memmove.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(1824) @t1, ptr noundef nonnull align 4 dereferenceable(1824) @t2, i64 1824, i1 false)
83 ; CHECK-NEXT: ret ptr @t1
86 %ret = call dereferenceable(1) ptr @__memmove_chk(ptr @t1, ptr @t2, i64 1824, i64 1824)
90 declare ptr @__memmove_chk(ptr, ptr, i64, i64)