keith471 / COMP520_peephole

Other
0 stars 0 forks source link

Dup, Store, Pop #3

Closed gjh33 closed 7 years ago

gjh33 commented 7 years ago

If we see dup, store, pop that is superfluous. Just storing would be sufficient. Not sure why this is even generated.

example:

.method public checkRow(II)Z
  .limit locals 4
  .limit stack 3
  iconst_0
  dup
  istore_3
  pop
  start_0:
  iload_3
  ldc 9
  if_icmplt true_2
  iconst_0
  goto stop_3
  true_2:
  iconst_1
  stop_3:
  ifeq stop_1
  aload_0
  iload_1
  iload_3
  invokevirtual BacktrackSolver/getVal(II)I
  iload_2
  if_icmpeq true_5
  iconst_0
  goto stop_6
  true_5:
  iconst_1
  stop_6:
  ifeq stop_4
  iconst_0
  ireturn
  stop_4:
  iload_3
  iconst_1
  iadd
  dup
  istore_3
  pop
  goto start_0
  stop_1:
  iconst_1
  ireturn
  nop
.end method

The first instance of this is near the top of the code. As you can see it's pointless. I will remove all instances.

.method public checkRow(II)Z
  .limit locals 4
  .limit stack 3
  iconst_0
  istore_3
  start_0:
  iload_3
  ldc 9
  if_icmplt true_2
  iconst_0
  goto stop_3
  true_2:
  iconst_1
  stop_3:
  ifeq stop_1
  aload_0
  iload_1
  iload_3
  invokevirtual BacktrackSolver/getVal(II)I
  iload_2
  if_icmpeq true_5
  iconst_0
  goto stop_6
  true_5:
  iconst_1
  stop_6:
  ifeq stop_4
  iconst_0
  ireturn
  stop_4:
  iload_3
  iconst_1
  iadd
  istore_3
  goto start_0
  stop_1:
  iconst_1
  ireturn
  nop
.end method

4 lines removed

Conditions:

Extensions:

gjh33 commented 7 years ago

This is already in patterns.h. Damn