openj9 icon indicating copy to clipboard operation
openj9 copied to clipboard

OpenJ9 Outputs Incorrect Results with JIT Compiler

Open Qeryu opened this issue 1 year ago • 6 comments

Java -version output

openjdk version "1.8.0_402-internal"
OpenJDK Runtime Environment (build 1.8.0_402-internal-user_2024_01_31_16_41-b00)
Eclipse OpenJ9 VM (build master-40a4d38b2, JRE 1.8.0 Linux amd64-64-Bit Compressed References 20240131_000000 (JIT enabled, AOT enabled)
OpenJ9   - 40a4d38b2
OMR      - a74c0935b
JCL      - 33602fcbe7 based on jdk8u402-b06)

javac 1.8.0_402-internal

Summary of problem

When I run the following code, openj9 outputs error results different from jdk. Since there is no error result when -Xint is turned on, I think it may be a JIT problem:

class Test {

    int a = 400;
    int[] m = new int[a];
    int[] c = new int[a];

    void n() {
        for (int i = 46; i > 9; --i) {
            m[i + 1] = 1;
            c[i] = 2;
        }
        for (int i = 0; i < 20000; ++i) c = m;
    }

    void g() {
        for (int i = 0; i < 20000; ++i)
            n();
        System.out.println(m[11]);
    }

    public static void main(String[] o) {
        Test test = new Test();
        test.g();
    }
}
$ openj9-openjdk-jdk8/.../java Test
2
$ other-jdk/.../java Test
1
$ openj9-openjdk-jdk8/.../java -Xint Test

I investigated the causes of the problem and found the following. I hope it can be helpful to you in the process of fixing the bug.

$ openj9-openjdk-jdk8/.../java '-Xjit:{Test.n(*)*}(optLevel=hot,lastOptIndex=137)' Test
2
$ openj9-openjdk-jdk8/.../java '-Xjit:{Test.n(*)*}(optLevel=hot,lastOptIndex=136)' Test
1
$ openj9-openjdk-jdk8/.../java '-Xjit:{Test.n(*)*}(optLevel=warm)' Test
1

Qeryu avatar Feb 14 '24 17:02 Qeryu

Thanks for reporting the problem. In my own runs, I needed to include the count=1,disableAsyncCompilation JIT compiler options, and I ended up with different lastOptIndex settings than yours:

$ openj9-openjdk-jdk8/bin/java '-Xjit:{Test.n(*)*}(optLevel=hot,lastOptIndex=122),count=1,disableAsyncCompilation' Test
1
root@ubuntu-1-hz1:/home/henry/docker-hostdir/defects/issue18956
$ openj9-openjdk-jdk8/bin/java '-Xjit:{Test.n(*)*}(optLevel=hot,lastOptIndex=123),count=1,disableAsyncCompilation' Test
2

Looking at log files, I found lastOptIndex=123 corresponded to Idiom Recognition:

<optimization id=123 name=idiomRecognition method=Test.n()V>
Performing 123: idiomRecognition
            (Building use/def info)
         PREPARTITION VN   (Building value number info)
[   260] 123.1    O^O NEWLOOPREDUCER: Reducing loop 4 to MemSet

May I ask you to run with the option '-Xjit:{Test.n(*)*}(optLevel=hot,lastOptIndex=137,optDetails,log=issue18955.log)' and check the log file to see whether Idiom Recognition corresponds to optIndex 137 in your tests?

hzongaro avatar Feb 14 '24 17:02 hzongaro

When I run with the option '-Xjit:{Test.n(*)*}(optLevel=hot,lastOptIndex=137,optDetails,log=issue18955.log)', the log file indicates that the optIndex corresponds to localCSE.

<optimization id=137 name=localCSE method=Test.n()V>
Performing 137: localCSE
[   387] 137.1    O^O LOCAL COMMON SUBEXPRESSION ELIMINATION:    Local Common Subexpression Elimination propagating local #423 in node : 00007F7DB4F3EC90 PARENT : 00007F7DB4F3EC40 from node 00007F7DB4F3E970
         O^O LOCAL COMMON SUBEXPRESSION ELIMINATION:    Rhs of store def node : 00007F7DB4F3E9C0
