From 4fba35f973d2305b19965fd8ebe47bf742a01b8e Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 18 Jul 2022 12:01:12 +0200 Subject: [PATCH] [InstCombine] Clarify invoke/callbr handling in constexpr call fold (NFCI) We only need to check the block for the normal/default destination, not for other destinations. Using the value in those would be illegal anyway. The callbr case cannot actually happen here, because callbr is currently limited to inline asm. Retaining it to match the spirit of the original code. --- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index edfdf70..741725d 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -3242,15 +3242,16 @@ bool InstCombinerImpl::transformConstExprCastCall(CallBase &Call) { // the call because there is no place to put the cast instruction (without // breaking the critical edge). Bail out in this case. if (!Caller->use_empty()) { - if (InvokeInst *II = dyn_cast(Caller)) - for (User *U : II->users()) + BasicBlock *PhisNotSupportedBlock = nullptr; + if (auto *II = dyn_cast(Caller)) + PhisNotSupportedBlock = II->getNormalDest(); + if (auto *CB = dyn_cast(Caller)) + PhisNotSupportedBlock = CB->getDefaultDest(); + if (PhisNotSupportedBlock) + for (User *U : Caller->users()) if (PHINode *PN = dyn_cast(U)) - if (PN->getParent() == II->getNormalDest() || - PN->getParent() == II->getUnwindDest()) + if (PN->getParent() == PhisNotSupportedBlock) return false; - // FIXME: Be conservative for callbr to avoid a quadratic search. - if (isa(Caller)) - return false; } } -- 2.7.4