Skip to content

Commit

Permalink
Optimize arrays with stable elements
Browse files Browse the repository at this point in the history
- array elements are considered stable if their values are constant
  unless they are zero
  • Loading branch information
gita-omr committed Nov 26, 2021
1 parent f76321a commit 447964f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
10 changes: 9 additions & 1 deletion compiler/env/OMRKnownObjectTable.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2020 IBM Corp. and others
* Copyright (c) 2000, 2021 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -86,6 +86,14 @@ OMR::KnownObjectTable::isArrayWithConstantElements(Index index)
return false;
}

bool
OMR::KnownObjectTable::isArrayWithStableElements(Index index)
{
TR_ASSERT(index != UNKNOWN && 0 <= index && index < self()->getEndIndex(), "isArrayWithStableElements(%d): index must be in range 0..%d", index, self()->getEndIndex());
return false;
}


uintptr_t *
OMR::KnownObjectTable::getPointerLocation(Index index)
{
Expand Down
6 changes: 5 additions & 1 deletion compiler/env/OMRKnownObjectTable.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2020 IBM Corp. and others
* Copyright (c) 2000, 2021 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -87,6 +87,10 @@ class OMR_EXTENSIBLE KnownObjectTable
// API for checking if an known object is an array with immutable elements
bool isArrayWithConstantElements(Index index);

// API for checking if an known object is an array whose elements are immutable
// unless they are zero
bool isArrayWithStableElements(Index index);

Index getOrCreateIndexAt(uintptr_t *objectReferenceLocation);
Index getOrCreateIndexAt(uintptr_t *objectReferenceLocation, bool isArrayWithConstantElements);
Index getExistingIndexAt(uintptr_t *objectReferenceLocation);
Expand Down
7 changes: 7 additions & 0 deletions compiler/optimizer/VPConstraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,13 @@ bool TR::VPKnownObject::isArrayWithConstantElements(TR::Compilation * comp)
return knot->isArrayWithConstantElements(_index);
}

bool TR::VPKnownObject::isArrayWithStableElements(TR::Compilation * comp)
{
TR::KnownObjectTable *knot = comp->getKnownObjectTable();
TR_ASSERT(knot, "TR::KnownObjectTable should not be null");
return knot->isArrayWithStableElements(_index);
}

TR_YesNoMaybe TR::VPClassType::isArray()
{
if (_sig[0] == '[')
Expand Down
5 changes: 3 additions & 2 deletions compiler/optimizer/VPConstraint.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2020 IBM Corp. and others
* Copyright (c) 2000, 2021 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -960,7 +960,8 @@ class VPKnownObject : public TR::VPFixedClass
virtual TR::VPConstraint *intersect1(TR::VPConstraint *other, OMR::ValuePropagation *vp);

virtual TR_YesNoMaybe isJavaLangClassObject();
virtual bool isArrayWithConstantElements(TR::Compilation * comp);
bool isArrayWithConstantElements(TR::Compilation * comp);
bool isArrayWithStableElements(TR::Compilation * comp);

virtual bool mustBeEqual(TR::VPConstraint *other, OMR::ValuePropagation *vp);
virtual bool mustBeNotEqual(TR::VPConstraint *other, OMR::ValuePropagation *vp);
Expand Down
2 changes: 1 addition & 1 deletion compiler/optimizer/VPHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ static bool tryFoldCompileTimeLoad(
// Invalidate alias info so that it can be recomputed in the next optimization that needs it
vp->optimizer()->setAliasSetsAreValid(false);
}
else
else if (!constraint->getKnownObject()->isArrayWithStableElements(vp->comp()))
break;
}

Expand Down

0 comments on commit 447964f

Please sign in to comment.