[llvm] [LVI][SCCP] Avoid copying ValueLatticeElement (PR #163901)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 17 00:49:56 PDT 2025


================
@@ -634,11 +634,11 @@ class SCCPInstVisitor : public InstVisitor<SCCPInstVisitor> {
   /// Merge \p MergeWithV into \p IV and push \p V to the worklist, if \p IV
   /// changes.
   bool mergeInValue(ValueLatticeElement &IV, Value *V,
-                    ValueLatticeElement MergeWithV,
+                    const ValueLatticeElement &MergeWithV,
                     ValueLatticeElement::MergeOptions Opts = {
                         /*MayIncludeUndef=*/false, /*CheckWiden=*/false});
 
-  bool mergeInValue(Value *V, ValueLatticeElement MergeWithV,
+  bool mergeInValue(Value *V, const ValueLatticeElement &MergeWithV,
----------------
nikic wrote:

I'm not sure this one is always safe. For example in https://github.com/dtcxzyw/llvm-project/blob/6a67889a728f410074d12ccfdf46bdf54bf9f56b/llvm/lib/Transforms/Utils/SCCPSolver.cpp#L1630 MergeWithV is the result of getValueState(). In that case ValueState[V] is known to be initialized already due to the previous `ValueState[&I].isOverdefined()` check, but it seems easy to cause reference invalidation here.

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


More information about the llvm-commits mailing list