[llvm] [InstCombine] Enable select freeze poison folding when storing value (PR #129776)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 6 21:15:04 PST 2025


================
@@ -4812,16 +4812,21 @@ Instruction *InstCombinerImpl::visitFreeze(FreezeInst &I) {
   //
   // TODO: This could use getBinopAbsorber() / getBinopIdentity() to avoid
   //       duplicating logic for binops at least.
-  auto getUndefReplacement = [&I](Type *Ty) {
-    Constant *BestValue = nullptr;
-    Constant *NullValue = Constant::getNullValue(Ty);
+  auto getUndefReplacement = [&I, &AC = this->AC, &DT = this->DT](Type *Ty) {
+    Value *SelectArgument = nullptr;
+    if (I.hasOneUse() &&
+        match(I.user_back(),
+              m_c_Select(m_Specific(&I), m_Value(SelectArgument))) &&
+        isGuaranteedNotToBeUndefOrPoison(SelectArgument, &AC, &I, &DT))
+      return SelectArgument;
+    Value *BestValue = nullptr;
+    Value *NullValue = Constant::getNullValue(Ty);
----------------
dtcxzyw wrote:

```suggestion
    Constant *BestValue = nullptr;
    Constant *NullValue = Constant::getNullValue(Ty);
```

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


More information about the llvm-commits mailing list