Skip to content

Commit 73d61d7

Browse files
choikwaDDEle
authored andcommitted
don't touch mergeInValue as that makes everything unreachable. Instead, add check w/ getUnderlyingObjects to grab all the ptr derivatives, in tryToReplaceWithConstant
1 parent e2d14f5 commit 73d61d7

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

llvm/lib/Transforms/IPO/SCCP.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ static bool runIPSCCP(
176176
bool ReplacedPointerArg = false;
177177
for (Argument &Arg : F.args()) {
178178
if (!Arg.use_empty() &&
179-
!Arg.hasNoAliasAttr() && //don't replace if arg is noalias
180179
Solver.tryToReplaceWithConstant(&Arg)) {
181180
ReplacedPointerArg |= Arg.getType()->isPointerTy();
182181
++NumArgsElimed;

llvm/lib/Transforms/Utils/SCCPSolver.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ bool SCCPSolver::tryToReplaceWithConstant(Value *V) {
6262
Constant *Const = getConstantOrNull(V);
6363
if (!Const)
6464
return false;
65+
66+
// Don't replace noalias arg or derivatives
67+
if (isa<PointerType>(V->getType())) {
68+
SmallVector<const Value *, 4> Objects;
69+
getUnderlyingObjects(V, Objects, nullptr);
70+
71+
for (const auto Obj : Objects) {
72+
if (const auto *Arg = dyn_cast<Argument>(Obj)) {
73+
if (isa<PointerType>(Arg->getType()) &&
74+
Arg->hasNoAliasAttr())
75+
return false;
76+
}
77+
}
78+
}
79+
6580
// Replacing `musttail` instructions with constant breaks `musttail` invariant
6681
// unless the call itself can be removed.
6782
// Calls with "clang.arc.attachedcall" implicitly use the return value and
@@ -1168,11 +1183,7 @@ void SCCPInstVisitor::visitInstruction(Instruction &I) {
11681183
bool SCCPInstVisitor::mergeInValue(ValueLatticeElement &IV, Value *V,
11691184
ValueLatticeElement MergeWithV,
11701185
ValueLatticeElement::MergeOptions Opts) {
1171-
if (const auto *Arg = dyn_cast<Argument>(V)) {
1172-
if (isa<PointerType>(Arg->getType()) &&
1173-
Arg->hasNoAliasAttr())
1174-
return false; // do not merge w/ noalias ptr.
1175-
}
1186+
11761187
if (IV.mergeIn(MergeWithV, Opts)) {
11771188
pushUsersToWorkList(V);
11781189
LLVM_DEBUG(dbgs() << "Merged " << MergeWithV << " into " << *V << " : "

0 commit comments

Comments
 (0)