1 ; Test that the StpCpyOptimizer works correctly 2 ; RUN: opt < %s -simplify-libcalls -S | FileCheck %s 3 4 ; This transformation requires the pointer size, as it assumes that size_t is 5 ; the size of a pointer. 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-n8:16:32" 7 8 @hello = constant [6 x i8] c"hello\00" 9 10 declare i8* @stpcpy(i8*, i8*) 11 12 declare i8* @__stpcpy_chk(i8*, i8*, i32) nounwind 13 14 declare i32 @llvm.objectsize.i32(i8*, i1) nounwind readonly 15 16 define i32 @t1() { 17 ; CHECK: @t1 18 %target = alloca [1024 x i8] 19 %arg1 = getelementptr [1024 x i8]* %target, i32 0, i32 0 20 %arg2 = getelementptr [6 x i8]* @hello, i32 0, i32 0 21 %rslt1 = call i8* @stpcpy( i8* %arg1, i8* %arg2 ) 22 ; CHECK: @llvm.memcpy.p0i8.p0i8.i32 23 ret i32 0 24 } 25 26 define i32 @t2() { 27 ; CHECK: @t2 28 %target = alloca [1024 x i8] 29 %arg1 = getelementptr [1024 x i8]* %target, i32 0, i32 0 30 %arg2 = getelementptr [6 x i8]* @hello, i32 0, i32 0 31 %tmp1 = call i32 @llvm.objectsize.i32(i8* %arg1, i1 false) 32 %rslt1 = call i8* @__stpcpy_chk(i8* %arg1, i8* %arg2, i32 %tmp1) 33 ; CHECK: @__memcpy_chk 34 ret i32 0 35 } 36 37 define i8* @t3(i8* %arg) { 38 ; CHECK: @t3 39 %stpcpy = tail call i8* @stpcpy(i8* %arg, i8* %arg) 40 ; CHECK: [[LEN:%[a-z]+]] = call i32 @strlen(i8* %arg) 41 ; CHECK-NEXT: getelementptr inbounds i8* %arg, i32 [[LEN]] 42 ret i8* %stpcpy 43 } 44