[   388] 137.2    O^O LOCAL COMMON SUBEXPRESSION ELIMINATION:    Local Common Subexpression Elimination commoning node : 00007F7DB4F3F870 by available node : 00007F7DB4F3F8C0
[   389] 137.3    O^O LOCAL COMMON SUBEXPRESSION ELIMINATION:    Local Common Subexpression Elimination propagating local #423 in node : 00007F7DB4F3EF60 PARENT : 00007F7DB4F3EF10 from node 00007F7DB4F3EBF0
         O^O LOCAL COMMON SUBEXPRESSION ELIMINATION:    Rhs of store def node : 00007F7DB4F3EC40
[   390] 137.4    O^O LOCAL COMMON SUBEXPRESSION ELIMINATION:    Local Common Subexpression Elimination commoning node : 00007F7DB4F3F820 by available node : 00007F7DB4F3F8C0
<trees
	title="Trees after localCSE"
	method="Test.n()V"
	hotness="hot">

The Optimization ID for Idiom Recognition remains 123. Below is the complete log file I obtained.

issue18955.log.1604928.1220.20240215.204700.1604928.log

Qeryu avatar Feb 15 '24 13:02 Qeryu

We haven't investigated this problem enough to get a fix in for the 0.44.0 release. Moving to 0.45.

hzongaro avatar Feb 21 '24 21:02 hzongaro

Hello, I found mis-compilation again in the localCSE optimization but using another testcase. To avoid cluttering the issue system, I'll post the relevant information here.

Could you please confirm if this is due to the same reason as the issue mentioned above? @hzongaro

class Test {

  int a = 400;
  long b;
  volatile short c = 2;
  double[] k = new double[a];

  void d() {
    int h = 1, f = 1;
    do {
      b = 2;
      for (int g = 2; g < 66; g++) {
        for (int j = 1; j < 2; ++j) k[f] = h -= b;
        b <<= c;
      }
    } while (++f < 381);
    System.out.println(h);
  }

  public static void main(String[] l) {
    Test t = new Test();
    for (int i = 0; i < 50; i++) t.d();
  }
}
$ other-jdk/.../java Test
...
-1431655511
-1431655511
-1431655511
-1431655511
-1431655511
-1431655511
-1431655511
-1431655511
-1431655511
-1431655511
-1431655511

$ openj9-openjdk-jdk8/.../java '-Xjit:{Test.d(*)*}(optLevel=hot,lastOptIndex=99,optDetails,log=jit.log)' Test
...
-1431655511
-1431655511
-1431655511
-1431655511
-1431655511
-1431655511
-1431655511
-1431655511
-1431655511
-1431655511
-1431655511

# mis-compilation
$ openj9-openjdk-jdk8/.../java '-Xjit:{Test.d(*)*}(optLevel=hot,lastOptIndex=100,optDetails,log=jit.log)' Test
...
-1431655511
-1431655511
-48639
-48639
-48639
-48639
-48639
-48639
-48639
-48639
-48639

The relevant log files are located here: jit.log.1340959.68205.20240225.213645.1340959.log

Qeryu avatar Feb 25 '24 13:02 Qeryu

I took a quick look at the log file for the original test case, and I have confirmed that it's a problem in Idiom Recognition. Before Idiom Recogition, the IL for the body of the loop looks like this:

