Skip to content

Commit

Permalink
Remove dead code (dotnet#60095)
Browse files Browse the repository at this point in the history
* Remove dead code

 - Delete unused GTF_NOP_DEATH.
 - Delete dead code handling GT_INDEX_ADDR as a
   GTK_SPECIAL node, it has always been GTK_BINOP.
 - Remove the unused Compiler* parameter from GenTreeQmark's constructor.
 - Remove the unused Compiler* parameter from LIR::Use::ReplaceWith,
   ever so slightly improving its performance.

There are a handful of expected diffs with this change,
they are due to proper costing for INDEX_ADDR causing
fgMorphArgs to make slightly different decisions.

* Use more strong typing in GenTreeQmark

* Call the base constructor

MSVC apparently does not detect this :(.
  • Loading branch information
SingleAccretion authored Oct 7, 2021
1 parent 4eb8d0e commit 23e386f
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 109 deletions.
8 changes: 0 additions & 8 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9081,14 +9081,6 @@ void cTreeFlags(Compiler* comp, GenTree* tree)
#endif
break;

case GT_NOP:

if (tree->gtFlags & GTF_NOP_DEATH)
{
chars += printf("[NOP_DEATH]");
}
break;

case GT_NO_OP:
break;

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3009,7 +3009,7 @@ class Compiler
// For binary opers.
GenTree* gtNewOperNode(genTreeOps oper, var_types type, GenTree* op1, GenTree* op2);

GenTreeQmark* gtNewQmarkNode(var_types type, GenTree* cond, GenTree* colon);
GenTreeQmark* gtNewQmarkNode(var_types type, GenTree* cond, GenTreeColon* colon);

GenTree* gtNewLargeOperNode(genTreeOps oper,
var_types type = TYP_I_IMPL,
Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/jit/decomposelongs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ GenTree* DecomposeLongs::FinalizeDecomposition(LIR::Use& use,

Range().InsertAfter(insertResultAfter, gtLong);

use.ReplaceWith(m_compiler, gtLong);
use.ReplaceWith(gtLong);

return gtLong->gtNext;
}
Expand Down Expand Up @@ -1075,7 +1075,7 @@ GenTree* DecomposeLongs::DecomposeShift(LIR::Use& use)
gtLong->SetUnusedValue();
}
Range().Remove(shift);
use.ReplaceWith(m_compiler, gtLong);
use.ReplaceWith(gtLong);
return next;
}

Expand Down Expand Up @@ -1370,7 +1370,7 @@ GenTree* DecomposeLongs::DecomposeShift(LIR::Use& use)
Range().InsertAfter(shift, LIR::SeqTree(m_compiler, call));

Range().Remove(shift);
use.ReplaceWith(m_compiler, call);
use.ReplaceWith(call);
return call;
}
}
Expand Down Expand Up @@ -1449,7 +1449,7 @@ GenTree* DecomposeLongs::DecomposeRotate(LIR::Use& use)
GenTree* next = tree->gtNext;
// Remove tree and don't do anything else.
Range().Remove(tree);
use.ReplaceWith(m_compiler, gtLong);
use.ReplaceWith(gtLong);
return next;
}
else
Expand Down Expand Up @@ -1863,7 +1863,7 @@ GenTree* DecomposeLongs::OptimizeCastFromDecomposedLong(GenTreeCast* cast, GenTr
LIR::Use useOfCast;
if (Range().TryGetUse(cast, &useOfCast))
{
useOfCast.ReplaceWith(m_compiler, loSrc);
useOfCast.ReplaceWith(loSrc);
}
else
{
Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/jit/fgprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,10 @@ void BlockCountInstrumentor::InstrumentMethodEntry(Schema& schema, BYTE* profile

// Compare Basic-Block count value against zero
//
GenTree* relop = m_comp->gtNewOperNode(GT_NE, typ, valueNode, m_comp->gtNewIconNode(0, typ));
GenTree* colon = new (m_comp, GT_COLON) GenTreeColon(TYP_VOID, m_comp->gtNewNothingNode(), call);
GenTree* cond = m_comp->gtNewQmarkNode(TYP_VOID, relop, colon);
Statement* stmt = m_comp->gtNewStmt(cond);
GenTree* relop = m_comp->gtNewOperNode(GT_NE, typ, valueNode, m_comp->gtNewIconNode(0, typ));
GenTreeColon* colon = new (m_comp, GT_COLON) GenTreeColon(TYP_VOID, m_comp->gtNewNothingNode(), call);
GenTreeQmark* cond = m_comp->gtNewQmarkNode(TYP_VOID, relop, colon);
Statement* stmt = m_comp->gtNewStmt(cond);

// Add this check into the scratch block entry so we only do the check once per call.
// If we put it in block we may be putting it inside a loop.
Expand Down
9 changes: 1 addition & 8 deletions src/coreclr/jit/flowgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2804,7 +2804,7 @@ void Compiler::fgAddInternal()
// Stick the conditional call at the start of the method

fgEnsureFirstBBisScratch();
fgNewStmtAtEnd(fgFirstBB, gtNewQmarkNode(TYP_VOID, guardCheckCond, callback));
fgNewStmtAtEnd(fgFirstBB, gtNewQmarkNode(TYP_VOID, guardCheckCond, callback->AsColon()));
}

#if !defined(FEATURE_EH_FUNCLETS)
Expand Down Expand Up @@ -4154,13 +4154,6 @@ void Compiler::fgSetTreeSeqHelper(GenTree* tree, bool isLIR)
noway_assert(!"DYN_BLK nodes should be sequenced as a special case");
break;

case GT_INDEX_ADDR:
// Evaluate the array first, then the index....
assert((tree->gtFlags & GTF_REVERSE_OPS) == 0);
fgSetTreeSeqHelper(tree->AsIndexAddr()->Arr(), isLIR);
fgSetTreeSeqHelper(tree->AsIndexAddr()->Index(), isLIR);
break;

default:
#ifdef DEBUG
gtDispTree(tree);
Expand Down
38 changes: 9 additions & 29 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4258,6 +4258,11 @@ unsigned Compiler::gtSetEvalOrder(GenTree* tree)
return gtSetListOrder(tree, isListCallArgs, callArgsInRegs);
}

case GT_INDEX_ADDR:
costEx = 6; // cmp reg,reg; jae throw; mov reg, [addrmode] (not taken)
costSz = 9; // jump to cold section
break;

case GT_ASG:
/* Assignments need a bit of special handling */
/* Process the target */
Expand Down Expand Up @@ -4887,23 +4892,6 @@ unsigned Compiler::gtSetEvalOrder(GenTree* tree)
}
break;

