@@ -634,11 +634,11 @@ class SCCPInstVisitor : public InstVisitor<SCCPInstVisitor> {
634634 // / Merge \p MergeWithV into \p IV and push \p V to the worklist, if \p IV
635635 // / changes.
636636 bool mergeInValue (ValueLatticeElement &IV, Value *V,
637- ValueLatticeElement MergeWithV,
637+ const ValueLatticeElement & MergeWithV,
638638 ValueLatticeElement::MergeOptions Opts = {
639639 /* MayIncludeUndef=*/ false , /* CheckWiden=*/ false });
640640
641- bool mergeInValue (Value *V, ValueLatticeElement MergeWithV,
641+ bool mergeInValue (Value *V, const ValueLatticeElement & MergeWithV,
642642 ValueLatticeElement::MergeOptions Opts = {
643643 /* MayIncludeUndef=*/ false , /* CheckWiden=*/ false }) {
644644 assert (!V->getType ()->isStructTy () &&
@@ -1128,8 +1128,7 @@ bool SCCPInstVisitor::isStructLatticeConstant(Function *F, StructType *STy) {
11281128 for (unsigned i = 0 , e = STy->getNumElements (); i != e; ++i) {
11291129 const auto &It = TrackedMultipleRetVals.find (std::make_pair (F, i));
11301130 assert (It != TrackedMultipleRetVals.end ());
1131- ValueLatticeElement LV = It->second ;
1132- if (!SCCPSolver::isConstant (LV))
1131+ if (!SCCPSolver::isConstant (It->second ))
11331132 return false ;
11341133 }
11351134 return true ;
@@ -1160,7 +1159,7 @@ Constant *SCCPInstVisitor::getConstantOrNull(Value *V) const {
11601159 std::vector<Constant *> ConstVals;
11611160 auto *ST = cast<StructType>(V->getType ());
11621161 for (unsigned I = 0 , E = ST->getNumElements (); I != E; ++I) {
1163- ValueLatticeElement LV = LVs[I];
1162+ const ValueLatticeElement & LV = LVs[I];
11641163 ConstVals.push_back (SCCPSolver::isConstant (LV)
11651164 ? getConstant (LV, ST->getElementType (I))
11661165 : UndefValue::get (ST->getElementType (I)));
@@ -1225,7 +1224,7 @@ void SCCPInstVisitor::visitInstruction(Instruction &I) {
12251224}
12261225
12271226bool SCCPInstVisitor::mergeInValue (ValueLatticeElement &IV, Value *V,
1228- ValueLatticeElement MergeWithV,
1227+ const ValueLatticeElement & MergeWithV,
12291228 ValueLatticeElement::MergeOptions Opts) {
12301229 if (IV.mergeIn (MergeWithV, Opts)) {
12311230 pushUsersToWorkList (V);
@@ -1264,7 +1263,7 @@ void SCCPInstVisitor::getFeasibleSuccessors(Instruction &TI,
12641263 return ;
12651264 }
12661265
1267- ValueLatticeElement BCValue = getValueState (BI->getCondition ());
1266+ const ValueLatticeElement & BCValue = getValueState (BI->getCondition ());
12681267 ConstantInt *CI = getConstantInt (BCValue, BI->getCondition ()->getType ());
12691268 if (!CI) {
12701269 // Overdefined condition variables, and branches on unfoldable constant
@@ -1326,7 +1325,7 @@ void SCCPInstVisitor::getFeasibleSuccessors(Instruction &TI,
13261325 // the target as executable.
13271326 if (auto *IBR = dyn_cast<IndirectBrInst>(&TI)) {
13281327 // Casts are folded by visitCastInst.
1329- ValueLatticeElement IBRValue = getValueState (IBR->getAddress ());
1328+ const ValueLatticeElement & IBRValue = getValueState (IBR->getAddress ());
13301329 BlockAddress *Addr = dyn_cast_or_null<BlockAddress>(
13311330 getConstant (IBRValue, IBR->getAddress ()->getType ()));
13321331 if (!Addr) { // Overdefined or unknown condition?
@@ -1408,7 +1407,7 @@ void SCCPInstVisitor::visitPHINode(PHINode &PN) {
14081407 if (!isEdgeFeasible (PN.getIncomingBlock (i), PN.getParent ()))
14091408 continue ;
14101409
1411- ValueLatticeElement IV = getValueState (PN.getIncomingValue (i));
1410+ const ValueLatticeElement & IV = getValueState (PN.getIncomingValue (i));
14121411 PhiState.mergeIn (IV);
14131412 NumActiveIncoming++;
14141413 if (PhiState.isOverdefined ())
@@ -1481,7 +1480,7 @@ void SCCPInstVisitor::visitCastInst(CastInst &I) {
14811480 }
14821481 }
14831482
1484- ValueLatticeElement OpSt = getValueState (I.getOperand (0 ));
1483+ const ValueLatticeElement & OpSt = getValueState (I.getOperand (0 ));
14851484 if (OpSt.isUnknownOrUndef ())
14861485 return ;
14871486
@@ -1496,9 +1495,9 @@ void SCCPInstVisitor::visitCastInst(CastInst &I) {
14961495 if (I.getDestTy ()->isIntOrIntVectorTy () &&
14971496 I.getSrcTy ()->isIntOrIntVectorTy () &&
14981497 I.getOpcode () != Instruction::BitCast) {
1499- auto &LV = getValueState (&I);
15001498 ConstantRange OpRange =
15011499 OpSt.asConstantRange (I.getSrcTy (), /* UndefAllowed=*/ false );
1500+ auto &LV = getValueState (&I);
15021501
15031502 Type *DestTy = I.getDestTy ();
15041503 ConstantRange Res = ConstantRange::getEmpty (DestTy->getScalarSizeInBits ());
@@ -1516,15 +1515,20 @@ void SCCPInstVisitor::handleExtractOfWithOverflow(ExtractValueInst &EVI,
15161515 const WithOverflowInst *WO,
15171516 unsigned Idx) {
15181517 Value *LHS = WO->getLHS (), *RHS = WO->getRHS ();
1519- ValueLatticeElement L = getValueState ( LHS);
1520- ValueLatticeElement R = getValueState (RHS);
1518+ Type *Ty = LHS-> getType ( );
1519+
15211520 addAdditionalUser (LHS, &EVI);
15221521 addAdditionalUser (RHS, &EVI);
1523- if (L.isUnknownOrUndef () || R.isUnknownOrUndef ())
1524- return ; // Wait to resolve.
15251522
1526- Type *Ty = LHS->getType ();
1523+ const ValueLatticeElement &L = getValueState (LHS);
1524+ if (L.isUnknownOrUndef ())
1525+ return ; // Wait to resolve.
15271526 ConstantRange LR = L.asConstantRange (Ty, /* UndefAllowed=*/ false );
1527+
1528+ const ValueLatticeElement &R = getValueState (RHS);
1529+ if (R.isUnknownOrUndef ())
1530+ return ; // Wait to resolve.
1531+
15281532 ConstantRange RR = R.asConstantRange (Ty, /* UndefAllowed=*/ false );
15291533 if (Idx == 0 ) {
15301534 ConstantRange Res = LR.binaryOp (WO->getBinaryOp (), RR);
@@ -1616,7 +1620,7 @@ void SCCPInstVisitor::visitSelectInst(SelectInst &I) {
16161620 if (ValueState[&I].isOverdefined ())
16171621 return (void )markOverdefined (&I);
16181622
1619- ValueLatticeElement CondValue = getValueState (I.getCondition ());
1623+ const ValueLatticeElement & CondValue = getValueState (I.getCondition ());
16201624 if (CondValue.isUnknownOrUndef ())
16211625 return ;
16221626
@@ -1802,7 +1806,7 @@ void SCCPInstVisitor::visitGetElementPtrInst(GetElementPtrInst &I) {
18021806 Operands.reserve (I.getNumOperands ());
18031807
18041808 for (unsigned i = 0 , e = I.getNumOperands (); i != e; ++i) {
1805- ValueLatticeElement State = getValueState (I.getOperand (i));
1809+ const ValueLatticeElement & State = getValueState (I.getOperand (i));
18061810 if (State.isUnknownOrUndef ())
18071811 return ; // Operands are not resolved yet.
18081812
@@ -1881,14 +1885,13 @@ void SCCPInstVisitor::visitLoadInst(LoadInst &I) {
18811885 if (ValueState[&I].isOverdefined ())
18821886 return (void )markOverdefined (&I);
18831887
1884- ValueLatticeElement PtrVal = getValueState (I.getOperand (0 ));
1888+ const ValueLatticeElement & PtrVal = getValueState (I.getOperand (0 ));
18851889 if (PtrVal.isUnknownOrUndef ())
18861890 return ; // The pointer is not resolved yet!
18871891
1888- ValueLatticeElement &IV = ValueState[&I];
1889-
18901892 if (SCCPSolver::isConstant (PtrVal)) {
18911893 Constant *Ptr = getConstant (PtrVal, I.getOperand (0 )->getType ());
1894+ ValueLatticeElement &IV = ValueState[&I];
18921895
18931896 // load null is undefined.
18941897 if (isa<ConstantPointerNull>(Ptr)) {
@@ -1944,7 +1947,7 @@ void SCCPInstVisitor::handleCallOverdefined(CallBase &CB) {
19441947 return markOverdefined (&CB); // Can't handle struct args.
19451948 if (A.get ()->getType ()->isMetadataTy ())
19461949 continue ; // Carried in CB, not allowed in Operands.
1947- ValueLatticeElement State = getValueState (A);
1950+ const ValueLatticeElement & State = getValueState (A);
19481951
19491952 if (State.isUnknownOrUndef ())
19501953 return ; // Operands are not resolved yet.
0 commit comments