Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8358951

C2: IntVector.fromMemorySegment does not vectorize with byte[] (performance regression)

XMLWordPrintable

      At the beginning of JDK23, we could load Vectors from mismatching arrays, e.g. IntVector from a byte[] via IntVector.fromMemorySegment, and that would vectorize.

      Test2.java is a regression from JDK-8329555 in JDK 23 b20.

      Test3.java seems to be a regression from JDK-8339299.

      We should add thorough IR tests for all these combinations to ensure we do not get such regressions any more.

      ---------------- Original Report ----------------------

      Please see the attached Test.java

      It seems that MemorySegment backed by int[] or native memory do indeed produce vector code. But not with byte[] backed memory. I have not investigated other primitive array types yet.

      It could be good to investigate the combination of all Vector types with all backing memory types. Write an IR test and a benchmark for all. To go even further: what happens when you combine different backing memory?

      This kind of investigation would be expecially important if we want replace some intrinsics that are currently written with platform specifc assembly, and replace them with Java code that uses MemorySegment and the Vector API.

      I ran the experiment like this:

      [empeter@emanuel bin]$ ./java -XX:CompileCommand=compileonly,Test::testI -XX:CompileCommand=printcompilation,Test::* -Xbatch -XX:+PrintIdeal Test.java | grep LoadVector
       1388 LoadVector === 1353 7 1387 |543 [[ 1088 1413 1153 765 1215 1233 887 1136 1122 902 ]] @int[int:>=0] (java/lang/Cloneable,java/io/Serializable):NotNull:exact+any *, idx=16; mismatched #vectord<I,2> !jvms: ScopedMemoryAccess::loadFromMemorySegmentScopedInternal @ bci:29 (line 358) ScopedMemoryAccess::loadFromMemorySegment @ bci:14 (line 335) IntVector::fromMemorySegment0Template @ bci:33 (line 3564) Int64Vector::fromMemorySegment0 @ bci:3 (line 957) IntVector::fromMemorySegment @ bci:31 (line 3196) Test::testI @ bci:10 (line 28)
      [empeter@emanuel bin]$ ./java -XX:CompileCommand=compileonly,Test::testB -XX:CompileCommand=printcompilation,Test::* -Xbatch -XX:+PrintIdeal Test.java | grep LoadVector
      [empeter@emanuel bin]$ ./java -XX:CompileCommand=compileonly,Test::testN -XX:CompileCommand=printcompilation,Test::* -Xbatch -XX:+PrintIdeal Test.java | grep LoadVector
       1237 LoadVector === 1205 7 1235 [[ 814 1263 1049 692 1063 1080 1015 829 ]] @rawptr:BotPTR, idx=Raw; mismatched #vectord<I,2> (does not depend only on test, raw access) !jvms: ScopedMemoryAccess::loadFromMemorySegmentScopedInternal @ bci:29 (line 358) ScopedMemoryAccess::loadFromMemorySegment @ bci:14 (line 335) IntVector::fromMemorySegment0Template @ bci:33 (line 3564) Int64Vector::fromMemorySegment0 @ bci:3 (line 957) IntVector::fromMemorySegment @ bci:31 (line 3196) Test::testN @ bci:10 (line 38)
      [empeter@emanuel bin]$ ./java -XX:CompileCommand=compileonly,Test::test* -XX:CompileCommand=printcompilation,Test::* -Xbatch -XX:+PrintIdeal Test.java | grep LoadVector
       1196 LoadVector === 1193 1194 1191 [[ 809 1230 1042 1068 1048 672 1028 994 794 ]] @rawptr:BotPTR, idx=Raw; mismatched #vectord<I,2> (does not depend only on test, raw access) !jvms: ScopedMemoryAccess::loadFromMemorySegmentScopedInternal @ bci:29 (line 358) ScopedMemoryAccess::loadFromMemorySegment @ bci:14 (line 335) IntVector::fromMemorySegment0Template @ bci:33 (line 3564) Int64Vector::fromMemorySegment0 @ bci:3 (line 957) IntVector::fromMemorySegment @ bci:31 (line 3196) Test::testI @ bci:10 (line 28)
       1196 LoadVector === 1193 1194 1191 [[ 809 1230 1042 1068 1048 672 1028 994 794 ]] @rawptr:BotPTR, idx=Raw; mismatched #vectord<I,2> (does not depend only on test, raw access) !jvms: ScopedMemoryAccess::loadFromMemorySegmentScopedInternal @ bci:29 (line 358) ScopedMemoryAccess::loadFromMemorySegment @ bci:14 (line 335) IntVector::fromMemorySegment0Template @ bci:33 (line 3564) Int64Vector::fromMemorySegment0 @ bci:3 (line 957) IntVector::fromMemorySegment @ bci:31 (line 3196) Test::testB @ bci:10 (line 33)
       1196 LoadVector === 1193 1194 1191 [[ 809 1230 1042 1068 1048 672 1028 994 794 ]] @rawptr:BotPTR, idx=Raw; mismatched #vectord<I,2> (does not depend only on test, raw access) !jvms: ScopedMemoryAccess::loadFromMemorySegmentScopedInternal @ bci:29 (line 358) ScopedMemoryAccess::loadFromMemorySegment @ bci:14 (line 335) IntVector::fromMemorySegment0Template @ bci:33 (line 3564) Int64Vector::fromMemorySegment0 @ bci:3 (line 957) IntVector::fromMemorySegment @ bci:31 (line 3196) Test::testN @ bci:10 (line 38)
      [empeter@emanuel bin]$ ./java -XX:CompileCommand=compileonly,Test::testI -XX:CompileCommand=printcompilation,Test::* -Xbatch -XX:+PrintIdeal Test.java | grep StoreVector
       1039 ConP === 0 [[ 1088 1233 1215 1153 1136 1122 ]] #jdk/incubator/vector/IntVector$$Lambda+0x000000000a0fa4c8 (jdk/internal/vm/vector/VectorSupport$StoreVectorOperation):exact * Oop:jdk/incubator/vector/IntVector$$Lambda+0x000000000a0fa4c8 (jdk/internal/vm/vector/VectorSupport$StoreVectorOperation):exact *
       1413 StoreVector === 1313 7 1410 1388 |1212 [[ 1412 ]] @int[int:>=0] (java/lang/Cloneable,java/io/Serializable):NotNull:exact+any *, idx=16; mismatched Memory: @int[int:>=0] (java/lang/Cloneable,java/io/Serializable):NotNull:exact+any *, idx=16; !jvms: ScopedMemoryAccess::storeIntoMemorySegmentScopedInternal @ bci:29 (line 441) ScopedMemoryAccess::storeIntoMemorySegment @ bci:15 (line 418) IntVector::intoMemorySegment0 @ bci:32 (line 3663) IntVector::intoMemorySegment @ bci:44 (line 3443) Test::testI @ bci:22 (line 29)
      [empeter@emanuel bin]$ ./java -XX:CompileCommand=compileonly,Test::testB -XX:CompileCommand=printcompilation,Test::* -Xbatch -XX:+PrintIdeal Test.java | grep StoreVector
       1039 ConP === 0 [[ 1268 1233 1215 1153 1136 1122 1088 ]] #jdk/incubator/vector/IntVector$$Lambda+0x000000006d0fa4c8 (jdk/internal/vm/vector/VectorSupport$StoreVectorOperation):exact * Oop:jdk/incubator/vector/IntVector$$Lambda+0x000000006d0fa4c8 (jdk/internal/vm/vector/VectorSupport$StoreVectorOperation):exact *
      [empeter@emanuel bin]$ ./java -XX:CompileCommand=compileonly,Test::testN -XX:CompileCommand=printcompilation,Test::* -Xbatch -XX:+PrintIdeal Test.java | grep StoreVector
        966 ConP === 0 [[ 1015 1080 1063 1049 ]] #jdk/incubator/vector/IntVector$$Lambda+0x000000001c0fa4c8 (jdk/internal/vm/vector/VectorSupport$StoreVectorOperation):exact * Oop:jdk/incubator/vector/IntVector$$Lambda+0x000000001c0fa4c8 (jdk/internal/vm/vector/VectorSupport$StoreVectorOperation):exact *
       1263 StoreVector === 1169 7 1259 1237 [[ 1262 ]] @rawptr:BotPTR, idx=Raw; mismatched Memory: @rawptr:BotPTR, idx=Raw; !jvms: ScopedMemoryAccess::storeIntoMemorySegmentScopedInternal @ bci:29 (line 441) ScopedMemoryAccess::storeIntoMemorySegment @ bci:15 (line 418) IntVector::intoMemorySegment0 @ bci:32 (line 3663) IntVector::intoMemorySegment @ bci:44 (line 3443) Test::testN @ bci:22 (line 39)
      [empeter@emanuel bin]$ ./java -XX:CompileCommand=compileonly,Test::test* -XX:CompileCommand=printcompilation,Test::* -Xbatch -XX:+PrintIdeal Test.java | grep StoreVector
        946 ConP === 0 [[ 1068 994 1048 1042 1028 ]] #jdk/incubator/vector/IntVector$$Lambda+0x00000000220fa4c8 (jdk/internal/vm/vector/VectorSupport$StoreVectorOperation):exact * Oop:jdk/incubator/vector/IntVector$$Lambda+0x00000000220fa4c8 (jdk/internal/vm/vector/VectorSupport$StoreVectorOperation):exact *
       1230 StoreVector === 1225 1226 1223 1196 [[ 1229 ]] @rawptr:BotPTR, idx=Raw; mismatched Memory: @rawptr:BotPTR, idx=Raw; !jvms: ScopedMemoryAccess::storeIntoMemorySegmentScopedInternal @ bci:29 (line 441) ScopedMemoryAccess::storeIntoMemorySegment @ bci:15 (line 418) IntVector::intoMemorySegment0 @ bci:32 (line 3663) IntVector::intoMemorySegment @ bci:44 (line 3443) Test::testI @ bci:22 (line 29)
        946 ConP === 0 [[ 1068 994 1048 1042 1028 ]] #jdk/incubator/vector/IntVector$$Lambda+0x00000000220fa4c8 (jdk/internal/vm/vector/VectorSupport$StoreVectorOperation):exact * Oop:jdk/incubator/vector/IntVector$$Lambda+0x00000000220fa4c8 (jdk/internal/vm/vector/VectorSupport$StoreVectorOperation):exact *
       1230 StoreVector === 1225 1226 1223 1196 [[ 1229 ]] @rawptr:BotPTR, idx=Raw; mismatched Memory: @rawptr:BotPTR, idx=Raw; !jvms: ScopedMemoryAccess::storeIntoMemorySegmentScopedInternal @ bci:29 (line 441) ScopedMemoryAccess::storeIntoMemorySegment @ bci:15 (line 418) IntVector::intoMemorySegment0 @ bci:32 (line 3663) IntVector::intoMemorySegment @ bci:44 (line 3443) Test::testB @ bci:22 (line 34)
        946 ConP === 0 [[ 1068 994 1048 1042 1028 ]] #jdk/incubator/vector/IntVector$$Lambda+0x00000000220fa4c8 (jdk/internal/vm/vector/VectorSupport$StoreVectorOperation):exact * Oop:jdk/incubator/vector/IntVector$$Lambda+0x00000000220fa4c8 (jdk/internal/vm/vector/VectorSupport$StoreVectorOperation):exact *
       1230 StoreVector === 1225 1226 1223 1196 [[ 1229 ]] @rawptr:BotPTR, idx=Raw; mismatched Memory: @rawptr:BotPTR, idx=Raw; !jvms: ScopedMemoryAccess::storeIntoMemorySegmentScopedInternal @ bci:29 (line 441) ScopedMemoryAccess::storeIntoMemorySegment @ bci:15 (line 418) IntVector::intoMemorySegment0 @ bci:32 (line 3663) IntVector::intoMemorySegment @ bci:44 (line 3443) Test::testN @ bci:22 (line 39)

        1. Test3.java
          3 kB
        2. Test2.java
          3 kB
        3. Test.java
          1 kB

            jbhateja Jatin Bhateja
            epeter Emanuel Peter
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: