Skip to content

Commit 3ad5a57

Browse files
authored
Merge pull request #7397 from eclipse/revert-7364-replaceRedundantIshl
Revert "Replace redundant shifts and rotations of const 0 with const 0"
2 parents befee22 + 0c6cc06 commit 3ad5a57

File tree

2 files changed

+21
-149
lines changed

2 files changed

+21
-149
lines changed

Diff for: compiler/optimizer/OMRSimplifierHandlers.cpp

+8-90
Original file line numberDiff line numberDiff line change
@@ -10259,12 +10259,7 @@ TR::Node *ishlSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s)
1025910259
if (identity)
1026010260
return identity;
1026110261

10262-
// Replace shift of constant zero with constant zero
10263-
if (firstChild->getOpCode().isLoadConst() && firstChild->getInt() == 0)
10264-
{
10265-
return s->replaceNode(node, firstChild, s->_curTree);
10266-
}
10267-
else if (secondChild->getOpCode().isLoadConst() &&
10262+
if (secondChild->getOpCode().isLoadConst() &&
1026810263
performTransformation(s->comp(), "%sChanged ishl by const into imul by const in node [%s]\n", s->optDetailString(), node->getName(s->getDebug())))
1026910264
{
1027010265
// Normalize shift by a constant into multiply by a constant
@@ -10306,12 +10301,7 @@ TR::Node *lshlSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s)
1030610301
if (identity)
1030710302
return identity;
1030810303

10309-
// Replace shift of constant zero with constant zero
10310-
if (firstChild->getOpCode().isLoadConst() && firstChild->getLongInt() == 0)
10311-
{
10312-
return s->replaceNode(node, firstChild, s->_curTree);
10313-
}
10314-
else if (secondChild->getOpCode().isLoadConst())
10304+
if (secondChild->getOpCode().isLoadConst())
1031510305
{
1031610306
// Canonicalize shift by a constant into multiply by a constant
1031710307
//
@@ -10355,12 +10345,6 @@ TR::Node *bshlSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s)
1035510345
if (identity)
1035610346
return identity;
1035710347

10358-
// Replace shift of constant zero with constant zero
10359-
if (firstChild->getOpCode().isLoadConst() && firstChild->getByte() == 0)
10360-
{
10361-
return s->replaceNode(node, firstChild, s->_curTree);
10362-
}
10363-
1036410348
return node;
1036510349
}
1036610350

@@ -10381,12 +10365,6 @@ TR::Node *sshlSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s)
1038110365
if (identity)
1038210366
return identity;
1038310367

10384-
// Replace shift of constant zero with constant zero
10385-
if (firstChild->getOpCode().isLoadConst() && firstChild->getShortInt() == 0)
10386-
{
10387-
return s->replaceNode(node, firstChild, s->_curTree);
10388-
}
10389-
1039010368
return node;
1039110369
}
1039210370

@@ -10413,13 +10391,7 @@ TR::Node *ishrSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s)
1041310391
if (identity)
1041410392
return identity;
1041510393

10416-
// Replace shift of constant zero with constant zero
10417-
if (firstChild->getOpCode().isLoadConst() && firstChild->getInt() == 0)
10418-
{
10419-
return s->replaceNode(node, firstChild, s->_curTree);
10420-
}
10421-
else
10422-
normalizeShiftAmount(node, 31, s);
10394+
normalizeShiftAmount(node, 31, s);
1042310395

1042410396
return node;
1042510397
}
@@ -10443,13 +10415,7 @@ TR::Node *lshrSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s)
1044310415
if (identity)
1044410416
return identity;
1044510417

10446-
// Replace shift of constant zero with constant zero
10447-
if (firstChild->getOpCode().isLoadConst() && firstChild->getLongInt() == 0)
10448-
{
10449-
return s->replaceNode(node, firstChild, s->_curTree);
10450-
}
10451-
else
10452-
normalizeShiftAmount(node, 63, s);
10418+
normalizeShiftAmount(node, 63, s);
1045310419

