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.
4 ; Also check that it can handle inlining *removing* a libcall entirely.
6 ; Finally, we include some recursive patterns and forced analysis invaliadtion
7 ; that can trigger infinite CGSCC refinement if not handled correctly.
9 ; RUN: opt -passes='cgscc(inline,function(instcombine,invalidate<all>))' -S < %s | FileCheck %s
11 define ptr @wibble(ptr %arg1, ptr %arg2) {
12 ; CHECK-LABEL: define ptr @wibble(
14 %tmp = alloca [1024 x i8], align 16
15 call void @llvm.memcpy.p0.p0.i64(ptr %tmp, ptr %arg1, i64 1024, i1 false)
16 ; CHECK: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 16 dereferenceable(1024)
17 %tmp3 = call i64 @llvm.objectsize.i64.p0(ptr %tmp, i1 false, i1 true, i1 false)
18 %tmp4 = call ptr @__strncpy_chk(ptr %arg2, ptr %tmp, i64 1023, i64 %tmp3)
20 ; CHECK: call ptr @strncpy(ptr noundef nonnull dereferenceable(1) %arg2, ptr noundef nonnull dereferenceable(1) %tmp, i64 1023)
28 define ptr @strncpy(ptr %arg1, ptr %arg2, i64 %size) noinline {
30 ; CHECK: call ptr @my_special_strncpy(ptr %arg1, ptr %arg2, i64 %size)
31 %result = call ptr @my_special_strncpy(ptr %arg1, ptr %arg2, i64 %size)
35 declare ptr @my_special_strncpy(ptr %arg1, ptr %arg2, i64 %size)
37 declare i64 @llvm.objectsize.i64.p0(ptr, i1, i1, i1)
39 declare ptr @__strncpy_chk(ptr, ptr, i64, i64)
41 declare void @llvm.memcpy.p0.p0.i64(ptr nocapture writeonly, ptr nocapture readonly, i64, i1)
43 ; Check that even when we completely remove a libcall we don't get the call
44 ; graph wrong once we handle libcalls in the call graph specially to address
46 define i32 @hoge(ptr %arg1) {
47 ; CHECK-LABEL: define i32 @hoge(
49 %tmp41 = load ptr, ptr null
50 %tmp6 = load i32, ptr %arg1
51 %tmp7 = call i32 @ntohl(i32 %tmp6)
52 ; CHECK-NOT: call i32 @ntohl
57 ; Even though this function is not used, it should be retained as it may be
58 ; used when doing further libcall transformations.
59 define internal i32 @ntohl(i32 %x) {
60 ; CHECK-LABEL: define internal i32 @ntohl(
62 %and2 = lshr i32 %x, 8
63 %shr = and i32 %and2, 65280
67 define i64 @write(i32 %i, ptr %p, i64 %j) {
69 %val = call i64 @write_wrapper(i32 %i, ptr %p, i64 %j) noinline
73 define i64 @write_wrapper(i32 %i, ptr %p, i64 %j) {
75 %val = call i64 @write(i32 %i, ptr %p, i64 %j) noinline