Skip to content

Commit 295e346

Browse files
author
Eli Friedman
committedJan 15, 2019
[EarlyIfConversion] Don't if-convert unconditional branches.
A block ending in an unconditional branch can have two successors if one is a landing pad. In practice, I think this only has an effect on Windows because landing pads are never empty for Itanium unwinding. (Alternatively, I could add a check to AArch64InstrInfo::canInsertSelect, but this seems more obvious.) Differential Revision: https://reviews.llvm.org/D56468 llvm-svn: 351142
1 parent 33aecc8 commit 295e346

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
 

‎llvm/lib/CodeGen/EarlyIfConversion.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,13 @@ bool SSAIfConv::canConvertIf(MachineBasicBlock *MBB) {
398398
return false;
399399
}
400400

401+
// Make sure the analyzed branch is conditional; one of the successors
402+
// could be a landing pad. (Empty landing pads can be generated on Windows.)
403+
if (Cond.empty()) {
404+
LLVM_DEBUG(dbgs() << "AnalyzeBranch found an unconditional branch.\n");
405+
return false;
406+
}
407+
401408
// AnalyzeBranch doesn't set FBB on a fall-through branch.
402409
// Make sure it is always set.
403410
FBB = TBB == Succ0 ? Succ1 : Succ0;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
; RUN: llc < %s | FileCheck %s
2+
3+
; Make sure this doesn't crash (and the output is sane).
4+
; CHECK: ; %__except.ret
5+
; CHECK-NEXT: mov x0, xzr
6+
7+
target datalayout = "e-m:w-p:64:64-i32:32-i64:64-i128:128-n32:64-S128"
8+
target triple = "aarch64-pc-windows-msvc19.11.0"
9+
10+
define i64 @f(i32* %hwnd, i32 %message, i64 %wparam, i64 %lparam) personality i8* bitcast (i32 (...)* @__C_specific_handler to i8*) {
11+
entry:
12+
%call = invoke i64 @callee(i32* %hwnd, i32 %message, i64 %wparam, i64 %lparam)
13+
to label %__try.cont unwind label %catch.dispatch
14+
15+
catch.dispatch: ; preds = %entry
16+
%0 = catchswitch within none [label %__except.ret] unwind to caller
17+
18+
__except.ret: ; preds = %catch.dispatch
19+
%1 = catchpad within %0 [i8* bitcast (i32 (i8*, i8*)* @filt to i8*)]
20+
catchret from %1 to label %__try.cont
21+
22+
__try.cont: ; preds = %__except.ret, %entry
23+
%rv.0 = phi i64 [ 0, %__except.ret ], [ %call, %entry ]
24+
ret i64 %rv.0
25+
}
26+
27+
declare dso_local i64 @callee(i32*, i32, i64, i64)
28+
declare i32 @filt(i8*, i8* nocapture readnone)
29+
declare dso_local i32 @__C_specific_handler(...)

0 commit comments

Comments
 (0)