[PATCH] D146415: [LSR]: Fix cast to BranchInst.

EverRest via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 20 04:31:55 PDT 2023


MarkGoncharovAl created this revision.
MarkGoncharovAl added reviewers: eopXD, nikic, reames.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
MarkGoncharovAl requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

getTerminator() returns Instruction*.
So, some tests (spec2006.483.xalancbmk) fail with SegFault, because we should cast more carefully.

Also, TODO is already implemented.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146415

Files:
  llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp


Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -6701,11 +6701,12 @@
 
   BasicBlock *LoopLatch = L->getLoopLatch();
 
-  // TODO: Can we do something for greater than and less than?
-  // Terminating condition is foldable when it is an eq/ne icmp
-  BranchInst *BI = cast<BranchInst>(LoopLatch->getTerminator());
-  if (BI->isUnconditional())
+  BranchInst *BI = dyn_cast<BranchInst>(LoopLatch->getTerminator());
+  if (!BI || BI->isUnconditional()) {
+    LLVM_DEBUG(dbgs() << "Cannot fold terminator that is not a conditional "
+                         "branch instruction")
     return std::nullopt;
+  }
   auto *TermCond = dyn_cast<ICmpInst>(BI->getCondition());
   if (!TermCond) {
     LLVM_DEBUG(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146415.506539.patch
Type: text/x-patch
Size: 895 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230320/da554342/attachment.bin>


More information about the llvm-commits mailing list