[llvm] [InstCombine] Support well-defined recurrences in isGuaranteedNotToBeUndefOrPoison (PR #150420)

David Sherwood via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 31 05:41:19 PDT 2025


================
@@ -7657,6 +7720,13 @@ static bool isGuaranteedNotToBeUndefOrPoison(
       }
       if (IsWellDefined)
         return true;
+
+      bool StartNeedsFreeze;
+      if (canFoldFreezeIntoRecurrence(
+              const_cast<PHINode *>(PN), const_cast<DominatorTree *>(DT),
----------------
david-arm wrote:

I tried marking DominatorTree as const and it seemed to work for me, although I agree it's hard to avoid the `const_cast` for the PHI node. However, I guess it's fine in this case because we're ignoring the result and we're not going to drop any flags. I see there are existing uses of const_cast elsewhere in ValueTracking.cpp too.

Can you update the interface to just mark the DominatorTree argument as const then?

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


More information about the llvm-commits mailing list