1 ; Test lib call simplification of __memset_chk calls with various values 2 ; for dstlen and len. 3 ; 4 ; RUN: opt < %s -instcombine -S | FileCheck %s 5 ; rdar://7719085 6 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" 8 9 %struct.T = type { [100 x i32], [100 x i32], [1024 x i8] } 10 @t = common global %struct.T zeroinitializer 11 12 ; Check cases where dstlen >= len. 13 14 define void @test_simplify1() { 15 ; CHECK-LABEL: @test_simplify1( 16 %dst = bitcast %struct.T* @t to i8* 17 18 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64 19 call i8* @__memset_chk(i8* %dst, i32 0, i64 1824, i64 1824) 20 ret void 21 } 22 23 define void @test_simplify2() { 24 ; CHECK-LABEL: @test_simplify2( 25 %dst = bitcast %struct.T* @t to i8* 26 27 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64 28 call i8* @__memset_chk(i8* %dst, i32 0, i64 1824, i64 3648) 29 ret void 30 } 31 32 define void @test_simplify3() { 33 ; CHECK-LABEL: @test_simplify3( 34 %dst = bitcast %struct.T* @t to i8* 35 36 ; CHECK-NEXT: call void @llvm.memset.p0i8.i64 37 call i8* @__memset_chk(i8* %dst, i32 0, i64 1824, i64 -1) 38 ret void 39 } 40 41 ; Check cases where dstlen < len. 42 43 define void @test_no_simplify1() { 44 ; CHECK-LABEL: @test_no_simplify1( 45 %dst = bitcast %struct.T* @t to i8* 46 47 ; CHECK-NEXT: call i8* @__memset_chk 48 call i8* @__memset_chk(i8* %dst, i32 0, i64 1824, i64 400) 49 ret void 50 } 51 52 define void @test_no_simplify2() { 53 ; CHECK-LABEL: @test_no_simplify2( 54 %dst = bitcast %struct.T* @t to i8* 55 56 ; CHECK-NEXT: call i8* @__memset_chk 57 call i8* @__memset_chk(i8* %dst, i32 0, i64 1824, i64 0) 58 ret void 59 } 60 61 declare i8* @__memset_chk(i8*, i32, i64, i64) 62