Skip to content

Commit

Permalink
fix: do not remove swap ops before itxn_field if it's immediates po…
Browse files Browse the repository at this point in the history
…int to the same field
  • Loading branch information
daniel-makerx committed Aug 28, 2024
1 parent 58f4acb commit 0e88cdb
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/sizes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
tuple_support/NestedTuples 956 613 343 613 0
tuple_support/TupleComparisons 136 68 68 68 0
tuple_support/TupleSupport 696 409 287 409 0
typed_abi_call/Greeter 3101 2673 428 2673 0
typed_abi_call/Greeter 3101 2674 427 2674 0
typed_abi_call/Logger 964 827 137 827 0
unary/Unary 130 67 63 67 0
unassigned_expression/Unassigned 132 107 25 107 0
Expand Down
5 changes: 5 additions & 0 deletions src/puya/teal/optimize/peephole.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ def _optimize_triplet(
and c.op_code == "frame_bury"
and b.immediates == c.immediates
)
or ( # can't swap itxn_field if they refer to the same field e.g. ApplicationArgs
b.op_code == "itxn_field"
and c.op_code == "itxn_field"
and b.immediates == c.immediates
)
):
return [c, b], True

Expand Down
1 change: 1 addition & 0 deletions test_cases/typed_abi_call/out/Greeter.approval.teal
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ test_is_a_b:
// )
method "is_a_b(byte[],byte[])void"
itxn_field ApplicationArgs
swap
itxn_field ApplicationArgs
itxn_field ApplicationArgs
int appl
Expand Down
2 changes: 1 addition & 1 deletion test_cases/typed_abi_call/out/Greeter.arc32.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions test_cases/typed_abi_call/out_O2/Greeter.approval.teal
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ test_is_a_b:
itxn_field ApplicationID
method "is_a_b(byte[],byte[])void"
itxn_field ApplicationArgs
swap
itxn_field ApplicationArgs
itxn_field ApplicationArgs
int appl
Expand Down

0 comments on commit 0e88cdb

Please sign in to comment.