keith471 / COMP520_peephole

Other
0 stars 0 forks source link

replace store double load with dup #2

Open gjh33 opened 7 years ago

gjh33 commented 7 years ago

Consider the following situation

.method public doubleRandom()I
  .limit locals 2
  .limit stack 2
  invokevirtual java/util/Random/randomInt() I;
  astore_1
  aload_1
  aload_1
  iadd
  ireturn
.end method

We can replace the double astore, aload, aload with dup.

.method public doubleRandom()I
  .limit locals 2
  .limit stack 2
  invokevirtual java/util/Random/randomInt() I;
  dup
  iadd
  ireturn
.end method

Conditions:

Possible Extension: