1 ; RUN: opt -S %s -passes=deadargelim -o - | FileCheck %s
2 ; In that test @internal_fct is used by an instruction
3 ; we don't know how to rewrite (the comparison that produces
5 ; Because of that use, we used to bail out on removing the
6 ; unused arguments for this function.
7 ; Yet, we should still be able to rewrite the direct calls that are
8 ; statically known, by replacing the related arguments with poison.
9 ; This is what we check on the call that produces %res2.
11 define i32 @call_indirect(ptr readnone %fct_ptr, i32 %arg1, i32 %arg2, i32 %arg3) {
12 ; CHECK-LABEL: @call_indirect(
13 ; CHECK-NEXT: [[CMP0:%.*]] = icmp eq ptr [[FCT_PTR:%.*]], @external_fct
14 ; CHECK-NEXT: br i1 [[CMP0]], label [[CALL_EXT:%.*]], label [[CHK2:%.*]]
16 ; CHECK-NEXT: [[RES1:%.*]] = tail call i32 @external_fct(i32 poison, i32 [[ARG2:%.*]], i32 poison)
17 ; CHECK-NEXT: br label [[END:%.*]]
19 ; CHECK-NEXT: [[CMP1:%.*]] = icmp eq ptr [[FCT_PTR]], @internal_fct
20 ; CHECK-NEXT: br i1 [[CMP1]], label [[CALL_INT:%.*]], label [[CALL_OTHER:%.*]]
22 ; CHECK-NEXT: [[RES2:%.*]] = tail call i32 @internal_fct(i32 poison, i32 [[ARG2]], i32 poison)
23 ; CHECK-NEXT: br label [[END]]
25 ; CHECK-NEXT: [[RES3:%.*]] = tail call i32 @other_fct(i32 [[ARG2]])
26 ; CHECK-NEXT: br label [[END]]
28 ; CHECK-NEXT: [[FINAL_RES:%.*]] = phi i32 [ [[RES1]], [[CALL_EXT]] ], [ [[RES2]], [[CALL_INT]] ], [ [[RES3]], [[CALL_OTHER]] ]
29 ; CHECK-NEXT: ret i32 [[FINAL_RES]]
31 %cmp0 = icmp eq ptr %fct_ptr, @external_fct
32 br i1 %cmp0, label %call_ext, label %chk2
35 %res1 = tail call i32 @external_fct(i32 %arg1, i32 %arg2, i32 %arg3)
39 %cmp1 = icmp eq ptr %fct_ptr, @internal_fct
40 br i1 %cmp1, label %call_int, label %call_other
43 %res2 = tail call i32 @internal_fct(i32 %arg1, i32 %arg2, i32 %arg3)
47 %res3 = tail call i32 @other_fct(i32 %arg1, i32 %arg2, i32 %arg3)
51 %final_res = phi i32 [%res1, %call_ext], [%res2, %call_int], [%res3, %call_other]
56 define i32 @external_fct(i32 %unused_arg1, i32 %arg2, i32 %unused_arg3) {
60 define internal i32 @internal_fct(i32 %unused_arg1, i32 %arg2, i32 %unused_arg3) {
64 define internal i32 @other_fct(i32 %unused_arg1, i32 %arg2, i32 %unused_arg3) {