[llvm] [InstCombine] Opt phi(freeze(undef), C) -> phi(C, C) (PR #161181)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 30 09:09:48 PDT 2025
================
@@ -5179,9 +5180,35 @@ Instruction *InstCombinerImpl::visitFreeze(FreezeInst &I) {
// TODO: This could use getBinopAbsorber() / getBinopIdentity() to avoid
// duplicating logic for binops at least.
auto getUndefReplacement = [&](Type *Ty) {
- Value *BestValue = nullptr;
+ auto pickCommonConstantFromPHI = [&](PHINode &PN) -> Value * {
+ // phi(freeze(undef), C, C). Choose C for freeze so the PHI can be
+ // removed.
+ Constant *BestValue = nullptr;
+ Constant *C = nullptr;
+ for (Value *V : PN.incoming_values()) {
+ if (match(V, m_Freeze(m_Undef())))
+ continue;
+
+ if (!isa<Constant>(V))
+ return nullptr;
+
+ if (!isGuaranteedNotToBeUndefOrPoison(V, &AC, &I, &DT))
----------------
dtcxzyw wrote:
```suggestion
if (!isGuaranteedNotToBeUndefOrPoison(V))
```
Context information is unused for constants.
https://github.com/llvm/llvm-project/pull/161181
More information about the llvm-commits
mailing list