brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.4 KiB · bf54fb2 Raw
68 lines · plain
1; RUN: opt -S %s -passes=deadargelim -o - | FileCheck %s2; In that test @internal_fct is used by an instruction3; we don't know how to rewrite (the comparison that produces4; %cmp1).5; Because of that use, we used to bail out on removing the6; unused arguments for this function.7; Yet, we should still be able to rewrite the direct calls that are8; 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_fct14; 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_fct20; 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_fct32  br i1 %cmp0, label %call_ext, label %chk233 34call_ext:35  %res1 = tail call i32 @external_fct(i32 %arg1, i32 %arg2, i32 %arg3)36  br label %end37 38chk2:39  %cmp1 = icmp eq ptr %fct_ptr, @internal_fct40  br i1 %cmp1, label %call_int, label %call_other41 42call_int:43  %res2 = tail call i32 @internal_fct(i32 %arg1, i32 %arg2, i32 %arg3)44  br label %end45 46call_other:47  %res3 = tail call i32 @other_fct(i32 %arg1, i32 %arg2, i32 %arg3)48  br label %end49 50end:51  %final_res = phi i32 [%res1, %call_ext], [%res2, %call_int], [%res3, %call_other]52  ret i32 %final_res53}54 55 56define i32 @external_fct(i32 %unused_arg1, i32 %arg2, i32 %unused_arg3) {57  ret i32 %arg258}59 60define internal i32 @internal_fct(i32 %unused_arg1, i32 %arg2, i32 %unused_arg3) {61  ret i32 %arg262}63 64define internal i32 @other_fct(i32 %unused_arg1, i32 %arg2, i32 %unused_arg3) {65  ret i32 %arg266}67 68