From: Florian Hahn Date: Fri, 1 May 2020 13:43:15 +0000 (+0100) Subject: [SCCP] Get a copy of the state of CopyOf once. X-Git-Tag: llvmorg-12-init~7233 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d911c17596c105d66be8daba4e778600527fde2e;p=platform%2Fupstream%2Fllvm.git [SCCP] Get a copy of the state of CopyOf once. This fixes potential reference invalidations, when no lattice value is assigned for CopyOf. As the state of CopyOf won't change while in handleCallResult, we can get a copy once and use that. Should fix PR45749. --- diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp index ba97ed4..e5fd616 100644 --- a/llvm/lib/Transforms/Scalar/SCCP.cpp +++ b/llvm/lib/Transforms/Scalar/SCCP.cpp @@ -1223,22 +1223,23 @@ void SCCPSolver::handleCallResult(CallBase &CB) { Value *CopyOf = CB.getOperand(0); auto *PI = getPredicateInfoFor(&CB); auto *PBranch = dyn_cast_or_null(PI); + ValueLatticeElement OriginalVal = getValueState(CopyOf); if (!PI || !PBranch) { - mergeInValue(ValueState[&CB], &CB, getValueState(CopyOf)); + mergeInValue(ValueState[&CB], &CB, OriginalVal); return; } // Everything below relies on the condition being a comparison. auto *Cmp = dyn_cast(PBranch->Condition); if (!Cmp) { - mergeInValue(ValueState[&CB], &CB, getValueState(CopyOf)); + mergeInValue(ValueState[&CB], &CB, OriginalVal); return; } Value *CmpOp0 = Cmp->getOperand(0); Value *CmpOp1 = Cmp->getOperand(1); if (CopyOf != CmpOp0 && CopyOf != CmpOp1) { - mergeInValue(ValueState[&CB], &CB, getValueState(CopyOf)); + mergeInValue(ValueState[&CB], &CB, OriginalVal); return; } @@ -1259,7 +1260,6 @@ void SCCPSolver::handleCallResult(CallBase &CB) { ValueLatticeElement CondVal = getValueState(CmpOp1); ValueLatticeElement &IV = ValueState[&CB]; - ValueLatticeElement OriginalVal = getValueState(CopyOf); if (CondVal.isConstantRange() || OriginalVal.isConstantRange()) { auto NewCR = ConstantRange::getFull(DL.getTypeSizeInBits(CopyOf->getType())); @@ -1299,7 +1299,7 @@ void SCCPSolver::handleCallResult(CallBase &CB) { return; } - return (void)mergeInValue(IV, &CB, getValueState(CopyOf)); + return (void)mergeInValue(IV, &CB, OriginalVal); } }