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 4; %cmp1). 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. 10 11define 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:%.*]] 15; CHECK: call_ext: 16; CHECK-NEXT: [[RES1:%.*]] = tail call i32 @external_fct(i32 poison, i32 [[ARG2:%.*]], i32 poison) 17; CHECK-NEXT: br label [[END:%.*]] 18; CHECK: chk2: 19; CHECK-NEXT: [[CMP1:%.*]] = icmp eq ptr [[FCT_PTR]], @internal_fct 20; CHECK-NEXT: br i1 [[CMP1]], label [[CALL_INT:%.*]], label [[CALL_OTHER:%.*]] 21; CHECK: call_int: 22; CHECK-NEXT: [[RES2:%.*]] = tail call i32 @internal_fct(i32 poison, i32 [[ARG2]], i32 poison) 23; CHECK-NEXT: br label [[END]] 24; CHECK: call_other: 25; CHECK-NEXT: [[RES3:%.*]] = tail call i32 @other_fct(i32 [[ARG2]]) 26; CHECK-NEXT: br label [[END]] 27; CHECK: end: 28; CHECK-NEXT: [[FINAL_RES:%.*]] = phi i32 [ [[RES1]], [[CALL_EXT]] ], [ [[RES2]], [[CALL_INT]] ], [ [[RES3]], [[CALL_OTHER]] ] 29; CHECK-NEXT: ret i32 [[FINAL_RES]] 30; 31 %cmp0 = icmp eq ptr %fct_ptr, @external_fct 32 br i1 %cmp0, label %call_ext, label %chk2 33 34call_ext: 35 %res1 = tail call i32 @external_fct(i32 %arg1, i32 %arg2, i32 %arg3) 36 br label %end 37 38chk2: 39 %cmp1 = icmp eq ptr %fct_ptr, @internal_fct 40 br i1 %cmp1, label %call_int, label %call_other 41 42call_int: 43 %res2 = tail call i32 @internal_fct(i32 %arg1, i32 %arg2, i32 %arg3) 44 br label %end 45 46call_other: 47 %res3 = tail call i32 @other_fct(i32 %arg1, i32 %arg2, i32 %arg3) 48 br label %end 49 50end: 51 %final_res = phi i32 [%res1, %call_ext], [%res2, %call_int], [%res3, %call_other] 52 ret i32 %final_res 53} 54 55 56define i32 @external_fct(i32 %unused_arg1, i32 %arg2, i32 %unused_arg3) { 57 ret i32 %arg2 58} 59 60define internal i32 @internal_fct(i32 %unused_arg1, i32 %arg2, i32 %unused_arg3) { 61 ret i32 %arg2 62} 63 64define internal i32 @other_fct(i32 %unused_arg1, i32 %arg2, i32 %unused_arg3) { 65 ret i32 %arg2 66} 67 68