[llvm] [DFAJumpThreading] Unfold select to the incoming block of phi user (PR #160987)

Hongyu Chen via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 1 01:33:55 PDT 2025


================
@@ -190,12 +190,12 @@ void unfold(DomTreeUpdater *DTU, LoopInfo *LI, SelectInstToUnfold SIToUnfold,
             std::vector<BasicBlock *> *NewBBs) {
   SelectInst *SI = SIToUnfold.getInst();
   PHINode *SIUse = SIToUnfold.getUse();
-  BasicBlock *StartBlock = SI->getParent();
+  assert(SI->hasOneUse());
+  // The select may come indirectly, instead of from where it is defined.
+  BasicBlock *StartBlock = SIUse->getIncomingBlock(SI->user_begin().getUse());
----------------
XChy wrote:

Non-const user iterator causes compilation error:
>  error: no matching function for call to ‘llvm::Value::user_iterator_impl<const llvm::User>::user_iterator_impl(llvm::Use&)’

The alternative is `const_cast<const SelectInst *>(SI)->user_begin()`, but it looks more complicated to me.

https://github.com/llvm/llvm-project/pull/160987


More information about the llvm-commits mailing list