diff options
author | Davide Italiano <davide@freebsd.org> | 2017-12-31 16:47:16 +0000 |
---|---|---|
committer | Davide Italiano <davide@freebsd.org> | 2017-12-31 16:47:16 +0000 |
commit | 9f074fe915c35e352962cfdc9a253b2985a64c9e (patch) | |
tree | c2a8dce8cc7e4673991d9a230261376293b7560f /llvm/lib/Transforms/Utils | |
parent | f0f6eefb49f3f779def8201ac0cddfc05561d740 (diff) | |
download | bcm5719-llvm-9f074fe915c35e352962cfdc9a253b2985a64c9e.tar.gz bcm5719-llvm-9f074fe915c35e352962cfdc9a253b2985a64c9e.zip |
[SimplifyCFG] Stop hoisting musttail calls incorrectly.
PR35774.
llvm-svn: 321603
Diffstat (limited to 'llvm/lib/Transforms/Utils')
-rw-r--r-- | llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 58f1e8008ea..5d5300368cc 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1276,6 +1276,17 @@ static bool HoistThenElseCodeToIf(BranchInst *BI, if (isa<TerminatorInst>(I1)) goto HoistTerminator; + // If we're going to hoist a call, make sure that the two instructions we're + // commoning/hoisting are both marked with musttail, or neither of them is + // marked as such. Otherwise, we might end up in a situation where we hoist + // from a block where the terminator is a `ret` to a block where the terminator + // is a `br`, and `musttail` calls expect to be followed by a return. + auto *C1 = dyn_cast<CallInst>(I1); + auto *C2 = dyn_cast<CallInst>(I2); + if (C1 && C2) + if (C1->isMustTailCall() != C2->isMustTailCall()) + return false; + if (!TTI.isProfitableToHoist(I1) || !TTI.isProfitableToHoist(I2)) return Changed; |