[llvm] d911c17 - [SCCP] Get a copy of the state of CopyOf once.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri May 1 06:50:34 PDT 2020
Author: Florian Hahn
Date: 2020-05-01T14:46:35+01:00
New Revision: d911c17596c105d66be8daba4e778600527fde2e
URL: https://github.com/llvm/llvm-project/commit/d911c17596c105d66be8daba4e778600527fde2e
DIFF: https://github.com/llvm/llvm-project/commit/d911c17596c105d66be8daba4e778600527fde2e.diff
LOG: [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.
Added:
Modified:
llvm/lib/Transforms/Scalar/SCCP.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp
index ba97ed428dfd..e5fd6167f47e 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<PredicateBranch>(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<CmpInst>(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);
}
}
More information about the llvm-commits
mailing list