[CodeGenPrep] Skip merging empty case blocks
This is recommit of r287553 after fixing the invalid loop info after eliminating an empty block and unit test failures in AVR and WebAssembly :
Summary: Merging an empty case block into the header block of switch could cause ISel to add COPY instructions in the header of switch, instead of the case block, if the case block is used as an incoming block of a PHI. This could potentially increase dynamic instructions, especially when the switch is in a loop. I added a test case which was reduced from the benchmark I was targetting.
Reviewers: t.p.northover, mcrosier, manmanren, wmi, joerg, davidxl
Subscribers: joerg, qcolombet, danielcdh, hfinkel, mcrosier, llvm-commits
Differential Revision: https://reviews.llvm.org/D22696
llvm-svn: 289988
2016-12-17 04:38:39 +08:00
|
|
|
; RUN: llc -march=avr -print-after=expand-isel-pseudos -cgp-freq-ratio-to-skip-merge=10 < %s 2>&1 | FileCheck %s
|
2016-11-10 07:46:52 +08:00
|
|
|
|
|
|
|
; Because `switch` seems to trigger Machine Basic Blocks to be ordered
|
|
|
|
; in a different order than they were constructed, this exposes an
|
|
|
|
; error in the `expand-isel-pseudos` pass. Specifically, it thought we
|
|
|
|
; could always fallthrough to a newly-constructed MBB. However,
|
|
|
|
; there's no guarantee that either of the constructed MBBs need to
|
|
|
|
; occur immediately after the currently-focused one!
|
|
|
|
;
|
|
|
|
; This issue manifests in a CFG that looks something like this:
|
|
|
|
;
|
2018-02-08 13:02:00 +08:00
|
|
|
; %bb.2.finish:
|
2017-12-05 01:18:51 +08:00
|
|
|
; Predecessors according to CFG: %bb.0 %bb.1
|
2017-12-07 18:40:31 +08:00
|
|
|
; %0 = PHI %3, <%bb.0>, %5, <%bb.1>
|
|
|
|
; %7 = LDIRdK 2
|
|
|
|
; %8 = LDIRdK 1
|
|
|
|
; CPRdRr %2, %0, implicit-def %SREG
|
|
|
|
; BREQk <%bb.6>, implicit %SREG
|
2017-12-05 01:18:51 +08:00
|
|
|
; Successors according to CFG: %bb.5(?%) %bb.6(?%)
|
2016-11-10 07:46:52 +08:00
|
|
|
;
|
2017-12-05 01:18:51 +08:00
|
|
|
; The code assumes it the fallthrough block after this is %bb.5, but
|
|
|
|
; it's actually %bb.3! To be proper, there should be an unconditional
|
|
|
|
; jump tying this block to %bb.5.
|
2016-11-10 07:46:52 +08:00
|
|
|
|
|
|
|
define i8 @select_must_add_unconditional_jump(i8 %arg0, i8 %arg1) unnamed_addr {
|
|
|
|
entry-block:
|
|
|
|
switch i8 %arg0, label %dead [
|
|
|
|
i8 0, label %zero
|
|
|
|
i8 1, label %one
|
|
|
|
]
|
|
|
|
|
|
|
|
zero:
|
|
|
|
br label %finish
|
|
|
|
|
|
|
|
one:
|
|
|
|
br label %finish
|
|
|
|
|
|
|
|
finish:
|
|
|
|
%predicate = phi i8 [ 50, %zero ], [ 100, %one ]
|
|
|
|
%is_eq = icmp eq i8 %arg1, %predicate
|
|
|
|
%result = select i1 %is_eq, i8 1, i8 2
|
|
|
|
ret i8 %result
|
|
|
|
|
|
|
|
dead:
|
|
|
|
ret i8 0
|
|
|
|
}
|
|
|
|
|
|
|
|
; This check may be a bit brittle, but the important thing is that the
|
|
|
|
; basic block containing `select` needs to contain explicit jumps to
|
|
|
|
; both successors.
|
|
|
|
|
2018-02-08 13:02:00 +08:00
|
|
|
; CHECK: %bb.2.finish:
|
2017-12-09 15:51:43 +08:00
|
|
|
; CHECK: BREQk [[BRANCHED:%bb.[0-9]+]]
|
|
|
|
; CHECK: RJMPk [[DIRECT:%bb.[0-9]+]]
|
2016-11-10 07:46:52 +08:00
|
|
|
; CHECK: Successors according to CFG
|
|
|
|
; CHECK-SAME-DAG: {{.*}}[[BRANCHED]]
|
|
|
|
; CHECK-SAME-DAG: {{.*}}[[DIRECT]]
|
2018-02-08 13:02:00 +08:00
|
|
|
; CHECK: %bb.3.dead:
|