[llvm] [InstCombinePHI] Enhance PHI CSE to remove redundant phis (PR #163453)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 18 02:49:46 PDT 2025
https://github.com/dtcxzyw commented:
I find that it is more natural to handle this pattern in `simplifySelectInst`:
```
bool isSimplifierIdenticalPHI(PHINode &PHI, PHINode &IdenticalPHI) {
if (PHI.getParent() != IdenticalPHI.getParent())
return false;
// Check incoming values
...
// Check next values
...
}
Value *simplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal,
const SimplifyQuery &Q, unsigned MaxRecurse) {
...
if (auto *TruePHI = dyn_cast<PHINode>(TrueVal)) {
if (auto *FalsePHI = dyn_cast<PHINode>(FalseVal)) {
if (isSimplifierIdenticalPHI(*TruePHI, *FalsePHI))
return FalseVal;
if (isSimplifierIdenticalPHI(*TruePHI, *FalsePHI))
return FalseVal;
if (isSimplifierIdenticalPHI(*FalsePHI, *TruePHI))
return TrueVal;
}
}
return nullptr;
}
```
https://github.com/llvm/llvm-project/pull/163453
More information about the llvm-commits
mailing list