n15n      BBStart <block_4> (freq 10000) (in loop 4)                                          [0x7f1c6f004ce0] bci=[-1,3,8] rc=0 vc=819 vn=- li=-1 udi=- nc=0
n35n      istorei  <array-shadow>[#229  Shadow] [flags 0x80000603 0x0 ]                       [0x7f1c6f005320] bci=[-1,17,9] rc=0 vc=819 vn=- li=-1 udi=- nc=2
n34n        aladd (X>=0 internalPtr )                                                         [0x7f1c6f0052d0] bci=[-1,17,9] rc=1 vc=819 vn=- li=- udi=- nc=2 flg=0x8100
n19n          aload  <temp slot 4>[#429  Auto] [flags 0x7 0x0 ] (X!=0 )                       [0x7f1c6f004e20] bci=[-1,10,9] rc=1 vc=819 vn=- li=- udi=20 nc=0 flg=0x4
n33n          lsub (highWordZero X>=0 cannotOverflow )                                        [0x7f1c6f005280] bci=[-1,17,9] rc=1 vc=819 vn=- li=- udi=- nc=2 flg=0x5100
n135n           lmul (X>=0 cannotOverflow )                                                   [0x7f1c6f0819f0] bci=[-1,17,9] rc=2 vc=819 vn=- li=- udi=- nc=2 flg=0x1100
n30n              i2l (highWordZero X>=0 )                                                    [0x7f1c6f005190] bci=[-1,17,9] rc=1 vc=819 vn=- li=- udi=- nc=1 flg=0x4100
n22n                iload  <auto slot 1>[#423  Auto] [flags 0x3 0x0 ] (X>=0 cannotOverflow )  [0x7f1c6f004f10] bci=[-1,13,9] rc=2 vc=819 vn=- li=- udi=21 nc=0 flg=0x1100
n136n             lconst 4 (highWordZero X!=0 X>=0 )                                          [0x7f1c6f081a40] bci=[-1,14,9] rc=1 vc=819 vn=- li=- udi=- nc=0 flg=0x4104
n32n            lconst -12 (X!=0 X<=0 )                                                       [0x7f1c6f005230] bci=[-1,17,9] rc=1 vc=819 vn=- li=- udi=- nc=0 flg=0x204
n25n        iconst 1 (X!=0 X>=0 )                                                             [0x7f1c6f005000] bci=[-1,16,9] rc=1 vc=819 vn=- li=- udi=- nc=0 flg=0x104
n51n      istorei  <array-shadow>[#229  Shadow] [flags 0x80000603 0x0 ]                       [0x7f1c6f005820] bci=[-1,24,10] rc=0 vc=819 vn=- li=-1 udi=- nc=2
n50n        aladd (X>=0 internalPtr )                                                         [0x7f1c6f0057d0] bci=[-1,24,10] rc=1 vc=819 vn=- li=- udi=- nc=2 flg=0x8100
n37n          aload  <temp slot 3>[#428  Auto] [flags 0x7 0x0 ] (X!=0 )                       [0x7f1c6f0053c0] bci=[-1,19,10] rc=1 vc=819 vn=- li=- udi=22 nc=0 flg=0x4
n49n          lsub (highWordZero X>=0 cannotOverflow )                                        [0x7f1c6f005780] bci=[-1,24,10] rc=1 vc=819 vn=- li=- udi=- nc=2 flg=0x5100
n135n           ==>lmul
n48n            lconst -8 (X!=0 X<=0 )                                                        [0x7f1c6f005730] bci=[-1,24,10] rc=1 vc=819 vn=- li=- udi=- nc=0 flg=0x204
n41n        iconst 2 (X!=0 X>=0 )                                                             [0x7f1c6f005500] bci=[-1,23,10] rc=1 vc=819 vn=- li=- udi=- nc=0 flg=0x104
n55n      istore  <auto slot 1>[#423  Auto] [flags 0x3 0x0 ]                                  [0x7f1c6f0800f0] bci=[-1,25,8] rc=0 vc=819 vn=- li=-1 udi=4 nc=1
n54n        iadd (X>=0 cannotOverflow )                                                       [0x7f1c6f0800a0] bci=[-1,25,8] rc=2 vc=819 vn=- li=- udi=- nc=2 flg=0x1100
n22n          ==>iload
n53n          iconst -1 (X!=0 X<=0 )                                                          [0x7f1c6f080050] bci=[-1,25,8] rc=1 vc=819 vn=- li=- udi=- nc=0 flg=0x204
n17n      ificmpgt --> block_4 BBStart at n15n ()                                             [0x7f1c6f004d80] bci=[-1,6,8] rc=0 vc=819 vn=- li=-1 udi=- nc=2 flg=0x20
n54n        ==>iadd
n14n        iconst 9 (X!=0 X>=0 )                                                             [0x7f1c6f004c90] bci=[-1,4,8] rc=1 vc=819 vn=- li=- udi=- nc=0 flg=0x104
n4n       BBEnd </block_4> ===== 

Idiom Recognition replaces the loop with arrayset operations:

[   260] 123.1    O^O NEWLOOPREDUCER: Reducing loop 4 to MemSet
...
n15n      BBStart <block_4> (freq 10000)                                                      [0x7f1c6f004ce0] bci=[-1,3,8] rc=0 vc=831 vn=- li=- udi=- nc=0
n736n     treetop                                                                             [0x7f1c6f08d5c0] bci=[-1,17,9] rc=0 vc=0 vn=- li=- udi=- nc=1
n735n       arrayset  <arrayset>[#219  helper Method] [flags 0x400 0x0 ] ()                   [0x7f1c6f08d570] bci=[-1,17,9] rc=1 vc=0 vn=- li=- udi=- nc=3 flg=0x20
n716n         aladd (X>=0 internalPtr )                                                       [0x7f1c6f08cf80] bci=[-1,17,9] rc=1 vc=831 vn=- li=- udi=- nc=2 flg=0x8100
n717n           aload  <temp slot 4>[#429  Auto] [flags 0x7 0x0 ] (X!=0 )                     [0x7f1c6f08cfd0] bci=[-1,10,9] rc=1 vc=831 vn=- li=- udi=13 nc=0 flg=0x4
n718n           lsub (highWordZero X>=0 cannotOverflow )                                      [0x7f1c6f08d020] bci=[-1,17,9] rc=1 vc=831 vn=- li=- udi=- nc=2 flg=0x5100
n719n             lmul (X>=0 cannotOverflow )                                                 [0x7f1c6f08d070] bci=[-1,17,9] rc=1 vc=831 vn=- li=- udi=- nc=2 flg=0x1100
n720n               i2l (highWordZero X>=0 )                                                  [0x7f1c6f08d0c0] bci=[-1,17,9] rc=1 vc=831 vn=- li=- udi=- nc=1 flg=0x4100
n727n                 iconst 10 (X!=0 X>=0 )                                                  [0x7f1c6f08d2f0] bci=[-1,4,8] rc=1 vc=0 vn=- li=- udi=- nc=0 flg=0x104
n722n               lconst 4 (highWordZero X!=0 X>=0 )                                        [0x7f1c6f08d160] bci=[-1,14,9] rc=1 vc=831 vn=- li=- udi=- nc=0 flg=0x4104
n723n             lconst -12 (X!=0 X<=0 )                                                     [0x7f1c6f08d1b0] bci=[-1,17,9] rc=1 vc=831 vn=- li=- udi=- nc=0 flg=0x204
n724n         iconst 1 (X!=0 X>=0 )                                                           [0x7f1c6f08d200] bci=[-1,16,9] rc=1 vc=831 vn=- li=- udi=- nc=0 flg=0x104
n734n         lmul                                                                            [0x7f1c6f08d520] bci=[-1,13,9] rc=1 vc=0 vn=- li=- udi=- nc=2
n732n           i2l                                                                           [0x7f1c6f08d480] bci=[-1,13,9] rc=1 vc=0 vn=- li=- udi=- nc=1
n728n             isub                                                                        [0x7f1c6f08d340] bci=[-1,13,9] rc=1 vc=0 vn=- li=- udi=- nc=2
n694n               iload  <auto slot 1>[#423  Auto] [flags 0x3 0x0 ] (X>=0 cannotOverflow )  [0x7f1c6f08c8a0] bci=[-1,13,9] rc=2 vc=831 vn=- li=- udi=14 nc=0 flg=0x1100
n725n               iconst 9 (X!=0 X>=0 )                                                     [0x7f1c6f08d250] bci=[-1,4,8] rc=1 vc=831 vn=- li=- udi=- nc=0 flg=0x104
n733n           lconst 4 (highWordZero X!=0 X>=0 )                                            [0x7f1c6f08d4d0] bci=[-1,17,9] rc=1 vc=0 vn=- li=- udi=- nc=0 flg=0x4104
n715n     treetop                                                                             [0x7f1c6f08cf30] bci=[-1,24,10] rc=0 vc=0 vn=- li=- udi=- nc=1
n714n       arrayset  <arrayset>[#219  helper Method] [flags 0x400 0x0 ] ()                   [0x7f1c6f08cee0] bci=[-1,24,10] rc=1 vc=0 vn=- li=- udi=- nc=3 flg=0x20
n695n         aladd (X>=0 internalPtr )                                                       [0x7f1c6f08c8f0] bci=[-1,24,10] rc=1 vc=831 vn=- li=- udi=- nc=2 flg=0x8100
n696n           aload  <temp slot 3>[#428  Auto] [flags 0x7 0x0 ] (X!=0 )                     [0x7f1c6f08c940] bci=[-1,19,10] rc=1 vc=831 vn=- li=- udi=15 nc=0 flg=0x4
n697n           lsub (highWordZero X>=0 cannotOverflow )                                      [0x7f1c6f08c990] bci=[-1,24,10] rc=1 vc=831 vn=- li=- udi=- nc=2 flg=0x5100
n698n             lmul (X>=0 cannotOverflow )                                                 [0x7f1c6f08c9e0] bci=[-1,17,9] rc=1 vc=831 vn=- li=- udi=- nc=2 flg=0x1100
n699n               i2l (highWordZero X>=0 )                                                  [0x7f1c6f08ca30] bci=[-1,17,9] rc=1 vc=831 vn=- li=- udi=- nc=1 flg=0x4100
n706n                 iconst 10 (X!=0 X>=0 )                                                  [0x7f1c6f08cc60] bci=[-1,4,8] rc=1 vc=0 vn=- li=- udi=- nc=0 flg=0x104
n701n               lconst 4 (highWordZero X!=0 X>=0 )                                        [0x7f1c6f08cad0] bci=[-1,14,9] rc=1 vc=831 vn=- li=- udi=- nc=0 flg=0x4104
n702n             lconst -8 (X!=0 X<=0 )                                                      [0x7f1c6f08cb20] bci=[-1,24,10] rc=1 vc=831 vn=- li=- udi=- nc=0 flg=0x204
n703n         iconst 2 (X!=0 X>=0 )                                                           [0x7f1c6f08cb70] bci=[-1,23,10] rc=1 vc=831 vn=- li=- udi=- nc=0 flg=0x104
n713n         lmul                                                                            [0x7f1c6f08ce90] bci=[-1,13,9] rc=1 vc=0 vn=- li=- udi=- nc=2
n711n           i2l                                                                           [0x7f1c6f08cdf0] bci=[-1,13,9] rc=1 vc=0 vn=- li=- udi=- nc=1
n707n             isub                                                                        [0x7f1c6f08ccb0] bci=[-1,13,9] rc=1 vc=0 vn=- li=- udi=- nc=2
n694n               ==>iload
n704n               iconst 9 (X!=0 X>=0 )                                                     [0x7f1c6f08cbc0] bci=[-1,4,8] rc=1 vc=831 vn=- li=- udi=- nc=0 flg=0x104
n712n           lconst 4 (highWordZero X!=0 X>=0 )                                            [0x7f1c6f08ce40] bci=[-1,24,10] rc=1 vc=0 vn=- li=- udi=- nc=0 flg=0x4104
n737n     istore  <auto slot 1>[#423  Auto] [flags 0x3 0x0 ]                                  [0x7f1c6f08d610] bci=[-1,4,8] rc=0 vc=0 vn=- li=- udi=- nc=1
n731n       iconst 9 (X!=0 X>=0 )                                                             [0x7f1c6f08d430] bci=[-1,4,8] rc=1 vc=0 vn=- li=- udi=- nc=0 flg=0x104
n744n     goto --> block_5 BBStart at n1n                                                     [0x7f1c6f08d840] bci=[-1,4,8] rc=0 vc=0 vn=- li=- udi=- nc=0
n4n       BBEnd </block_4> =====                                                              [0x7f1c6f004970] bci=[-1,6,8] rc=0 vc=831 vn=- li=- udi=- nc=0

So it sets some elements of array m to 1 and then sets some elements of array c to 2. The problem is that after the first call to n, both m and c refer to the same array. So Idiom Recognition seems not to be taking into account the possibility that the same array could be being updated in the loop.

hzongaro avatar Jun 24 '24 21:06 hzongaro

@Qeryu, I took a look at the second test that you mentioned in this issue. I believe that problem is a duplicate of either #18777 or #19218, both of which were fixed by @a7ehuo. Looking at the IL in the jit log that you posted, before PRE we see this IL accessing Test.b:

n9n       BBStart <block_3> (freq 1432) (in loop 3)                                           [0x7ff4ab004d00] bci=[-1,16,12] rc=0 vc=835 vn=- li=- udi=- nc=0
n19n      lstorei  Test.b J[#425  Shadow +8] [flags 0x604 0x0 ]                               [0x7ff4ab005020] bci=[-1,8,11] rc=0 vc=835 vn=- li=- udi=- nc=2
n17n        aload  <'this' parm LTest;>[#422  Parm] [flags 0x40000107 0x0 ] (X!=0 X>=0 )      [0x7ff4ab004f80] bci=[-1,4,11] rc=1 vc=835 vn=- li=- udi=31 nc=0 flg=0x104
n18n        lconst 2 (highWordZero X!=0 X>=0 )               
...
n43n      BBStart <block_7> (freq 10000) (in loop 5)                                          [0x7ff4ab0057a0] bci=[-1,22,13] rc=0 vc=835 vn=- li=- udi=- nc=0
n65n      istore  <auto slot 1>[#423  Auto] [flags 0x3 0x0 ]                                  [0x7ff4ab080410] bci=[-1,42,13] rc=0 vc=835 vn=- li=- udi=8 nc=1
n64n        isub                                                                              [0x7ff4ab0803c0] bci=[-1,40,13] rc=2 vc=835 vn=- li=- udi=- nc=2
n59n          iload  <auto slot 1>[#423  Auto] [flags 0x3 0x0 ] (cannotOverflow )             [0x7ff4ab080230] bci=[-1,33,13] rc=1 vc=835 vn=- li=- udi=39 nc=0 flg=0x1000
n485n         l2i                                                                             [0x7ff4ab088750] bci=[-1,36,13] rc=1 vc=835 vn=- li=- udi=- nc=1
n62n            lloadi  Test.b J[#425  Shadow +8] [flags 0x604 0x0 ] (cannotOverflow )        [0x7ff4ab080320] bci=[-1,36,13] rc=1 vc=835 vn=- li=- udi=- nc=1 flg=0x1000
n61n              aload  <'this' parm LTest;>[#422  Parm] [flags 0x40000107 0x0 ] (X!=0 X>=0 )  [0x7ff4ab0802d0] bci=[-1,35,13] rc=1 vc=835 vn=- li=- udi=40 nc=0 flg=0x104
n76n      dstorei  <array-shadow>[#232  Shadow] [flags 0x80000606 0x0 ]                       [0x7ff4ab080780] bci=[-1,44,13] rc=0 vc=835 vn=- li=- udi=- nc=2
n75n        aladd (X>=0 internalPtr )                                                         [0x7ff4ab080730] bci=[-1,44,13] rc=1 vc=835 vn=- li=- udi=- nc=2 flg=0x8100
n55n          aload  <temp slot 9>[#479  Auto] [flags 0x7 0x0 ] (X!=0 )                       [0x7ff4ab0800f0] bci=[-1,29,13] rc=1 vc=835 vn=- li=- udi=38 nc=0 flg=0x4
n74n          lload  <temp slot 8>[#478  Auto] [flags 0x4 0x0 ] (highWordZero X>=0 cannotOverflow )  [0x7ff4ab0806e0] bci=[-1,44,13] rc=1 vc=835 vn=- li=- udi=41 nc=0 flg=0x5100
n66n        i2d                                                                               [0x7ff4ab080460] bci=[-1,43,13] rc=1 vc=835 vn=- li=- udi=- nc=1
n64n          ==>isub
...
n515n     BBStart <block_53> (freq 1500) (in loop 5)                                          [0x7ff4ab0890b0] bci=[-1,13,12] rc=0 vc=835 vn=- li=- udi=- nc=0
n519n     lstorei  Test.b J[#425  Shadow +8] [flags 0x604 0x0 ]                               [0x7ff4ab0891f0] bci=[-1,61,14] rc=0 vc=835 vn=- li=- udi=- nc=2
n518n       aload  <'this' parm LTest;>[#422  Parm] [flags 0x40000107 0x0 ] (X!=0 X>=0 )      [0x7ff4ab0891a0] bci=[-1,51,14] rc=2 vc=835 vn=- li=- udi=42 nc=0 flg=0x104
n520n       lshl                                                                              [0x7ff4ab089240] bci=[-1,60,14] rc=1 vc=835 vn=- li=- udi=- nc=2
n517n         lloadi  Test.b J[#425  Shadow +8] [flags 0x604 0x0 ] (cannotOverflow )          [0x7ff4ab089150] bci=[-1,53,14] rc=1 vc=835 vn=- li=- udi=- nc=1 flg=0x1000
n518n           ==>aload
n521n         iloadi  Test.c S[#435  volatile Shadow +24] [flags 0x2602 0x0 ] (cannotOverflow )  [0x7ff4ab089290] bci=[-1,57,14] rc=1 vc=835 vn=- li=- udi=- nc=1 flg=0x1000
n522n           aload  <'this' parm LTest;>[#422  Parm] [flags 0x40000107 0x0 ] (X!=0 X>=0 )  [0x7ff4ab0892e0] bci=[-1,56,14] rc=1 vc=835 vn=- li=- udi=43 nc=0 flg=0x104

The first segment is assigning 2 to this.b in the outer do-while loop, the second is calculating h -= this.b and the third is calculating this.b <<= this.c.

After PRE, we have this:

Performing 99: partialRedundancyElimination
         O^O PARTIAL REDUNDANCY ELIMINATION: 1Placing lloadi optimally : 00007FF4AB08F820 using symRef #480
         O^O PARTIAL REDUNDANCY ELIMINATION: Eliminating redundant computation (store) : 00007FF4AB005020
[   260] O^O PARTIAL REDUNDANCY ELIMINATION: Eliminating redundant computation (lloadi) : 00007FF4AB080320 in block_7, visit count 1077
...
n9n       BBStart <block_3> (freq 1432) (in loop 3)                                           [0x7ff4ab004d00] bci=[-1,16,12] rc=0 vc=1063 vn=- li=-1 udi=- nc=0
n19n      lstorei  Test.b J[#425  Shadow +8] [flags 0x604 0x0 ]                               [0x7ff4ab005020] bci=[-1,8,11] rc=0 vc=1063 vn=- li=2 udi=- nc=2
n17n        aload  <'this' parm LTest;>[#422  Parm] [flags 0x40000107 0x0 ] (X!=0 X>=0 )      [0x7ff4ab004f80] bci=[-1,4,11] rc=1 vc=1063 vn=- li=1 udi=31 nc=0 flg=0x104
n18n        lconst 2 (highWordZero X!=0 X>=0 )                                                [0x7ff4ab004fd0] bci=[-1,5,11] rc=2 vc=1063 vn=- li=-1 udi=- nc=0 flg=0x4104
n849n     lstore  <temp slot 10>[#480  Auto] [flags 0x4 0x0 ]                                 [0x7ff4ab08f910] bci=[-1,5,11] rc=0 vc=0 vn=- li=-1 udi=- nc=1
n18n        ==>lconst 2
...
n43n      BBStart <block_7> (freq 10000) (in loop 5)                                          [0x7ff4ab0057a0] bci=[-1,22,13] rc=0 vc=1077 vn=- li=-1 udi=- nc=0
n65n      istore  <auto slot 1>[#423  Auto] [flags 0x3 0x0 ]                                  [0x7ff4ab080410] bci=[-1,42,13] rc=0 vc=1077 vn=- li=-1 udi=8 nc=1
n64n        isub                                                                              [0x7ff4ab0803c0] bci=[-1,40,13] rc=2 vc=1077 vn=- li=13 udi=- nc=2
n59n          iload  <auto slot 1>[#423  Auto] [flags 0x3 0x0 ] (cannotOverflow )             [0x7ff4ab080230] bci=[-1,33,13] rc=1 vc=1077 vn=- li=11 udi=39 nc=0 flg=0x1000
n485n         l2i                                                                             [0x7ff4ab088750] bci=[-1,36,13] rc=1 vc=1077 vn=- li=12 udi=- nc=1
n62n            lload  <temp slot 10>[#480  Auto] [flags 0x4 0x0 ] (cannotOverflow createdByPRE )  [0x7ff4ab080320] bci=[-1,36,13] rc=1 vc=1077 vn=- li=2 udi=- nc=0 flg=0x41000
n76n      dstorei  <array-shadow>[#232  Shadow] [flags 0x80000606 0x0 ]                       [0x7ff4ab080780] bci=[-1,44,13] rc=0 vc=1077 vn=- li=16 udi=- nc=2
n75n        aladd (X>=0 internalPtr )                                                         [0x7ff4ab080730] bci=[-1,44,13] rc=1 vc=1077 vn=- li=-1 udi=- nc=2 flg=0x8100
n55n          aload  <temp slot 9>[#479  Auto] [flags 0x7 0x0 ] (X!=0 )                       [0x7ff4ab0800f0] bci=[-1,29,13] rc=1 vc=1077 vn=- li=9 udi=38 nc=0 flg=0x4
n74n          lload  <temp slot 8>[#478  Auto] [flags 0x4 0x0 ] (highWordZero X>=0 cannotOverflow )  [0x7ff4ab0806e0] bci=[-1,44,13] rc=1 vc=1077 vn=- li=14 udi=41 nc=0 flg=0x5100
n66n        i2d                                                                               [0x7ff4ab080460] bci=[-1,43,13] rc=1 vc=1077 vn=- li=15 udi=- nc=1
n64n          ==>isub
...
n515n     BBStart <block_53> (freq 1500) (in loop 5)                                          [0x7ff4ab0890b0] bci=[-1,13,12] rc=0 vc=1079 vn=- li=-1 udi=- nc=0
n519n     lstorei  Test.b J[#425  Shadow +8] [flags 0x604 0x0 ] ()                            [0x7ff4ab0891f0] bci=[-1,61,14] rc=0 vc=1079 vn=- li=2 udi=- nc=2 flg=0x8
n518n       aload  <'this' parm LTest;>[#422  Parm] [flags 0x40000107 0x0 ] (X!=0 X>=0 )      [0x7ff4ab0891a0] bci=[-1,51,14] rc=2 vc=1079 vn=- li=1 udi=42 nc=0 flg=0x104
n520n       lshl ()                                                                           [0x7ff4ab089240] bci=[-1,60,14] rc=1 vc=1079 vn=- li=- udi=- nc=2 flg=0x8
n517n         lloadi  Test.b J[#425  Shadow +8] [flags 0x604 0x0 ] (cannotOverflow )          [0x7ff4ab089150] bci=[-1,53,14] rc=1 vc=1079 vn=- li=2 udi=- nc=1 flg=0x1000
n518n           ==>aload
n521n         iloadi  Test.c S[#435  volatile Shadow +24] [flags 0x2602 0x0 ] (cannotOverflow )  [0x7ff4ab089290] bci=[-1,57,14] rc=1 vc=1079 vn=- li=- udi=- nc=1 flg=0x1008
n522n           aload  <'this' parm LTest;>[#422  Parm] [flags 0x40000107 0x0 ] (X!=0 X>=0 )  [0x7ff4ab0892e0] bci=[-1,56,14] rc=1 vc=1079 vn=- li=1 udi=43 nc=0 flg=0x104

So it sets both this.b and a temporary variable #480 with the value 2 in the outer do-while, uses #480 in the update of h, but at the end, it only calculates this.b <<= this.c - the temporary variable #480 is not similarly updated.

I wasn't ever able to reproduce this problem, so I can't verify that it's fixed by either of the fixes that applied for #18777 or #19218. May I ask you to test whether you are still able to reproduce the problem?

Regardless, we'll look at the Idiom Recognition problem in this issue.

hzongaro avatar Jun 25 '24 13:06 hzongaro

@Spencer-Comin, may I ask you to take a look at this problem in Idiom Recognition?

hzongaro avatar Jul 03 '24 14:07 hzongaro