forked from oracle/graal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AArch64: Merge shift pair and integral narrow into add/sub
This patch implements two types of match rules like C2. 1. Merge shift pair into add/sub. 2. Merge integral narrow into add/sub. E.g. Below code is generated for `x + (((y << 56) >> 56) << 3)` lsl x0, x3, oracle#56 asr x0, x0, oracle#56 add x0, x2, x0, lsl oracle#3 After this patch, generated assembly above can be optimized to below: add x0, x2, w3, sxtb oracle#3 The test cases in this patch can show more details about those match rules. TEST_IMG: ubuntu/graal-test TEST_CMD: safe ./projects/jdk/graal-build-test.sh \ TEST_CMD: --suite substratevm \ TEST_CMD: --tags "fullbuild,test,helloworld" \ TEST_CMD: --refspec $GERRIT_REFSPEC TEST_CMD: TEST_CMD: safe ./projects/jdk/graal-build-test.sh \ TEST_CMD: --suite compiler \ TEST_CMD: --refspec $GERRIT_REFSPEC Change-Id: I71b392eefd990d2ad838afc06fccebb3438e467c Jira: ENTLLT-2455 Jira: ENTLLT-1927
- Loading branch information
Eric Liu
committed
Feb 19, 2020
1 parent
998163d
commit 3a03e19
Showing
7 changed files
with
695 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
238 changes: 238 additions & 0 deletions
238
...h64.test/src/org/graalvm/compiler/core/aarch64/test/AArch64MergeExtendWithAddSubTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,238 @@ | ||
/* | ||
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. | ||
* Copyright (c) 2020, Arm Limited. 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 | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Oracle designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Oracle in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
*/ | ||
package org.graalvm.compiler.core.aarch64.test; | ||
|
||
import org.graalvm.compiler.lir.LIRInstruction; | ||
import org.graalvm.compiler.lir.aarch64.AArch64ArithmeticOp; | ||
import org.junit.Test; | ||
|
||
import java.util.function.Predicate; | ||
|
||
public class AArch64MergeExtendWithAddSubTest extends AArch64MatchRuleTest { | ||
|
||
private static final Predicate<LIRInstruction> PRED_EXTEND_ADD_SHIFT = op -> (op instanceof AArch64ArithmeticOp.ExtendedAddSubShiftOp && op.name().equals("ADD")); | ||
private static final Predicate<LIRInstruction> PRED_EXTEND_SUB_SHIFT = op -> (op instanceof AArch64ArithmeticOp.ExtendedAddSubShiftOp && op.name().equals("SUB")); | ||
|
||
private static final Long[] LONG_VALUES = {-1L, 0L, 0x1234567812345678L, 0xFFFFFFFFL, 0x12L, 0x1234L, Long.MIN_VALUE, Long.MAX_VALUE}; | ||
private static final Integer[] INT_VALUES = {-1, 0, 0x1234, 0x12345678, Integer.MIN_VALUE, Integer.MAX_VALUE}; | ||
|
||
private <T> void predicateExist(String[] testCases, T[] values, Predicate<LIRInstruction> predicate) { | ||
for (String t : testCases) { | ||
for (T value : values) { | ||
test(t, value, value); | ||
checkLIR(t, predicate, 1); | ||
} | ||
} | ||
} | ||
|
||
public long addI2LShift(long x, long y) { | ||
int z = (int) y; | ||
return x + (((long) z) << 3); | ||
} | ||
|
||
public long addB2LShift(long x, long y) { | ||
byte z = (byte) y; | ||
return x + (((long) z) << 2); | ||
} | ||
|
||
public long addC2LShift(long x, long y) { | ||
char z = (char) y; | ||
return x + (((long) z) << 1); | ||
} | ||
|
||
public long addS2LShift(long x, long y) { | ||
short z = (short) y; | ||
return x + (((long) z) << 4); | ||
} | ||
|
||
public long subI2LShift(long x, long y) { | ||
int z = (int) y; | ||
return x - (((long) z) << 1); | ||
} | ||
|
||
public long subB2LShift(long x, long y) { | ||
byte z = (byte) y; | ||
return x - (((long) z) << 2); | ||
} | ||
|
||
public long subC2LShift(long x, long y) { | ||
char z = (char) y; | ||
return x - (((long) z) << 3); | ||
} | ||
|
||
public long subS2LShift(long x, long y) { | ||
short z = (short) y; | ||
return x - (((long) z) << 4); | ||
} | ||
|
||
public long addI2L(long x, long y) { | ||
int z = (int) y; | ||
return x + ((long) z); | ||
} | ||
|
||
public long addB2L(long x, long y) { | ||
byte z = (byte) y; | ||
return x + ((long) z); | ||
} | ||
|
||
public long addC2L(long x, long y) { | ||
char z = (char) y; | ||
return x + ((long) z); | ||
} | ||
|
||
public long addS2L(long x, long y) { | ||
short z = (short) y; | ||
return x + ((long) z); | ||
} | ||
|
||
public int addB2S(int x, int y) { | ||
short a = (short) x; | ||
byte b = (byte) y; | ||
return a + ((short) b); | ||
} | ||
|
||
public int addB2SShift(int x, int y) { | ||
short a = (short) x; | ||
byte b = (byte) y; | ||
return a + (((short) b) << 2); | ||
} | ||
|
||
public int addB2I(int x, int y) { | ||
byte z = (byte) y; | ||
return x + ((int) z); | ||
} | ||
|
||
public int addB2IShift(int x, int y) { | ||
byte z = (byte) y; | ||
return x + (((int) z) << 3); | ||
} | ||
|
||
public int addS2I(int x, int y) { | ||
short z = (short) y; | ||
return x + ((int) z); | ||
} | ||
|
||
public int addS2IShift(int x, int y) { | ||
short z = (short) y; | ||
return x + (((int) z) << 2); | ||
} | ||
|
||
public int addC2I(int x, int y) { | ||
char z = (char) y; | ||
return x + ((int) z); | ||
} | ||
|
||
public int addC2IShift(int x, int y) { | ||
char z = (char) y; | ||
return x + (((int) z) << 1); | ||
} | ||
|
||
@Test | ||
public void mergeSignExtendIntoAdd() { | ||
predicateExist(new String[]{"addB2S", "addB2I", "addS2I", "addC2I"}, INT_VALUES, PRED_EXTEND_ADD_SHIFT); | ||
predicateExist(new String[]{"addB2L", "addC2L", "addI2L", "addS2L"}, LONG_VALUES, PRED_EXTEND_ADD_SHIFT); | ||
} | ||
|
||
@Test | ||
public void mergeSignExtendShiftIntoAdd() { | ||
predicateExist(new String[]{"addB2SShift", "addB2IShift", "addS2IShift", "addC2IShift"}, INT_VALUES, PRED_EXTEND_ADD_SHIFT); | ||
predicateExist(new String[]{"addB2LShift", "addC2LShift", "addI2LShift", "addS2LShift"}, LONG_VALUES, PRED_EXTEND_ADD_SHIFT); | ||
} | ||
|
||
public long subI2L(long x, long y) { | ||
int z = (int) y; | ||
return x - ((long) z); | ||
} | ||
|
||
public long subB2L(long x, long y) { | ||
byte z = (byte) y; | ||
return x - ((long) z); | ||
} | ||
|
||
public long subC2L(long x, long y) { | ||
char z = (char) y; | ||
return x - ((long) z); | ||
} | ||
|
||
public long subS2L(long x, long y) { | ||
short z = (short) y; | ||
return x - ((long) z); | ||
} | ||
|
||
public int subB2S(int x, int y) { | ||
short a = (short) x; | ||
byte b = (byte) y; | ||
return a - ((short) b); | ||
} | ||
|
||
public int subB2SShift(int x, int y) { | ||
short a = (short) x; | ||
byte b = (byte) y; | ||
return a - (((short) b) << 2); | ||
} | ||
|
||
public int subB2I(int x, int y) { | ||
byte z = (byte) y; | ||
return x - ((int) z); | ||
} | ||
|
||
public int subB2IShift(int x, int y) { | ||
byte z = (byte) y; | ||
return x - (((int) z) << 3); | ||
} | ||
|
||
public int subS2I(int x, int y) { | ||
short z = (short) y; | ||
return x - ((int) z); | ||
} | ||
|
||
public int subS2IShift(int x, int y) { | ||
short z = (short) y; | ||
return x - (((int) z) << 2); | ||
} | ||
|
||
public int subC2I(int x, int y) { | ||
char z = (char) y; | ||
return x - ((int) z); | ||
} | ||
|
||
public int subC2IShift(int x, int y) { | ||
char z = (char) y; | ||
return x - (((int) z) << 1); | ||
} | ||
|
||
@Test | ||
public void mergeSignExtendShiftIntoSub() { | ||
predicateExist(new String[]{"subB2SShift", "subB2IShift", "subS2IShift", "subC2IShift"}, INT_VALUES, PRED_EXTEND_SUB_SHIFT); | ||
predicateExist(new String[]{"subB2LShift", "subC2LShift", "subI2LShift", "subS2LShift"}, LONG_VALUES, PRED_EXTEND_SUB_SHIFT); | ||
} | ||
|
||
@Test | ||
public void mergeSignExtendIntoSub() { | ||
predicateExist(new String[]{"subB2S", "subB2I", "subS2I", "subC2I"}, INT_VALUES, PRED_EXTEND_SUB_SHIFT); | ||
predicateExist(new String[]{"subB2L", "subC2L", "subI2L", "subS2L"}, LONG_VALUES, PRED_EXTEND_SUB_SHIFT); | ||
} | ||
} |
Oops, something went wrong.