xref: /llvm-project/llvm/test/Transforms/InstCombine/strcpy-1.ll (revision 635f93dff7f07a58af4e8a7c915dfdb1852bb76b)
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; Test that the strcpy library call simplifier works correctly.
3; rdar://6839935
4; RUN: opt < %s -passes=instcombine -S | FileCheck %s
5;
6; This transformation requires the pointer size, as it assumes that size_t is
7; the size of a pointer.
8target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32"
9
10@hello = constant [6 x i8] c"hello\00"
11@a = common global [32 x i8] zeroinitializer, align 1
12@b = common global [32 x i8] zeroinitializer, align 1
13
14declare ptr @strcpy(ptr, ptr)
15
16define void @test_simplify1() {
17; CHECK-LABEL: @test_simplify1(
18; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(6) @a, ptr noundef nonnull align 1 dereferenceable(6) @hello, i32 6, i1 false)
19; CHECK-NEXT:    ret void
20;
21
22
23  call ptr @strcpy(ptr @a, ptr @hello)
24  ret void
25}
26
27define ptr @test_simplify2() {
28; CHECK-LABEL: @test_simplify2(
29; CHECK-NEXT:    ret ptr @a
30;
31
32
33  %ret = call ptr @strcpy(ptr @a, ptr @a)
34  ret ptr %ret
35}
36
37
38define void @test_simplify3(ptr %dst) {
39; CHECK-LABEL: @test_simplify3(
40; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(80) [[DST:%.*]], ptr noundef nonnull align 1 dereferenceable(6) @hello, i32 6, i1 false)
41; CHECK-NEXT:    ret void
42;
43
44
45  call ptr @strcpy(ptr dereferenceable(80) %dst, ptr @hello)
46  ret void
47}
48
49define ptr @test_no_simplify1() {
50; CHECK-LABEL: @test_no_simplify1(
51; CHECK-NEXT:    [[RET:%.*]] = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) @a, ptr noundef nonnull dereferenceable(1) @b)
52; CHECK-NEXT:    ret ptr [[RET]]
53;
54
55
56  %ret = call ptr @strcpy(ptr @a, ptr @b)
57  ret ptr %ret
58}
59
60define ptr @test_no_simplify2(ptr %dst, ptr %src) {
61; CHECK-LABEL: @test_no_simplify2(
62; CHECK-NEXT:    [[RET:%.*]] = musttail call ptr @strcpy(ptr [[DST:%.*]], ptr [[SRC:%.*]])
63; CHECK-NEXT:    ret ptr [[RET]]
64;
65
66  %ret = musttail call ptr @strcpy(ptr %dst, ptr %src)
67  ret ptr %ret
68}
69
70
71define void @test_no_incompatible_attr() {
72; CHECK-LABEL: @test_no_incompatible_attr(
73; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(6) @a, ptr noundef nonnull align 1 dereferenceable(6) @hello, i32 6, i1 false)
74; CHECK-NEXT:    ret void
75;
76
77
78  call dereferenceable(1) ptr @strcpy(ptr @a, ptr @hello)
79  ret void
80}
81