1045410420
return node;
1045510421
}
@@ -10471,12 +10437,6 @@ TR::Node *bshrSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s)
1047110437
if (identity)
1047210438
return identity;
1047310439

10474-
// Replace shift of constant zero with constant zero
10475-
if (firstChild->getOpCode().isLoadConst() && firstChild->getByte() == 0)
10476-
{
10477-
return s->replaceNode(node, firstChild, s->_curTree);
10478-
}
10479-
1048010440
return node;
1048110441
}
1048210442

@@ -10497,12 +10457,6 @@ TR::Node *sshrSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s)
1049710457
if (identity)
1049810458
return identity;
1049910459

10500-
// Replace shift of constant zero with constant zero
10501-
if (firstChild->getOpCode().isLoadConst() && firstChild->getShortInt() == 0)
10502-
{
10503-
return s->replaceNode(node, firstChild, s->_curTree);
10504-
}
10505-
1050610460
return node;
1050710461
}
1050810462

@@ -10595,13 +10549,7 @@ TR::Node *iushrSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s
1059510549
}
1059610550
}
1059710551

10598-
// Replace shift of constant zero with constant zero
10599-
if (firstChild->getOpCode().isLoadConst() && firstChild->getUnsignedInt() == 0)
10600-
{
10601-
return s->replaceNode(node, firstChild, s->_curTree);
10602-
}
10603-
else
10604-
normalizeShiftAmount(node, 31, s);
10552+
normalizeShiftAmount(node, 31, s);
1060510553

1060610554
return node;
1060710555
}
@@ -10743,13 +10691,7 @@ TR::Node *lushrSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s
1074310691
}
1074410692
}
1074510693

10746-
// Replace shift of constant zero with constant zero
10747-
if (firstChild->getOpCode().isLoadConst() && firstChild->getUnsignedLongInt() == 0)
10748-
{
10749-
return s->replaceNode(node, firstChild, s->_curTree);
10750-
}
10751-
else
10752-
normalizeShiftAmount(node, 63, s);
10694+
normalizeShiftAmount(node, 63, s);
1075310695

1075410696
return node;
1075510697
}
@@ -10771,12 +10713,6 @@ TR::Node *bushrSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s
1077110713
if (identity)
1077210714
return identity;
1077310715

10774-
// Replace shift of constant zero with constant zero
10775-
if (firstChild->getOpCode().isLoadConst() && firstChild->getUnsignedByte() == 0)
10776-
{
10777-
return s->replaceNode(node, firstChild, s->_curTree);
10778-
}
10779-
1078010716
return node;
1078110717
}
1078210718

@@ -10797,12 +10733,6 @@ TR::Node *sushrSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s
1079710733
if (identity)
1079810734
return identity;
1079910735

10800-
// Replace shift of constant zero with constant zero
10801-
if (firstChild->getOpCode().isLoadConst() && firstChild->getUnsignedShortInt() == 0)
10802-
{
10803-
return s->replaceNode(node, firstChild, s->_curTree);
10804-
}
10805-
1080610736
return node;
1080710737
}
1080810738

@@ -10831,13 +10761,7 @@ TR::Node *irolSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s)
1083110761
return s->replaceNode(node, firstChild, s->_curTree);
1083210762
}
1083310763

10834-
// Replace rotate of constant zero with constant zero
10835-
if (firstChild->getOpCode().isLoadConst() && firstChild->getInt() == 0)
10836-
{
10837-
return s->replaceNode(node, firstChild, s->_curTree);
10838-
}
10839-
else
10840-
normalizeShiftAmount(node, 31, s);
10764+
normalizeShiftAmount(node, 31, s);
1084110765
return node;
1084210766
}
1084310767

