brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.7 KiB · 7fdfa35 Raw
140 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; Test lib call simplification of __strcpy_chk calls with various values3; for src, dst, and slen.4;5; RUN: opt < %s -passes=instcombine -S | FileCheck %s6 7target 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"8 9@a = common global [60 x i8] zeroinitializer, align 110@b = common global [60 x i8] zeroinitializer, align 111@.str = private constant [12 x i8] c"abcdefghijk\00"12 13; Check cases where slen >= strlen (src).14 15define ptr @test_simplify1() {16; CHECK-LABEL: @test_simplify1(17; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(12) @a, ptr noundef nonnull align 1 dereferenceable(12) @.str, i32 12, i1 false)18; CHECK-NEXT:    ret ptr @a19;20 21  %ret = call ptr @__strcpy_chk(ptr @a, ptr @.str, i32 60)22  ret ptr %ret23}24 25define ptr @test_simplify1_tail() {26; CHECK-LABEL: @test_simplify1_tail(27; CHECK-NEXT:    tail call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(12) @a, ptr noundef nonnull align 1 dereferenceable(12) @.str, i32 12, i1 false)28; CHECK-NEXT:    ret ptr @a29;30 31  %ret = tail call ptr @__strcpy_chk(ptr @a, ptr @.str, i32 60)32  ret ptr %ret33}34 35define ptr @test_simplify2() {36; CHECK-LABEL: @test_simplify2(37; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(12) @a, ptr noundef nonnull align 1 dereferenceable(12) @.str, i32 12, i1 false)38; CHECK-NEXT:    ret ptr @a39;40 41  %ret = call ptr @__strcpy_chk(ptr @a, ptr @.str, i32 12)42  ret ptr %ret43}44 45define ptr @test_simplify3() {46; CHECK-LABEL: @test_simplify3(47; CHECK-NEXT:    call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(12) @a, ptr noundef nonnull align 1 dereferenceable(12) @.str, i32 12, i1 false)48; CHECK-NEXT:    ret ptr @a49;50 51  %ret = call ptr @__strcpy_chk(ptr @a, ptr @.str, i32 -1)52  ret ptr %ret53}54 55; Check cases where there are no string constants.56 57define ptr @test_simplify4() {58; CHECK-LABEL: @test_simplify4(59; CHECK-NEXT:    [[STRCPY:%.*]] = call ptr @strcpy(ptr noundef nonnull dereferenceable(1) @a, ptr noundef nonnull dereferenceable(1) @b)60; CHECK-NEXT:    ret ptr @a61;62 63  %ret = call ptr @__strcpy_chk(ptr @a, ptr @b, i32 -1)64  ret ptr %ret65}66 67define ptr @test_simplify4_tail() {68; CHECK-LABEL: @test_simplify4_tail(69; CHECK-NEXT:    [[STRCPY:%.*]] = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) @a, ptr noundef nonnull dereferenceable(1) @b)70; CHECK-NEXT:    ret ptr @a71;72 73  %ret = tail call ptr @__strcpy_chk(ptr @a, ptr @b, i32 -1)74  ret ptr %ret75}76 77; Check case where the string length is not constant.78 79define ptr @test_simplify5() {80; CHECK-LABEL: @test_simplify5(81; CHECK-NEXT:    [[LEN:%.*]] = call i32 @llvm.objectsize.i32.p0(ptr @a, i1 false, i1 false, i1 false)82; CHECK-NEXT:    [[RET:%.*]] = call ptr @__memcpy_chk(ptr nonnull @a, ptr nonnull @.str, i32 12, i32 [[LEN]])83; CHECK-NEXT:    ret ptr [[RET]]84;85 86  %len = call i32 @llvm.objectsize.i32.p0(ptr @a, i1 false, i1 false, i1 false)87  %ret = call ptr @__strcpy_chk(ptr @a, ptr @.str, i32 %len)88  ret ptr %ret89}90 91; Check case where the source and destination are the same.92 93define ptr @test_simplify6() {94; CHECK-LABEL: @test_simplify6(95; CHECK-NEXT:    [[LEN:%.*]] = call i32 @llvm.objectsize.i32.p0(ptr @a, i1 false, i1 false, i1 false)96; CHECK-NEXT:    [[RET:%.*]] = call ptr @__strcpy_chk(ptr nonnull @a, ptr nonnull @a, i32 [[LEN]])97; CHECK-NEXT:    ret ptr [[RET]]98;99 100  %len = call i32 @llvm.objectsize.i32.p0(ptr @a, i1 false, i1 false, i1 false)101  %ret = call ptr @__strcpy_chk(ptr @a, ptr @a, i32 %len)102  ret ptr %ret103}104 105; Check cases where there are no string constants, and is a tail call.106 107define ptr @test_simplify7() {108; CHECK-LABEL: @test_simplify7(109; CHECK-NEXT:    [[STRCPY:%.*]] = tail call ptr @strcpy(ptr noundef nonnull dereferenceable(1) @a, ptr noundef nonnull dereferenceable(1) @b)110; CHECK-NEXT:    ret ptr @a111;112 113  %ret = tail call ptr @__strcpy_chk(ptr @a, ptr @b, i32 -1)114  ret ptr %ret115}116 117; Check case where slen < strlen (src).118 119define ptr @test_no_simplify1() {120; CHECK-LABEL: @test_no_simplify1(121; CHECK-NEXT:    [[RET:%.*]] = call ptr @__strcpy_chk(ptr nonnull @a, ptr nonnull @b, i32 8)122; CHECK-NEXT:    ret ptr [[RET]]123;124 125  %ret = call ptr @__strcpy_chk(ptr @a, ptr @b, i32 8)126  ret ptr %ret127}128 129define ptr @test_no_simplify2(ptr %dst, ptr %src, i32 %a) {130; CHECK-LABEL: @test_no_simplify2(131; CHECK-NEXT:    [[RET:%.*]] = musttail call ptr @__strcpy_chk(ptr [[DST:%.*]], ptr [[SRC:%.*]], i32 60)132; CHECK-NEXT:    ret ptr [[RET]]133;134  %ret = musttail call ptr @__strcpy_chk(ptr %dst, ptr %src, i32 60)135  ret ptr %ret136}137 138declare ptr @__strcpy_chk(ptr, ptr, i32) nounwind139declare i32 @llvm.objectsize.i32.p0(ptr, i1, i1, i1) nounwind readonly140