@@ -638,14 +638,6 @@ class SCCPInstVisitor : public InstVisitor<SCCPInstVisitor> {
638638 ValueLatticeElement::MergeOptions Opts = {
639639 /* MayIncludeUndef=*/ false , /* CheckWiden=*/ false });
640640
641- bool mergeInValue (Value *V, const ValueLatticeElement &MergeWithV,
642- ValueLatticeElement::MergeOptions Opts = {
643- /* MayIncludeUndef=*/ false , /* CheckWiden=*/ false }) {
644- assert (!V->getType ()->isStructTy () &&
645- " non-structs should use markConstant" );
646- return mergeInValue (ValueState[V], V, MergeWithV, Opts);
647- }
648-
649641 // / getValueState - Return the ValueLatticeElement object that corresponds to
650642 // / the value. This function handles the case when the value hasn't been seen
651643 // / yet by properly seeding constants etc.
@@ -987,7 +979,7 @@ class SCCPInstVisitor : public InstVisitor<SCCPInstVisitor> {
987979 void trackValueOfArgument (Argument *A) {
988980 if (A->getType ()->isStructTy ())
989981 return (void )markOverdefined (A);
990- mergeInValue (A, getArgAttributeVL (A));
982+ mergeInValue (ValueState[A], A, getArgAttributeVL (A));
991983 }
992984
993985 bool isStructLatticeConstant (Function *F, StructType *STy);
@@ -1419,10 +1411,10 @@ void SCCPInstVisitor::visitPHINode(PHINode &PN) {
14191411 // extensions to match the number of active incoming values. This helps to
14201412 // limit multiple extensions caused by the same incoming value, if other
14211413 // incoming values are equal.
1422- mergeInValue (&PN, PhiState,
1414+ ValueLatticeElement &PhiStateRef = ValueState[&PN];
1415+ mergeInValue (PhiStateRef, &PN, PhiState,
14231416 ValueLatticeElement::MergeOptions ().setMaxWidenSteps (
14241417 NumActiveIncoming + 1 ));
1425- ValueLatticeElement &PhiStateRef = getValueState (&PN);
14261418 PhiStateRef.setNumRangeExtensions (
14271419 std::max (NumActiveIncoming, PhiStateRef.getNumRangeExtensions ()));
14281420}
@@ -1532,7 +1524,7 @@ void SCCPInstVisitor::handleExtractOfWithOverflow(ExtractValueInst &EVI,
15321524 ConstantRange RR = R.asConstantRange (Ty, /* UndefAllowed=*/ false );
15331525 if (Idx == 0 ) {
15341526 ConstantRange Res = LR.binaryOp (WO->getBinaryOp (), RR);
1535- mergeInValue (&EVI, ValueLatticeElement::getRange (Res));
1527+ mergeInValue (ValueState[&EVI], &EVI, ValueLatticeElement::getRange (Res));
15361528 } else {
15371529 assert (Idx == 1 && " Index can only be 0 or 1" );
15381530 ConstantRange NWRegion = ConstantRange::makeGuaranteedNoWrapRegion (
@@ -1564,7 +1556,7 @@ void SCCPInstVisitor::visitExtractValueInst(ExtractValueInst &EVI) {
15641556 if (auto *WO = dyn_cast<WithOverflowInst>(AggVal))
15651557 return handleExtractOfWithOverflow (EVI, WO, i);
15661558 ValueLatticeElement EltVal = getStructValueState (AggVal, i);
1567- mergeInValue (getValueState ( &EVI) , &EVI, EltVal);
1559+ mergeInValue (ValueState[ &EVI] , &EVI, EltVal);
15681560 } else {
15691561 // Otherwise, must be extracting from an array.
15701562 return (void )markOverdefined (&EVI);
@@ -1627,7 +1619,10 @@ void SCCPInstVisitor::visitSelectInst(SelectInst &I) {
16271619 if (ConstantInt *CondCB =
16281620 getConstantInt (CondValue, I.getCondition ()->getType ())) {
16291621 Value *OpVal = CondCB->isZero () ? I.getFalseValue () : I.getTrueValue ();
1630- mergeInValue (&I, getValueState (OpVal));
1622+ const ValueLatticeElement &OpValState = getValueState (OpVal);
1623+ // Safety: ValueState[&I] doesn't invalidate OpValState since it is already
1624+ // in the map.
1625+ mergeInValue (ValueState[&I], &I, OpValState);
16311626 return ;
16321627 }
16331628
@@ -1725,7 +1720,7 @@ void SCCPInstVisitor::visitBinaryOperator(Instruction &I) {
17251720 // being a special floating value.
17261721 ValueLatticeElement NewV;
17271722 NewV.markConstant (C, /* MayIncludeUndef=*/ true );
1728- return (void )mergeInValue (&I, NewV);
1723+ return (void )mergeInValue (ValueState[&I], &I, NewV);
17291724 }
17301725 }
17311726
@@ -1745,7 +1740,7 @@ void SCCPInstVisitor::visitBinaryOperator(Instruction &I) {
17451740 R = A.overflowingBinaryOp (BO->getOpcode (), B, OBO->getNoWrapKind ());
17461741 else
17471742 R = A.binaryOp (BO->getOpcode (), B);
1748- mergeInValue (&I, ValueLatticeElement::getRange (R));
1743+ mergeInValue (ValueState[&I], &I, ValueLatticeElement::getRange (R));
17491744
17501745 // TODO: Currently we do not exploit special values that produce something
17511746 // better than overdefined with an overdefined operand for vector or floating
@@ -1771,7 +1766,7 @@ void SCCPInstVisitor::visitCmpInst(CmpInst &I) {
17711766 if (C) {
17721767 ValueLatticeElement CV;
17731768 CV.markConstant (C);
1774- mergeInValue (&I, CV);
1769+ mergeInValue (ValueState[&I], &I, CV);
17751770 return ;
17761771 }
17771772
@@ -1919,7 +1914,7 @@ void SCCPInstVisitor::visitLoadInst(LoadInst &I) {
19191914 }
19201915
19211916 // Fall back to metadata.
1922- mergeInValue (&I, getValueFromMetadata (&I));
1917+ mergeInValue (ValueState[&I], &I, getValueFromMetadata (&I));
19231918}
19241919
19251920void SCCPInstVisitor::visitCallBase (CallBase &CB) {
@@ -1967,7 +1962,7 @@ void SCCPInstVisitor::handleCallOverdefined(CallBase &CB) {
19671962 }
19681963
19691964 // Fall back to metadata.
1970- mergeInValue (&CB, getValueFromMetadata (&CB));
1965+ mergeInValue (ValueState[&CB], &CB, getValueFromMetadata (&CB));
19711966}
19721967
19731968void SCCPInstVisitor::handleCallArguments (CallBase &CB) {
@@ -1996,7 +1991,7 @@ void SCCPInstVisitor::handleCallArguments(CallBase &CB) {
19961991 getMaxWidenStepsOpts ());
19971992 }
19981993 } else
1999- mergeInValue (&*AI,
1994+ mergeInValue (ValueState[&*AI], &*AI,
20001995 getValueState (*CAI).intersect (getArgAttributeVL (&*AI)),
20011996 getMaxWidenStepsOpts ());
20021997 }
@@ -2079,7 +2074,8 @@ void SCCPInstVisitor::handleCallResult(CallBase &CB) {
20792074 if (II->getIntrinsicID () == Intrinsic::vscale) {
20802075 unsigned BitWidth = CB.getType ()->getScalarSizeInBits ();
20812076 const ConstantRange Result = getVScaleRange (II->getFunction (), BitWidth);
2082- return (void )mergeInValue (II, ValueLatticeElement::getRange (Result));
2077+ return (void )mergeInValue (ValueState[II], II,
2078+ ValueLatticeElement::getRange (Result));
20832079 }
20842080
20852081 if (ConstantRange::isIntrinsicSupported (II->getIntrinsicID ())) {
@@ -2097,7 +2093,8 @@ void SCCPInstVisitor::handleCallResult(CallBase &CB) {
20972093
20982094 ConstantRange Result =
20992095 ConstantRange::intrinsic (II->getIntrinsicID (), OpRanges);
2100- return (void )mergeInValue (II, ValueLatticeElement::getRange (Result));
2096+ return (void )mergeInValue (ValueState[II], II,
2097+ ValueLatticeElement::getRange (Result));
21012098 }
21022099 }
21032100
@@ -2124,7 +2121,7 @@ void SCCPInstVisitor::handleCallResult(CallBase &CB) {
21242121 return handleCallOverdefined (CB); // Not tracking this callee.
21252122
21262123 // If so, propagate the return value of the callee into this call result.
2127- mergeInValue (&CB, TFRVI->second , getMaxWidenStepsOpts ());
2124+ mergeInValue (ValueState[&CB], &CB, TFRVI->second , getMaxWidenStepsOpts ());
21282125 }
21292126}
21302127
0 commit comments