|
| 1 | +;; This test comes from a real world scenario in LTO, where the |
| 2 | +;; definition of bcmp is deleted because it has no uses, but later instcombine |
| 3 | +;; re-introduces a call to bcmp() as part of SimplifyLibCalls. |
| 4 | + |
| 5 | +; RUN: opt %s -o %t -module-summary -mtriple riscv32-unknown-linux-musl |
| 6 | +; RUN: llvm-lto2 run -o %t2 \ |
| 7 | +; RUN: -r %t,foo,plx \ |
| 8 | +; RUN: -r %t,memcmp,x \ |
| 9 | +; RUN: -r %t,bcmp,pl %t -save-temps |
| 10 | +; RUN: llvm-dis %t2.1.2.internalize.bc -o - \ |
| 11 | +; RUN: | FileCheck %s --check-prefix=INTERNALIZE |
| 12 | +; RUN: opt %t2.1.2.internalize.bc -passes=instcombine -o - -S \ |
| 13 | +; RUN: | FileCheck %s --check-prefix=OPTIMIZE |
| 14 | + |
| 15 | +define i1 @foo(ptr %0, [2 x i32] %1) { |
| 16 | + ; OPTIMIZE-LABEL: define{{.*}}i1 @foo |
| 17 | + ; OPTIMIZE-NEXT: %size = extractvalue [2 x i32] %1, 1 |
| 18 | + ; OPTIMIZE-NEXT: %bcmp = {{.*}}call i32 @bcmp |
| 19 | + ; OPTIMIZE-NEXT: %eq = icmp eq i32 %bcmp, 0 |
| 20 | + ; OPTIMIZE-NEXT: ret i1 %eq |
| 21 | + |
| 22 | + %size = extractvalue [2 x i32] %1, 1 |
| 23 | + %cmp = call i32 @memcmp(ptr %0, ptr null, i32 %size) |
| 24 | + %eq = icmp eq i32 %cmp, 0 |
| 25 | + ret i1 %eq |
| 26 | +} |
| 27 | + |
| 28 | +; INTERNALIZE: declare i32 @memcmp(ptr, ptr, i32) |
| 29 | +declare i32 @memcmp(ptr, ptr, i32) |
| 30 | + |
| 31 | +;; Ensure bcmp is removed from module. Follow up patches can address this. |
| 32 | +; INTERNALIZE-NOT: declare{{.*}}i32 @bcmp |
| 33 | +; INTERNALIZE-NOT: define{{.*}}i32 @bcmp |
| 34 | +define i32 @bcmp(ptr %0, ptr %1, i32 %2) { |
| 35 | + ret i32 0 |
| 36 | +} |
| 37 | + |
0 commit comments