1 ; Test lib call simplification of __memset_chk calls with various values
4 ; RUN: opt < %s -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.T = type { [100 x i32], [100 x i32], [1024 x i8] }
10 @t = common global %struct.T zeroinitializer
12 ; Check cases where dstlen >= len.
14 define i8* @test_simplify1() {
15 ; CHECK-LABEL: @test_simplify1(
16 %dst = bitcast %struct.T* @t to i8*
18 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* bitcast (%struct.T* @t to i8*), i8 0, i64 1824, i32 4, i1 false)
19 ; CHECK-NEXT: ret i8* bitcast (%struct.T* @t to i8*)
20 %ret = call i8* @__memset_chk(i8* %dst, i32 0, i64 1824, i64 1824)
24 define i8* @test_simplify2() {
25 ; CHECK-LABEL: @test_simplify2(
26 %dst = bitcast %struct.T* @t to i8*
28 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* bitcast (%struct.T* @t to i8*), i8 0, i64 1824, i32 4, i1 false)
29 ; CHECK-NEXT: ret i8* bitcast (%struct.T* @t to i8*)
30 %ret = call i8* @__memset_chk(i8* %dst, i32 0, i64 1824, i64 3648)
34 define i8* @test_simplify3() {
35 ; CHECK-LABEL: @test_simplify3(
36 %dst = bitcast %struct.T* @t to i8*
38 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* bitcast (%struct.T* @t to i8*), i8 0, i64 1824, i32 4, i1 false)
39 ; CHECK-NEXT: ret i8* bitcast (%struct.T* @t to i8*)
40 %ret = call i8* @__memset_chk(i8* %dst, i32 0, i64 1824, i64 -1)
44 ; Check cases where dstlen < len.
46 define i8* @test_no_simplify1() {
47 ; CHECK-LABEL: @test_no_simplify1(
48 %dst = bitcast %struct.T* @t to i8*
50 ; CHECK-NEXT: %ret = call i8* @__memset_chk(i8* bitcast (%struct.T* @t to i8*), i32 0, i64 1824, i64 400)
51 ; CHECK-NEXT: ret i8* %ret
52 %ret = call i8* @__memset_chk(i8* %dst, i32 0, i64 1824, i64 400)
56 define i8* @test_no_simplify2() {
57 ; CHECK-LABEL: @test_no_simplify2(
58 %dst = bitcast %struct.T* @t to i8*
60 ; CHECK-NEXT: %ret = call i8* @__memset_chk(i8* bitcast (%struct.T* @t to i8*), i32 0, i64 1824, i64 0)
61 ; CHECK-NEXT: ret i8* %ret
62 %ret = call i8* @__memset_chk(i8* %dst, i32 0, i64 1824, i64 0)
66 declare i8* @__memset_chk(i8*, i32, i64, i64)