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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 17 13:08:46 PDT 2025


================
@@ -1627,7 +1619,10 @@ void SCCPInstVisitor::visitSelectInst(SelectInst &I) {
   if (ConstantInt *CondCB =
           getConstantInt(CondValue, I.getCondition()->getType())) {
     Value *OpVal = CondCB->isZero() ? I.getFalseValue() : I.getTrueValue();
-    mergeInValue(&I, getValueState(OpVal));
+    const ValueLatticeElement &OpValState = getValueState(OpVal);
+    // Safety: ValueState[&I] doesn't invalidate OpValState since it is already
+    // in the map.
+    mergeInValue(ValueState[&I], &I, OpValState);
----------------
nikic wrote:

It's unfortunate that `ValueState.at(&I)` returns a const reference, otherwise we could use that to assert existence.

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


More information about the llvm-commits mailing list