Skip to content

Commit a35d0c6

Browse files
committed
[GR-69727] Enable vectorization of NormalMapping demo
PullRequest: graal/22446
2 parents d2c1c53 + 5b6e734 commit a35d0c6

File tree

11 files changed

+396
-73
lines changed

11 files changed

+396
-73
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2021, Oracle and/or its affiliates. All rights reserved.
3-
* Copyright (c) 2019, Arm Limited. All rights reserved.
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
43
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
54
*
65
* This code is free software; you can redistribute it and/or modify it
@@ -23,30 +22,31 @@
2322
* or visit www.oracle.com if you need additional information or have any
2423
* questions.
2524
*/
26-
package jdk.graal.compiler.core.aarch64.test;
2725

28-
import jdk.graal.compiler.lir.LIRInstruction;
29-
import org.junit.Test;
30-
31-
import java.util.function.Predicate;
26+
package jdk.graal.compiler.core.test;
3227

33-
public class AArch64FloatSqrtTest extends AArch64MatchRuleTest {
28+
import org.junit.Assert;
29+
import org.junit.Test;
3430

35-
private static final Predicate<LIRInstruction> p1 = op -> op.name().equals("FSQRT");
36-
private static final Predicate<LIRInstruction> p2 = op -> op.name().equals("AArch64Convert$FloatConvertOp");
31+
import jdk.graal.compiler.jtt.lang.Math_copySign;
32+
import jdk.graal.compiler.nodes.StructuredGraph;
33+
import jdk.graal.compiler.nodes.calc.FloatConvertNode;
3734

38-
public float floatSqrt(float f) {
39-
return (float) Math.sqrt(f);
35+
public class SqrtCanonicalizationTest extends GraalCompilerTest {
36+
public static float floatSqrt(float x) {
37+
return (float) Math.sqrt((double) x);
4038
}
4139

42-
private float[] input = {-1, 0f, -0f, Float.MAX_VALUE, Float.MIN_NORMAL, Float.MIN_VALUE, Float.NaN, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY};
40+
@Override
41+
protected void checkHighTierGraph(StructuredGraph graph) {
42+
super.checkHighTierGraph(graph);
43+
Assert.assertEquals("float conversions", 0, graph.getNodes().filter(FloatConvertNode.class).count());
44+
}
4345

4446
@Test
4547
public void testFloatSqrt() {
46-
for (float f : input) {
48+
for (float f : Math_copySign.FLOAT_VALUES) {
4749
test("floatSqrt", f);
48-
checkLIR("floatSqrt", p1, 1);
49-
checkLIR("floatSqrt", p2, 0);
5050
}
5151
}
5252
}

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/jtt/lang/Math_copySign.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,12 +24,13 @@
2424
*/
2525
package jdk.graal.compiler.jtt.lang;
2626

27-
import jdk.graal.compiler.jtt.JTTTest;
2827
import org.junit.Test;
2928

29+
import jdk.graal.compiler.jtt.JTTTest;
30+
3031
public class Math_copySign extends JTTTest {
3132

32-
private static final float[] floatValues = {
33+
public static final float[] FLOAT_VALUES = {
3334
123.4f,
3435
-56.7f,
3536
7e30f,
@@ -49,7 +50,7 @@ public class Math_copySign extends JTTTest {
4950
-0x0.0002P-126f
5051
};
5152

52-
private static final double[] doubleValues = {
53+
public static final double[] DOUBLE_VALUES = {
5354
123.4d,
5455
-56.7d,
5556
7e30d,
@@ -75,8 +76,8 @@ public static float floatCopySign(float magnitude, float sign) {
7576

7677
@Test
7778
public void testFloatCopySign() {
78-
for (float magnitude : floatValues) {
79-
for (float sign : floatValues) {
79+
for (float magnitude : FLOAT_VALUES) {
80+
for (float sign : FLOAT_VALUES) {
8081
runTest("floatCopySign", magnitude, sign);
8182
}
8283
}
@@ -88,8 +89,8 @@ public static double doubleCopySign(double magnitude, double sign) {
8889

8990
@Test
9091
public void testDoubleCopySign() {
91-
for (double magnitude : doubleValues) {
92-
for (double sign : doubleValues) {
92+
for (double magnitude : DOUBLE_VALUES) {
93+
for (double sign : DOUBLE_VALUES) {
9394
runTest("doubleCopySign", magnitude, sign);
9495
}
9596
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/asm/amd64/AMD64Assembler.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,8 +2021,10 @@ public void emit(AMD64Assembler asm, AVXSize size, Register dst, AMD64Address sr
20212021
*/
20222022
public static final class EvexRMIOp extends VexRMIOp {
20232023
// @formatter:off
2024-
public static final EvexRMIOp EVFPCLASSSS = new EvexRMIOp("EVFPCLASS", VEXPrefixConfig.P_66, VEXPrefixConfig.M_0F3A, VEXPrefixConfig.W0, 0x67, VEXOpAssertion.MASK_XMM_AVX512DQ_128, EVEXTuple.T1S_32BIT, VEXPrefixConfig.W0);
2025-
public static final EvexRMIOp EVFPCLASSSD = new EvexRMIOp("EVFPCLASD", VEXPrefixConfig.P_66, VEXPrefixConfig.M_0F3A, VEXPrefixConfig.W1, 0x67, VEXOpAssertion.MASK_XMM_AVX512DQ_128, EVEXTuple.T1S_64BIT, VEXPrefixConfig.W1);
2024+
public static final EvexRMIOp EVFPCLASSSS = new EvexRMIOp("EVFPCLASSSS", VEXPrefixConfig.P_66, VEXPrefixConfig.M_0F3A, VEXPrefixConfig.W0, 0x67, VEXOpAssertion.MASK_XMM_AVX512DQ_128, EVEXTuple.T1S_32BIT, VEXPrefixConfig.W0);
2025+
public static final EvexRMIOp EVFPCLASSSD = new EvexRMIOp("EVFPCLASSSD", VEXPrefixConfig.P_66, VEXPrefixConfig.M_0F3A, VEXPrefixConfig.W1, 0x67, VEXOpAssertion.MASK_XMM_AVX512DQ_128, EVEXTuple.T1S_64BIT, VEXPrefixConfig.W1);
2026+
public static final EvexRMIOp EVFPCLASSPS = new EvexRMIOp("EVFPCLASSPS", VEXPrefixConfig.P_66, VEXPrefixConfig.M_0F3A, VEXPrefixConfig.W0, 0x66, VEXOpAssertion.MASK_XMM_AVX512DQ_VL, EVEXTuple.T1F_32BIT, VEXPrefixConfig.W0);
2027+
public static final EvexRMIOp EVFPCLASSPD = new EvexRMIOp("EVFPCLASSPD", VEXPrefixConfig.P_66, VEXPrefixConfig.M_0F3A, VEXPrefixConfig.W1, 0x66, VEXOpAssertion.MASK_XMM_AVX512DQ_VL, EVEXTuple.T1F_64BIT, VEXPrefixConfig.W1);
20262028
// @formatter:on
20272029

20282030
private EvexRMIOp(String opcode, int pp, int mmmmm, int w, int op, VEXOpAssertion assertion, EVEXTuple evexTuple, int wEvex) {
@@ -6278,6 +6280,14 @@ public final void kshiftrw(Register dst, Register src, int imm8) {
62786280
VexMaskRRIOp.KSHIFTRW.emit(this, AVXSize.XMM, dst, src, imm8);
62796281
}
62806282

6283+
public final void ktestb(Register src1, Register src2) {
6284+
VexRROp.KTESTB.emit(this, AVXSize.XMM, src1, src2);
6285+
}
6286+
6287+
public final void ktestw(Register src1, Register src2) {
6288+
VexRROp.KTESTW.emit(this, AVXSize.XMM, src1, src2);
6289+
}
6290+
62816291
public final void ktestd(Register src1, Register src2) {
62826292
VexRROp.KTESTD.emit(this, AVXSize.XMM, src1, src2);
62836293
}

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/aarch64/AArch64NodeMatchRules.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -34,7 +34,6 @@
3434
import jdk.graal.compiler.core.common.LIRKind;
3535
import jdk.graal.compiler.core.common.NumUtil;
3636
import jdk.graal.compiler.core.common.calc.CanonicalCondition;
37-
import jdk.graal.compiler.core.common.calc.FloatConvert;
3837
import jdk.graal.compiler.core.gen.NodeMatchRules;
3938
import jdk.graal.compiler.core.match.ComplexMatchResult;
4039
import jdk.graal.compiler.core.match.MatchRule;
@@ -58,7 +57,6 @@
5857
import jdk.graal.compiler.nodes.calc.AddNode;
5958
import jdk.graal.compiler.nodes.calc.AndNode;
6059
import jdk.graal.compiler.nodes.calc.BinaryNode;
61-
import jdk.graal.compiler.nodes.calc.FloatConvertNode;
6260
import jdk.graal.compiler.nodes.calc.IntegerConvertNode;
6361
import jdk.graal.compiler.nodes.calc.IntegerLessThanNode;
6462
import jdk.graal.compiler.nodes.calc.LeftShiftNode;
@@ -894,19 +892,6 @@ public ComplexMatchResult checkNegativeAndBranch(IfNode root, IntegerLessThanNod
894892
return null;
895893
}
896894

897-
/**
898-
* Goal: Use directly AArch64's single-precision fsqrt op.
899-
*/
900-
@MatchRule("(FloatConvert=a (Sqrt (FloatConvert=b c)))")
901-
public final ComplexMatchResult floatSqrt(FloatConvertNode a, FloatConvertNode b, ValueNode c) {
902-
if (isNumericFloat(a, c)) {
903-
if (a.getFloatConvert() == FloatConvert.D2F && b.getFloatConvert() == FloatConvert.F2D) {
904-
return builder -> getArithmeticLIRGenerator().emitMathSqrt(operand(c));
905-
}
906-
}
907-
return null;
908-
}
909-
910895
@MatchRule("(Conditional (IntegerBelow x y) Constant=cm1 (Conditional (IntegerEquals x y) Constant=c0 Constant=c1))")
911896
public ComplexMatchResult normalizedIntegerCompare(ValueNode x, ValueNode y, ConstantNode cm1, ConstantNode c0, ConstantNode c1) {
912897
if (cm1.getStackKind() == JavaKind.Int && cm1.asJavaConstant().asInt() == -1 && c0.getStackKind() == JavaKind.Int && c0.asJavaConstant().asInt() == 0 && c1.getStackKind() == JavaKind.Int &&

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/common/calc/FloatConvert.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,14 @@ public int getInputBits() {
9393
return inputBits;
9494
}
9595

96+
/**
97+
* Returns {@code true} if this operation's input bit size is strictly larger than its output
98+
* bit size.
99+
*/
100+
public boolean isNarrowing() {
101+
return inputBits > reverse().inputBits;
102+
}
103+
96104
/**
97105
* Returns the conversion operation corresponding to a conversion from {@code from} to
98106
* {@code to}. Returns {@code null} if the given stamps don't correspond to a conversion

0 commit comments

Comments
 (0)