instcombine: Add more test cases for __strcpy_chk simplification
[oota-llvm.git] / test / Transforms / InstCombine / strcpy_chk-1.ll
1 ; Test lib call simplification of __strcpy_chk calls with various values
2 ; for src, dst, and slen.
3 ;
4 ; RUN: opt < %s -instcombine -S | FileCheck %s
5
6 target 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"
7
8 @a = common global [60 x i8] zeroinitializer, align 1
9 @b = common global [60 x i8] zeroinitializer, align 1
10 @.str = private constant [8 x i8] c"abcdefg\00"
11
12 ; Check cases where slen >= strlen (src).
13
14 define void @test_simplify1() {
15 ; CHECK: @test_simplify1
16   %dst = getelementptr inbounds [60 x i8]* @a, i32 0, i32 0
17   %src = getelementptr inbounds [8 x i8]* @.str, i32 0, i32 0
18
19 ; CHECK-NEXT: call i8* @strcpy
20   call i8* @__strcpy_chk(i8* %dst, i8* %src, i32 60)
21   ret void
22 }
23
24 define void @test_simplify2() {
25 ; CHECK: @test_simplify2
26   %dst = getelementptr inbounds [60 x i8]* @a, i32 0, i32 0
27   %src = getelementptr inbounds [8 x i8]* @.str, i32 0, i32 0
28
29 ; CHECK-NEXT: call i8* @strcpy
30   call i8* @__strcpy_chk(i8* %dst, i8* %src, i32 8)
31   ret void
32 }
33
34 define void @test_simplify3() {
35 ; CHECK: @test_simplify3
36   %dst = getelementptr inbounds [60 x i8]* @a, i32 0, i32 0
37   %src = getelementptr inbounds [8 x i8]* @.str, i32 0, i32 0
38
39 ; CHECK-NEXT: call i8* @strcpy
40   call i8* @__strcpy_chk(i8* %dst, i8* %src, i32 -1)
41   ret void
42 }
43
44 ; Check cases where there are no string constants.
45
46 define void @test_simplify4() {
47 ; CHECK: @test_simplify4
48   %dst = getelementptr inbounds [60 x i8]* @a, i32 0, i32 0
49   %src = getelementptr inbounds [60 x i8]* @b, i32 0, i32 0
50
51 ; CHECK-NEXT: call i8* @strcpy
52   call i8* @__strcpy_chk(i8* %dst, i8* %src, i32 -1)
53   ret void
54 }
55
56 define void @test_no_simplify1() {
57 ; CHECK: @test_no_simplify1
58   %dst = getelementptr inbounds [60 x i8]* @a, i32 0, i32 0
59   %src = getelementptr inbounds [60 x i8]* @b, i32 0, i32 0
60
61 ; CHECK-NEXT: call i8* @__strcpy_chk
62   call i8* @__strcpy_chk(i8* %dst, i8* %src, i32 8)
63   ret void
64 }
65
66 ; Check case were slen < strlen (src).
67
68 define void @test_no_simplify2() {
69 ; CHECK: @test_no_simplify2
70   %dst = getelementptr inbounds [60 x i8]* @a, i32 0, i32 0
71   %src = getelementptr inbounds [8 x i8]* @.str, i32 0, i32 0
72
73 ; CHECK-NEXT: call i8* @__strcpy_chk
74   call i8* @__strcpy_chk(i8* %dst, i8* %src, i32 3)
75   ret void
76 }
77
78 define void @test_no_simplify3() {
79 ; CHECK: @test_no_simplify3
80   %dst = getelementptr inbounds [60 x i8]* @a, i32 0, i32 0
81   %src = getelementptr inbounds [8 x i8]* @.str, i32 0, i32 0
82
83 ; CHECK-NEXT: call i8* @__strcpy_chk
84   call i8* @__strcpy_chk(i8* %dst, i8* %src, i32 0)
85   ret void
86 }
87
88 declare i8* @__strcpy_chk(i8*, i8*, i32) nounwind