Skip to content

Commit

Permalink
[GR-54543] Derived offset iv: properly implement isConstantStride for…
Browse files Browse the repository at this point in the history
… masked negate strides.

PullRequest: graal/17929
  • Loading branch information
davleopo committed Jun 6, 2024
2 parents d9445f8 + b3cf023 commit 5f82a2a
Showing 1 changed file with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ public boolean isConstantInit() {

@Override
public boolean isConstantStride() {
if (isMaskedNegateStride()) {
if (base.isConstantStride()) {
try {
LoopUtility.multiplyExact(IntegerStamp.getBits(offset.stamp(NodeView.DEFAULT)), base.constantStride(), -1);
return true;
} catch (ArithmeticException e) {
return false;
}
}
}
return base.isConstantStride();
}

Expand All @@ -103,12 +113,31 @@ public long constantStride() {
}

private long constantStrideSafe() throws ArithmeticException {
if (value instanceof SubNode && base.valueNode() == value.getY()) {
if (isMaskedNegateStride()) {
return LoopUtility.multiplyExact(IntegerStamp.getBits(offset.stamp(NodeView.DEFAULT)), base.constantStride(), -1);
}
return base.constantStride();
}

/**
* Determine if the current induction variable's stride is actually one that represents a
* negation instead of a normal offset calculation. For example
*
* <pre>
* int i = 0;
* while (i < limit) {
* int reversIv = off - i;
* i++;
* }
* </pre>
*
* here {@code reverseIv} stride node is actually {@code i} negated since the IV is not
* {@code i op off} but {@code off op i} where {@code op} is a subtraction.
*/
private boolean isMaskedNegateStride() {
return value instanceof SubNode && base.valueNode() == value.getY();
}

@Override
public boolean isConstantExtremum() {
try {
Expand Down

0 comments on commit 5f82a2a

Please sign in to comment.