case GT_INDEX_ADDR:
costEx = 6; // cmp reg,reg; jae throw; mov reg, [addrmode] (not taken)
costSz = 9; // jump to cold section

level = gtSetEvalOrder(tree->AsIndexAddr()->Index());
costEx += tree->AsIndexAddr()->Index()->GetCostEx();
costSz += tree->AsIndexAddr()->Index()->GetCostSz();

lvl2 = gtSetEvalOrder(tree->AsIndexAddr()->Arr());
if (level < lvl2)
{
level = lvl2;
}
costEx += tree->AsIndexAddr()->Arr()->GetCostEx();
costSz += tree->AsIndexAddr()->Arr()->GetCostSz();
break;

default:
JITDUMP("unexpected operator in this tree:\n");
DISPTREE(tree);
Expand Down Expand Up @@ -6079,11 +6067,11 @@ GenTree* Compiler::gtNewOperNode(genTreeOps oper, var_types type, GenTree* op1,
return node;
}

GenTreeQmark* Compiler::gtNewQmarkNode(var_types type, GenTree* cond, GenTree* colon)
GenTreeQmark* Compiler::gtNewQmarkNode(var_types type, GenTree* cond, GenTreeColon* colon)
{
compQmarkUsed = true;
cond->gtFlags |= GTF_RELOP_QMARK;
GenTreeQmark* result = new (this, GT_QMARK) GenTreeQmark(type, cond, colon, this);
GenTreeQmark* result = new (this, GT_QMARK) GenTreeQmark(type, cond, colon);
#ifdef DEBUG
if (compQmarkRationalized)
{
Expand All @@ -6093,14 +6081,6 @@ GenTreeQmark* Compiler::gtNewQmarkNode(var_types type, GenTree* cond, GenTree* c
return result;
}

GenTreeQmark::GenTreeQmark(var_types type, GenTree* cond, GenTree* colonOp, Compiler* comp)
: GenTreeOp(GT_QMARK, type, cond, colonOp)
{
// These must follow a specific form.
assert(cond != nullptr && cond->TypeGet() == TYP_INT);
assert(colonOp != nullptr && colonOp->OperGet() == GT_COLON);
}

GenTreeIntCon* Compiler::gtNewIconNode(ssize_t value, var_types type)
{
return new (this, GT_CNS_INT) GenTreeIntCon(type, value);
Expand Down Expand Up @@ -7975,8 +7955,8 @@ GenTree* Compiler::gtCloneExpr(
break;

case GT_QMARK:
copy =
new (this, GT_QMARK) GenTreeQmark(tree->TypeGet(), tree->AsOp()->gtOp1, tree->AsOp()->gtOp2, this);
copy = new (this, GT_QMARK)
GenTreeQmark(tree->TypeGet(), tree->AsOp()->gtGetOp1(), tree->AsOp()->gtGetOp2()->AsColon());
break;

case GT_OBJ:
Expand Down
13 changes: 7 additions & 6 deletions src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,6 @@ enum GenTreeFlags : unsigned int

GTF_MEMORYBARRIER_LOAD = 0x40000000, // GT_MEMORYBARRIER -- Load barrier

GTF_NOP_DEATH = 0x40000000, // GT_NOP -- operand dies here

GTF_FLD_VOLATILE = 0x40000000, // GT_FIELD/GT_CLS_VAR -- same as GTF_IND_VOLATILE
GTF_FLD_INITCLASS = 0x20000000, // GT_FIELD/GT_CLS_VAR -- field access requires preceding class/static init helper

Expand Down Expand Up @@ -4993,12 +4991,15 @@ struct GenTreeFptrVal : public GenTree
/* gtQmark */
struct GenTreeQmark : public GenTreeOp
{
// The "Compiler*" argument is not a DEBUGARG here because we use it to keep track of the set of
// (possible) QMark nodes.
GenTreeQmark(var_types type, GenTree* cond, GenTree* colonOp, class Compiler* comp);
GenTreeQmark(var_types type, GenTree* cond, GenTreeColon* colon) : GenTreeOp(GT_QMARK, type, cond, colon)
{
// These must follow a specific form.
assert((cond != nullptr) && cond->TypeIs(TYP_INT));
assert((colon != nullptr) && colon->OperIs(GT_COLON));
}

#if DEBUGGABLE_GENTREE
GenTreeQmark() : GenTreeOp(GT_QMARK, TYP_INT, nullptr, nullptr)
GenTreeQmark() : GenTreeOp()
{
}
#endif
Expand Down
14 changes: 7 additions & 7 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2337,10 +2337,10 @@ GenTree* Compiler::impRuntimeLookupToTree(CORINFO_RESOLVED_TOKEN* pResolvedToken
indir->gtFlags |= GTF_IND_NONFAULTING;
indir->gtFlags |= GTF_IND_INVARIANT;

slot = gtNewLclvNode(slotLclNum, TYP_I_IMPL);
GenTree* asg = gtNewAssignNode(slot, indir);
GenTree* colon = new (this, GT_COLON) GenTreeColon(TYP_VOID, gtNewNothingNode(), asg);
GenTree* qmark = gtNewQmarkNode(TYP_VOID, relop, colon);
slot = gtNewLclvNode(slotLclNum, TYP_I_IMPL);
GenTree* asg = gtNewAssignNode(slot, indir);
GenTreeColon* colon = new (this, GT_COLON) GenTreeColon(TYP_VOID, gtNewNothingNode(), asg);
GenTreeQmark* qmark = gtNewQmarkNode(TYP_VOID, relop, colon);
impAppendTree(qmark, (unsigned)CHECK_SPILL_NONE, impCurStmtOffs);

return gtNewLclvNode(slotLclNum, TYP_I_IMPL);
Expand Down Expand Up @@ -11245,7 +11245,7 @@ GenTree* Compiler::impCastClassOrIsInstToTree(GenTree* op1,
// condFalse condTrue
//
temp = new (this, GT_COLON) GenTreeColon(TYP_REF, condTrue, condFalse);
qmarkMT = gtNewQmarkNode(TYP_REF, condMT, temp);
qmarkMT = gtNewQmarkNode(TYP_REF, condMT, temp->AsColon());

if (isCastClass && impIsClassExact(pResolvedToken->hClass) && condTrue->OperIs(GT_CALL))
{
Expand All @@ -11264,7 +11264,7 @@ GenTree* Compiler::impCastClassOrIsInstToTree(GenTree* op1,
// qmarkMT op1Copy
//
temp = new (this, GT_COLON) GenTreeColon(TYP_REF, gtClone(op1), qmarkMT);
qmarkNull = gtNewQmarkNode(TYP_REF, condNull, temp);
qmarkNull = gtNewQmarkNode(TYP_REF, condNull, temp->AsColon());
qmarkNull->gtFlags |= GTF_QMARK_CAST_INSTOF;

// Make QMark node a top level node by spilling it.
Expand Down Expand Up @@ -16111,7 +16111,7 @@ void Compiler::impImportBlockCode(BasicBlock* block)
op1 = gtNewHelperCallNode(helper, TYP_VOID, gtNewCallArgs(op2, op1));

op1 = new (this, GT_COLON) GenTreeColon(TYP_VOID, gtNewNothingNode(), op1);
op1 = gtNewQmarkNode(TYP_VOID, condBox, op1);
op1 = gtNewQmarkNode(TYP_VOID, condBox, op1->AsColon());

// QMARK nodes cannot reside on the evaluation stack. Because there
// may be other trees on the evaluation stack that side-effect the
Expand Down
8 changes: 3 additions & 5 deletions src/coreclr/jit/lir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void LIR::Use::AssertIsValid() const
//
// GenTree* constantOne = compiler->gtNewIconNode(1);
// range.InsertAfter(opEq.Def(), constantOne);
// opEq.ReplaceWith(compiler, constantOne);
// opEq.ReplaceWith(constantOne);
//
// Which would produce something like the following LIR:
//
Expand All @@ -179,13 +179,11 @@ void LIR::Use::AssertIsValid() const
// * jmpTrue void
//
// Arguments:
// compiler - The Compiler context.
// replacement - The replacement node.
//
void LIR::Use::ReplaceWith(Compiler* compiler, GenTree* replacement)
void LIR::Use::ReplaceWith(GenTree* replacement)
{
assert(IsInitialized());
assert(compiler != nullptr);
assert(replacement != nullptr);
assert(IsDummyUse() || m_range->Contains(m_user));
assert(m_range->Contains(replacement));
Expand Down Expand Up @@ -273,7 +271,7 @@ unsigned LIR::Use::ReplaceWithLclVar(Compiler* compiler, unsigned lclNum, GenTre

m_range->InsertAfter(node, store, load);

ReplaceWith(compiler, load);
ReplaceWith(load);

JITDUMP("ReplaceWithLclVar created store :\n");
DISPNODE(store);
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/lir.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class LIR final
void AssertIsValid() const;
bool IsDummyUse() const;

void ReplaceWith(Compiler* compiler, GenTree* replacement);
void ReplaceWith(GenTree* replacement);
unsigned ReplaceWithLclVar(Compiler* compiler, unsigned lclNum = BAD_VAR_NUM, GenTree** assign = nullptr);
};

Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2689,7 +2689,7 @@ GenTree* Lowering::OptimizeConstCompare(GenTree* cmp)
{
cc = new (comp, GT_SETCC) GenTreeCC(GT_SETCC, condition, TYP_INT);
BlockRange().InsertAfter(cmp, cc);
cmpUse.ReplaceWith(comp, cc);
cmpUse.ReplaceWith(cc);
}

cc->gtFlags |= GTF_USE_FLAGS;
Expand Down Expand Up @@ -2953,7 +2953,7 @@ GenTreeCC* Lowering::LowerNodeCC(GenTree* node, GenCondition condition)
{
cc = new (comp, GT_SETCC) GenTreeCC(GT_SETCC, condition, TYP_INT);
BlockRange().InsertAfter(node, cc);
use.ReplaceWith(comp, cc);
use.ReplaceWith(cc);
}
}
}
Expand Down Expand Up @@ -5065,7 +5065,7 @@ GenTree* Lowering::LowerAdd(GenTreeOp* node)
DISPNODE(op1);
if (BlockRange().TryGetUse(node, &use))
{
use.ReplaceWith(comp, op1);
use.ReplaceWith(op1);
}
else
{
Expand Down Expand Up @@ -5670,7 +5670,7 @@ GenTree* Lowering::LowerConstIntDivOrMod(GenTree* node)
BlockRange().Remove(divMod);

// replace the original divmod node with the new divmod tree
use.ReplaceWith(comp, newDivMod);
use.ReplaceWith(newDivMod);

return newDivMod->gtNext;
}
Expand Down Expand Up @@ -5931,7 +5931,7 @@ GenTree* Lowering::LowerArrElem(GenTree* node)
LIR::Use arrElemUse;
if (BlockRange().TryGetUse(arrElem, &arrElemUse))
{
arrElemUse.ReplaceWith(comp, leaNode);
arrElemUse.ReplaceWith(leaNode);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/lowerxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2899,7 +2899,7 @@ void Lowering::LowerHWIntrinsicGetElement(GenTreeHWIntrinsic* node)

if (foundUse)
{
use.ReplaceWith(comp, cast);
use.ReplaceWith(cast);
}
LowerNode(cast);
}
Expand Down Expand Up @@ -3981,7 +3981,7 @@ void Lowering::LowerHWIntrinsicToScalar(GenTreeHWIntrinsic* node)

if (foundUse)
{
use.ReplaceWith(comp, cast);
use.ReplaceWith(cast);
}
LowerNode(cast);
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/lsra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6242,7 +6242,7 @@ void LinearScan::insertCopyOrReload(BasicBlock* block, GenTree* tree, unsigned m
// Insert the copy/reload after the spilled node and replace the use of the original node with a use
// of the copy/reload.
blockRange.InsertAfter(tree, newNode);
treeUse.ReplaceWith(compiler, newNode);
treeUse.ReplaceWith(newNode);
}
}

Expand Down
12 changes: 0 additions & 12 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14961,18 +14961,6 @@ GenTree* Compiler::fgMorphTree(GenTree* tree, MorphAddrContext* mac)
tree->gtFlags |= tree->AsDynBlk()->gtDynamicSize->gtFlags & GTF_ALL_EFFECT;
break;

case GT_INDEX_ADDR:
GenTreeIndexAddr* indexAddr;
indexAddr = tree->AsIndexAddr();
indexAddr->Index() = fgMorphTree(indexAddr->Index());
indexAddr->Arr() = fgMorphTree(indexAddr->Arr());

tree->gtFlags &= ~GTF_CALL;

tree->gtFlags |= indexAddr->Index()->gtFlags & GTF_ALL_EFFECT;
tree->gtFlags |= indexAddr->Arr()->gtFlags & GTF_ALL_EFFECT;
break;

default:
#ifdef DEBUG
gtDispTree(tree);
Expand Down
Loading

0 comments on commit 23e386f

Please sign in to comment.