Skip to content

Commit

Permalink
[GR-58061] Fix oversize shift in IV scale computation
Browse files Browse the repository at this point in the history
PullRequest: graal/19861
  • Loading branch information
gergo- committed Jan 23, 2025
2 parents f6e5249 + a3b26f6 commit 98ee130
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -27,6 +27,9 @@
import static jdk.graal.compiler.nodeinfo.NodeCycles.CYCLES_IGNORED;
import static jdk.graal.compiler.nodeinfo.NodeSize.SIZE_IGNORED;

import org.junit.Ignore;
import org.junit.Test;

import jdk.graal.compiler.api.directives.GraalDirectives;
import jdk.graal.compiler.graph.NodeClass;
import jdk.graal.compiler.nodeinfo.NodeInfo;
Expand All @@ -47,10 +50,6 @@
import jdk.graal.compiler.nodes.util.GraphUtil;
import jdk.graal.compiler.options.OptionValues;
import jdk.graal.compiler.phases.OptimisticOptimizations;

import org.junit.Ignore;
import org.junit.Test;

import jdk.vm.ci.code.InstalledCode;
import jdk.vm.ci.meta.JavaKind;
import jdk.vm.ci.meta.ResolvedJavaMethod;
Expand Down Expand Up @@ -572,6 +571,22 @@ public void decrementUnsigned10() {
testCounted("decrementUnsignedSnippet", Integer.MAX_VALUE + 10, Integer.MAX_VALUE - 1, 2);
}

public static Result shiftLargeLongSnippet() {
Result ret = new Result();
for (long i = 1; GraalDirectives.injectIterationCount(11, i <= 10); i++) {
GraalDirectives.controlFlowAnchor();
long derived = i << 48;
ret.extremum = get(InductionVariable::extremumNode, InductionVariable::constantExtremum, InductionVariable::isConstantExtremum, derived);
}
ret.exitValue = 0;
return ret;
}

@Test
public void shiftLargeLong() {
testCounted("shiftLargeLongSnippet");
}

@NodeInfo(cycles = CYCLES_IGNORED, size = SIZE_IGNORED)
private static class IVPropertyNode extends FloatingNode implements LIRLowerable {
public static final NodeClass<IVPropertyNode> TYPE = NodeClass.create(IVPropertyNode.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -865,7 +865,7 @@ private static ValueNode calcScaleTo(Loop loop, ValueNode op, ValueNode base) {
if (op instanceof LeftShiftNode) {
LeftShiftNode shift = (LeftShiftNode) op;
if (shift.getX() == base && shift.getY().isConstant()) {
return ConstantNode.forIntegerStamp(base.stamp(NodeView.DEFAULT), 1 << shift.getY().asJavaConstant().asInt(), base.graph());
return ConstantNode.forIntegerStamp(base.stamp(NodeView.DEFAULT), 1L << shift.getY().asJavaConstant().asInt(), base.graph());
}
}
return null;
Expand Down

0 comments on commit 98ee130

Please sign in to comment.