From c27a8c8c8b867e6812b905f6154762802a498dbd Mon Sep 17 00:00:00 2001 From: Emanuel Peter Date: Tue, 13 Aug 2024 05:52:58 +0000 Subject: [PATCH] 8338124: C2 SuperWord: MulAddS2I input permutation still partially broken after JDK-8333840 Reviewed-by: chagedorn, thartmann, kvn --- src/hotspot/share/opto/superword.cpp | 2 +- .../loopopts/superword/TestMulAddS2I.java | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/hotspot/share/opto/superword.cpp b/src/hotspot/share/opto/superword.cpp index 2a43d2ec0af4a..bb5fed78b0274 100644 --- a/src/hotspot/share/opto/superword.cpp +++ b/src/hotspot/share/opto/superword.cpp @@ -2270,7 +2270,7 @@ Node_List* PackSet::strided_pack_input_at_index_or_null(const Node_List* pack, c return nullptr; // size mismatch } - for (uint i = 1; i < pack->size(); i++) { + for (uint i = 0; i < pack->size(); i++) { if (pack->at(i)->in(index) != pack_in->at(i * stride + offset)) { return nullptr; // use-def mismatch } diff --git a/test/hotspot/jtreg/compiler/loopopts/superword/TestMulAddS2I.java b/test/hotspot/jtreg/compiler/loopopts/superword/TestMulAddS2I.java index e0f073c7f8f7d..fb99fc5983a16 100644 --- a/test/hotspot/jtreg/compiler/loopopts/superword/TestMulAddS2I.java +++ b/test/hotspot/jtreg/compiler/loopopts/superword/TestMulAddS2I.java @@ -53,6 +53,7 @@ public class TestMulAddS2I { static final int[] GOLDEN_J; static final int[] GOLDEN_K; static final int[] GOLDEN_L; + static final int[] GOLDEN_M; static { for (int i = 0; i < RANGE; i++) { @@ -71,6 +72,7 @@ public class TestMulAddS2I { GOLDEN_J = testj(new int[ITER]); GOLDEN_K = testk(new int[ITER]); GOLDEN_L = testl(new int[ITER]); + GOLDEN_M = testm(new int[ITER]); } @@ -80,7 +82,7 @@ public static void main(String[] args) { } @Run(test = {"testa", "testb", "testc", "testd", "teste", "testf", "testg", "testh", - "testi", "testj", "testk", "testl"}) + "testi", "testj", "testk", "testl", "testm"}) @Warmup(0) public static void run() { compare(testa(), GOLDEN_A, "testa"); @@ -95,6 +97,7 @@ public static void run() { compare(testj(new int[ITER]), GOLDEN_J, "testj"); compare(testk(new int[ITER]), GOLDEN_K, "testk"); compare(testl(new int[ITER]), GOLDEN_L, "testl"); + compare(testm(new int[ITER]), GOLDEN_M, "testm"); } public static void compare(int[] out, int[] golden, String name) { @@ -299,4 +302,17 @@ public static int[] testl(int[] out) { return out; } + @Test + @IR(counts = {IRNode.MUL_ADD_S2I, "> 0"}, + applyIfCPUFeatureOr = {"sse2", "true", "asimd", "true"}) + @IR(counts = {IRNode.MUL_ADD_VS2VI, "= 0"}) + public static int[] testm(int[] out) { + for (int i = 0; i < ITER-4; i+=4) { + // Unrolled, with some swaps that prevent vectorization. + out[i+0] += ((sArr1[2*i+0] * sArr2[2*i+1]) + (sArr1[2*i+1] * sArr2[2*i+0])); // bad + out[i+1] += ((sArr1[2*i+2] * sArr2[2*i+2]) + (sArr1[2*i+3] * sArr2[2*i+3])); // ok + // 2-element gap + } + return out; + } }