[llvm] [DFAJumpThreading] Do not thread over blocks with multiple phi definitions (PR #195512)
Hongyu Chen via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 15 02:20:04 PDT 2026
================
@@ -765,8 +767,12 @@ struct AllSwitchPaths {
while (!Stack.empty()) {
PHINode *CurPhi = Stack.pop_back_val();
+ BasicBlock *CurDefBlock = CurPhi->getParent();
+
+ auto [_, Inserted] = Res.try_emplace(CurDefBlock, CurPhi);
+ if (!Inserted)
+ MultipleDefBBs.insert(CurDefBlock);
- Res[CurPhi->getParent()] = CurPhi;
SeenValues.insert(CurPhi);
for (BasicBlock *IncomingBB : CurPhi->blocks()) {
----------------
XChy wrote:
I thought that there may be a miscompilation risk if we do not add blocks with multiple definitions to the stack. As the case below shows, if we do not add `multiple_defs_bb2` to the stack, we cannot see that another definition flows from `multiple_defs_bb1` to `multiple_defs_bb2`. In this case, `multiple_defs_bb1` is considered a block with a single definition instead of multiple definitions.
```
multiple_defs_bb1
| \
| \
bb multiple_defs_bb2
| /
| /
switch_bb
```
https://github.com/llvm/llvm-project/pull/195512
More information about the llvm-commits
mailing list