@@ -10861,13 +10785,7 @@ TR::Node *lrolSimplifier(TR::Node * node, TR::Block * block, TR::Simplifier * s)
1086110785
return s->replaceNode(node, firstChild, s->_curTree);
1086210786
}
1086310787

10864-
// Replace rotate of constant zero with constant zero
10865-
if (firstChild->getOpCode().isLoadConst() && firstChild->getLongInt() == 0)
10866-
{
10867-
return s->replaceNode(node, firstChild, s->_curTree);
10868-
}
10869-
else
10870-
normalizeShiftAmount(node, 63, s);
10788+
normalizeShiftAmount(node, 63, s);
1087110789
return node;
1087210790
}
1087310791

Diff for: compiler/optimizer/VPHandlers.cpp

+13-59
Original file line numberDiff line numberDiff line change
@@ -7027,13 +7027,6 @@ TR::Node *constrainIshl(OMR::ValuePropagation *vp, TR::Node *node)
70277027
vp->replaceByConstant(node, constraint, lhsGlobal);
70287028
}
70297029

7030-
// Replace shift of constant zero with constant zero
7031-
if (lhs && lhs->asIntConst()
7032-
&& lhs->asIntConst()->getInt() == 0)
7033-
{
7034-
return vp->replaceNode(node, node->getFirstChild(), vp->_curTree);
7035-
}
7036-
70377030
checkForNonNegativeAndOverflowProperties(vp, node);
70387031
return node;
70397032
}
@@ -7057,13 +7050,7 @@ TR::Node *constrainLshl(OMR::ValuePropagation *vp, TR::Node *node)
70577050
vp->replaceByConstant(node, constraint, lhsGlobal);
70587051
}
70597052

7060-
// Replace shift of constant zero with constant zero
7061-
if (lhs && lhs->asLongConst()
7062-
&& lhs->asLongConst()->getLong() == 0)
7063-
{
7064-
return vp->replaceNode(node, node->getFirstChild(), vp->_curTree);
7065-
}
7066-
else if (lhs && lhs->asLongConst() &&
7053+
if (lhs && lhs->asLongConst() &&
70677054
lhs->asLongConst()->getLong() == 1)
70687055
{
70697056
TR::VPConstraint *constraint = TR::VPLongRange::create(vp, TR::getMinSigned<TR::Int64>(), TR::getMaxSigned<TR::Int64>(), true);
@@ -7204,23 +7191,17 @@ TR::Node *constrainIshr(OMR::ValuePropagation *vp, TR::Node *node)
72047191
return node;
72057192
constrainChildren(vp, node);
72067193

7207-
bool lhsGlobal, rhsGlobal;
7208-
TR::VPConstraint *lhs = vp->getConstraint(node->getFirstChild(), lhsGlobal);
7194+
bool rhsGlobal;
72097195
TR::VPConstraint *rhs = vp->getConstraint(node->getSecondChild(), rhsGlobal);
7210-
lhsGlobal &= rhsGlobal;
7211-
7212-
// Replace shift of constant zero with constant zero
7213-
if (lhs && lhs->asIntConst()
7214-
&& lhs->asIntConst()->getInt() == 0)
7215-
{
7216-
return vp->replaceNode(node, node->getFirstChild(), vp->_curTree);
7217-
}
7218-
72197196
if (rhs && rhs->asIntConst())
72207197
{
72217198
int32_t rhsConst = rhs->asIntConst()->getInt();
72227199
int32_t shiftAmount = rhsConst & 0x01F;
72237200

7201+
bool lhsGlobal;
7202+
TR::VPConstraint *lhs = vp->getConstraint(node->getFirstChild(), lhsGlobal);
7203+
lhsGlobal &= rhsGlobal;
7204+
72247205
int32_t low, high;
72257206
if (lhs)
72267207
{
@@ -7265,7 +7246,6 @@ TR::Node *constrainIshr(OMR::ValuePropagation *vp, TR::Node *node)
72657246
//lhs->decReferenceCount();
72667247
//rhs->decReferenceCount();
72677248
}
7268-
72697249
// this handler is not called for unsigned shifts
72707250
//#ifdef DEBUG
72717251
//else if(!firstChild->getType().isSignedInt()) dumpOptDetails(vp->comp(), "FIXME: Need to support ishr opt for Unsigned datatypes!\n");
@@ -7283,23 +7263,17 @@ TR::Node *constrainLshr(OMR::ValuePropagation *vp, TR::Node *node)
72837263

72847264
constrainChildren(vp, node);
72857265

7286-
bool lhsGlobal, rhsGlobal;
7287-
TR::VPConstraint *lhs = vp->getConstraint(node->getFirstChild(), lhsGlobal);
7266+
bool rhsGlobal;
72887267
TR::VPConstraint *rhs = vp->getConstraint(node->getSecondChild(), rhsGlobal);
7289-
lhsGlobal &= rhsGlobal;
7290-
7291-
// Replace shift of constant zero with constant zero
7292-
if (lhs && lhs->asLongConst()
7293-
&& lhs->asLongConst()->getLong() == 0)
7294-
{
7295-
return vp->replaceNode(node, node->getFirstChild(), vp->_curTree);
7296-
}
7297-
72987268
if (rhs && rhs->asIntConst())
72997269
{
73007270
int32_t rhsConst = rhs->asIntConst()->getInt();
73017271
int32_t shiftAmount = rhsConst & 0x03F;
73027272

7273+
bool lhsGlobal;
7274+
TR::VPConstraint *lhs = vp->getConstraint(node->getFirstChild(), lhsGlobal);
7275+
lhsGlobal &= rhsGlobal;
7276+
73037277
int64_t low, high;
73047278
if (lhs)
73057279
{
@@ -7366,18 +7340,8 @@ TR::Node *constrainIushr(OMR::ValuePropagation *vp, TR::Node *node)
73667340
//if (parent && parent->getType().isUnsignedInt())
73677341
// isUnsigned = true;
73687342

7369-
bool lhsGlobal, rhsGlobal;
7370-
TR::VPConstraint *lhs = vp->getConstraint(node->getFirstChild(), lhsGlobal);
7343+
bool rhsGlobal;
73717344
TR::VPConstraint *rhs = vp->getConstraint(node->getSecondChild(), rhsGlobal);
7372-
lhsGlobal &= rhsGlobal;
7373-
7374-
// Replace shift of constant zero with constant zero
7375-
if (lhs && lhs->asIntConst()
7376-
&& lhs->asIntConst()->getInt() == 0)
7377-
{
7378-
return vp->replaceNode(node, node->getFirstChild(), vp->_curTree);
7379-
}
7380-
73817345
if (rhs && rhs->asIntConst())
73827346
{
73837347
int32_t rhsConst = rhs->asIntConst()->getInt();
@@ -7453,18 +7417,8 @@ TR::Node *constrainLushr(OMR::ValuePropagation *vp, TR::Node *node)
74537417
return node;
74547418
constrainChildren(vp, node);
74557419

7456-
bool lhsGlobal, rhsGlobal;
7457-
TR::VPConstraint *lhs = vp->getConstraint(node->getFirstChild(), lhsGlobal);
7420+
bool rhsGlobal;
74587421
TR::VPConstraint *rhs = vp->getConstraint(node->getSecondChild(), rhsGlobal);
7459-
lhsGlobal &= rhsGlobal;
7460-
7461-
// Replace shift of constant zero with constant zero
7462-
if (lhs && lhs->asLongConst()
7463-
&& lhs->asLongConst()->getLong() == 0)
7464-
{
7465-
return vp->replaceNode(node, node->getFirstChild(), vp->_curTree);
7466-
}
7467-
74687422
if (rhs && rhs->asIntConst())
74697423
{
74707424
int32_t rhsConst = rhs->asIntConst()->getInt();

0 commit comments

Comments
 (0)