11/*
2- * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2023, 2024, 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
@@ -64,7 +64,7 @@ public void runTests() throws Exception {
6464 IRNode .OR_REDUCTION_V , "> 0" ,},
6565 applyIfCPUFeatureOr = {"avx2" , "true" })
6666 static long test1 (int [] data , long sum ) {
67- for (int i = 0 ; i < data .length ; i ++ ) {
67+ for (int i = 0 ; i < data .length ; i += 2 ) {
6868 // Mixing int and long ops means we only end up allowing half of the int
6969 // loads in one pack, and we have two int packs. The first pack has one
7070 // of the pairs missing because of the store, which creates a dependency.
@@ -77,6 +77,17 @@ static long test1(int[] data, long sum) {
7777 int v = data [i ]; // int read
7878 data [0 ] = 0 ; // ruin the first pack
7979 sum |= v ; // long reduction (and implicit cast from int to long)
80+
81+ // This example used to rely on that reductions were ignored in SuperWord::unrolling_analysis,
82+ // and hence the largest data type in the loop was the ints. This would then unroll the doubles
83+ // for twice the vector length, and this resulted in us having twice as many packs. Because of
84+ // the store "data[0] = 0", the first packs were destroyed, since they do not have power of 2
85+ // size.
86+ // Now, we no longer ignore reductions, and now we unroll half as much before SuperWord. This
87+ // means we would only get one pack per operation, and that one would get ruined, and we have
88+ // no vectorization. We now ensure there are again 2 packs per operation with a 2x hand unroll.
89+ int v2 = data [i + 1 ];
90+ sum |= v2 ;
8091 }
8192 return sum ;
8293 }
0 commit comments