The NewDefault was used to simplify the updating of PHI nodes, but it
causes some inefficiency for target that will run structurizer later. For
example, for a simple two-case switch, the extra NewDefault is causing
unstructured CFG like:
O
/ \
O O
/ \ / \
C1 ND C2
\ | /
\ | /
D
The change is to avoid the ND(NewDefault) block, that is we will get a
structured CFG for above example like:
O
/ \
/ \
O O
/ \ / \
C1 \ / C2
\-> D <-/
The IR change introduced by this patch should be trivial to other targets,
so I am doing this unconditionally.
Fall-through among the cases will also cause unstructured CFG, but it need
more work and will be addressed in a separate change.
Reviewed by: arsenm
Differential Revision: https://reviews.llvm.org/D123607
68 lines
1.8 KiB
LLVM
68 lines
1.8 KiB
LLVM
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
|
|
; RUN: opt < %s -unify-loop-exits -enable-new-pm=0 -S | FileCheck %s
|
|
; RUN: opt < %s -passes='lowerswitch,unify-loop-exits' -S | FileCheck %s
|
|
|
|
define void @loop_1(i32 %Value, i1 %PredEntry, i1 %PredD) {
|
|
; CHECK-LABEL: @loop_1(
|
|
; CHECK-NEXT: entry:
|
|
; CHECK-NEXT: br i1 [[PREDENTRY:%.*]], label [[A:%.*]], label [[G:%.*]]
|
|
; CHECK: A:
|
|
; CHECK-NEXT: br label [[B:%.*]]
|
|
; CHECK: B:
|
|
; CHECK-NEXT: br label [[NODEBLOCK:%.*]]
|
|
; CHECK: NodeBlock:
|
|
; CHECK-NEXT: [[PIVOT:%.*]] = icmp slt i32 [[VALUE:%.*]], 1
|
|
; CHECK-NEXT: br i1 [[PIVOT]], label [[LEAFBLOCK:%.*]], label [[LEAFBLOCK1:%.*]]
|
|
; CHECK: LeafBlock1:
|
|
; CHECK-NEXT: [[SWITCHLEAF2:%.*]] = icmp eq i32 [[VALUE]], 1
|
|
; CHECK-NEXT: br i1 [[SWITCHLEAF2]], label [[D:%.*]], label [[LOOP_EXIT_GUARD:%.*]]
|
|
; CHECK: LeafBlock:
|
|
; CHECK-NEXT: [[SWITCHLEAF:%.*]] = icmp eq i32 [[VALUE]], 0
|
|
; CHECK-NEXT: br i1 [[SWITCHLEAF]], label [[C:%.*]], label [[LOOP_EXIT_GUARD]]
|
|
; CHECK: C:
|
|
; CHECK-NEXT: br label [[D]]
|
|
; CHECK: D:
|
|
; CHECK-NEXT: br i1 [[PREDD:%.*]], label [[A]], label [[LOOP_EXIT_GUARD]]
|
|
; CHECK: X:
|
|
; CHECK-NEXT: br label [[EXIT:%.*]]
|
|
; CHECK: Y:
|
|
; CHECK-NEXT: br label [[EXIT]]
|
|
; CHECK: G:
|
|
; CHECK-NEXT: br label [[EXIT]]
|
|
; CHECK: exit:
|
|
; CHECK-NEXT: ret void
|
|
; CHECK: loop.exit.guard:
|
|
; CHECK-NEXT: [[GUARD_X:%.*]] = phi i1 [ true, [[LEAFBLOCK1]] ], [ true, [[LEAFBLOCK]] ], [ false, [[D]] ]
|
|
; CHECK-NEXT: br i1 [[GUARD_X]], label [[X:%.*]], label [[Y:%.*]]
|
|
;
|
|
entry:
|
|
br i1 %PredEntry, label %A, label %G
|
|
|
|
A:
|
|
br label %B
|
|
|
|
B:
|
|
switch i32 %Value, label %X [
|
|
i32 0, label %C
|
|
i32 1, label %D
|
|
]
|
|
|
|
C:
|
|
br label %D
|
|
|
|
D:
|
|
br i1 %PredD, label %A, label %Y
|
|
|
|
X:
|
|
br label %exit
|
|
|
|
Y:
|
|
br label %exit
|
|
|
|
G:
|
|
br label %exit
|
|
|
|
exit:
|
|
ret void
|
|
}
|