[llvm] 4fba35f - [InstCombine] Clarify invoke/callbr handling in constexpr call fold (NFCI)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 18 03:03:33 PDT 2022


Author: Nikita Popov
Date: 2022-07-18T12:02:46+02:00
New Revision: 4fba35f973d2305b19965fd8ebe47bf742a01b8e

URL: https://github.com/llvm/llvm-project/commit/4fba35f973d2305b19965fd8ebe47bf742a01b8e
DIFF: https://github.com/llvm/llvm-project/commit/4fba35f973d2305b19965fd8ebe47bf742a01b8e.diff

LOG: [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.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index edfdf70c2b975..741725d226623 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<InvokeInst>(Caller))
-        for (User *U : II->users())
+      BasicBlock *PhisNotSupportedBlock = nullptr;
+      if (auto *II = dyn_cast<InvokeInst>(Caller))
+        PhisNotSupportedBlock = II->getNormalDest();
+      if (auto *CB = dyn_cast<CallBrInst>(Caller))
+        PhisNotSupportedBlock = CB->getDefaultDest();
+      if (PhisNotSupportedBlock)
+        for (User *U : Caller->users())
           if (PHINode *PN = dyn_cast<PHINode>(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<CallBrInst>(Caller))
-        return false;
     }
   }
 


        


More information about the llvm-commits mailing list