1; Make sure that the CGSCC pass manager can handle when instcombine simplifies 2; one libcall into an unrelated libcall and update the call graph accordingly. 3; 4; Also check that it can handle inlining *removing* a libcall entirely. 5; 6; Finally, we include some recursive patterns and forced analysis invaliadtion 7; that can trigger infinite CGSCC refinement if not handled correctly. 8; 9; RUN: opt -passes='cgscc(inline,function(instcombine,invalidate<all>))' -S < %s | FileCheck %s 10 11define i8* @wibble(i8* %arg1, i8* %arg2) { 12; CHECK-LABEL: define i8* @wibble( 13bb: 14 %tmp = alloca [1024 x i8], align 16 15 %tmp2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %tmp, i64 0, i64 0 16 call void @llvm.memcpy.p0i8.p0i8.i64(i8* %tmp2, i8* %arg1, i64 1024, i1 false) 17; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 16 dereferenceable(1024) 18 %tmp3 = call i64 @llvm.objectsize.i64.p0i8(i8* %tmp2, i1 false, i1 true, i1 false) 19 %tmp4 = call i8* @__strncpy_chk(i8* %arg2, i8* %tmp2, i64 1023, i64 %tmp3) 20; CHECK-NOT: call 21; CHECK: call i8* @strncpy(i8* nonnull dereferenceable(1) %arg2, i8* nonnull dereferenceable(1) %tmp2, i64 1023) 22 23; CHECK-NOT: call 24 25 ret i8* %tmp4 26; CHECK: ret 27} 28 29define i8* @strncpy(i8* %arg1, i8* %arg2, i64 %size) noinline { 30bb: 31; CHECK: call i8* @my_special_strncpy(i8* %arg1, i8* %arg2, i64 %size) 32 %result = call i8* @my_special_strncpy(i8* %arg1, i8* %arg2, i64 %size) 33 ret i8* %result 34} 35 36declare i8* @my_special_strncpy(i8* %arg1, i8* %arg2, i64 %size) 37 38declare i64 @llvm.objectsize.i64.p0i8(i8*, i1, i1, i1) 39 40declare i8* @__strncpy_chk(i8*, i8*, i64, i64) 41 42declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture writeonly, i8* nocapture readonly, i64, i1) 43 44; Check that even when we completely remove a libcall we don't get the call 45; graph wrong once we handle libcalls in the call graph specially to address 46; the above case. 47define i32 @hoge(i32* %arg1) { 48; CHECK-LABEL: define i32 @hoge( 49bb: 50 %tmp41 = load i32*, i32** null 51 %tmp6 = load i32, i32* %arg1 52 %tmp7 = call i32 @ntohl(i32 %tmp6) 53; CHECK-NOT: call i32 @ntohl 54 ret i32 %tmp7 55; CHECK: ret i32 56} 57 58; Even though this function is not used, it should be retained as it may be 59; used when doing further libcall transformations. 60define internal i32 @ntohl(i32 %x) { 61; CHECK-LABEL: define internal i32 @ntohl( 62entry: 63 %and2 = lshr i32 %x, 8 64 %shr = and i32 %and2, 65280 65 ret i32 %shr 66} 67 68define i64 @write(i32 %i, i8* %p, i64 %j) { 69entry: 70 %val = call i64 @write_wrapper(i32 %i, i8* %p, i64 %j) noinline 71 ret i64 %val 72} 73 74define i64 @write_wrapper(i32 %i, i8* %p, i64 %j) { 75entry: 76 %val = call i64 @write(i32 %i, i8* %p, i64 %j) noinline 77 ret i64 %val 78} 79