Sink common instructions are not always performance friendly. We need to implement hoist common instructions on switch instruction to solve the following problem:
define i1 @foo(i64 %a, i64 %b, i64 %c, i64 %d) {
start:
%test = icmp eq i64 %a, %d
br i1 %test, label %switch_bb, label %exit
switch_bb: ; preds = %start
switch i64 %a, label %bb0 [
i64 1, label %bb1
i64 2, label %bb2
]
bb0: ; preds = %switch_bb
%0 = icmp eq i64 %b, %c
br label %exit
bb1: ; preds = %switch_bb
%1 = icmp eq i64 %b, %c
br label %exit
bb2: ; preds = %switch_bb
%2 = icmp eq i64 %b, %c
br label %exit
exit: ; preds = %bb2, %bb1, %bb0, %start
%result = phi i1 [ false, %start ], [ %0, %bb0 ], [ %1, %bb1 ], [ %2, %bb2 ]
ret i1 %result
}The pre-commit test is D156617.