Skip to content

Commit

Permalink
fix: IntrinsicSimplifier now visits source values on Assignment ops
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-makerx committed Jan 17, 2024
1 parent b3c1f2f commit 2da337e
Show file tree
Hide file tree
Showing 100 changed files with 7,535 additions and 7,969 deletions.
2 changes: 1 addition & 1 deletion src/puya/ir/optimize/constant_propagation.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def visit_assignment(self, ass: Assignment) -> Assignment | None:
):
self.modified += 1
ass.source = true if value else false
return ass
return super().visit_assignment(ass)

def visit_intrinsic_op(self, intrinsic: Intrinsic) -> Intrinsic | None:
match intrinsic:
Expand Down
12 changes: 3 additions & 9 deletions test_cases/abi_routing/out/contract.approval.debug.teal

Large diffs are not rendered by default.

12 changes: 3 additions & 9 deletions test_cases/abi_routing/out/contract.approval.teal
Original file line number Diff line number Diff line change
Expand Up @@ -412,23 +412,17 @@ method_with_default_args_block@0:
==
assert // wrong application from function
frame_dig -3
int 0
int 1
extract3
extract 0 1
byte 0x07
==
assert // wrong 0th byte from storage
frame_dig -3
int 1
int 1
extract3
extract 1 1
byte 0x08
==
assert // wrong 1st byte from storage
frame_dig -3
int 2
int 1
extract3
extract 2 1
byte 0x09
==
assert // wrong 2nd byte from storage
Expand Down
6 changes: 3 additions & 3 deletions test_cases/abi_routing/out/contract_Reference.cssa.ir
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,13 @@ contract test_cases.abi_routing.contract.Reference:
(assert tmp%6#0) // wrong application from storage
let tmp%7#0: uint64 = (== application_from_function#0 456u)
(assert tmp%7#0) // wrong application from function
let tmp%9#0: bytes = (extract3 bytes_from_storage#0 0u 1u)
let tmp%9#0: bytes = ((extract 0 1) bytes_from_storage#0)
let tmp%10#0: uint64 = (== tmp%9#0 0x07)
(assert tmp%10#0) // wrong 0th byte from storage
let tmp%12#0: bytes = (extract3 bytes_from_storage#0 1u 1u)
let tmp%12#0: bytes = ((extract 1 1) bytes_from_storage#0)
let tmp%13#0: uint64 = (== tmp%12#0 0x08)
(assert tmp%13#0) // wrong 1st byte from storage
let tmp%15#0: bytes = (extract3 bytes_from_storage#0 2u 1u)
let tmp%15#0: bytes = ((extract 2 1) bytes_from_storage#0)
let tmp%16#0: uint64 = (== tmp%15#0 0x09)
(assert tmp%16#0) // wrong 2nd byte from storage
let tmp%17#0: uint64 = (btoi int_from_storage#0)
Expand Down
6 changes: 3 additions & 3 deletions test_cases/abi_routing/out/contract_Reference.final.ir
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,13 @@ contract test_cases.abi_routing.contract.Reference:
(assert tmp%6#0) // wrong application from storage
let tmp%7#0: uint64 = (== application_from_function#0 456u)
(assert tmp%7#0) // wrong application from function
let tmp%9#0: bytes = (extract3 bytes_from_storage#0 0u 1u)
let tmp%9#0: bytes = ((extract 0 1) bytes_from_storage#0)
let tmp%10#0: uint64 = (== tmp%9#0 0x07)
(assert tmp%10#0) // wrong 0th byte from storage
let tmp%12#0: bytes = (extract3 bytes_from_storage#0 1u 1u)
let tmp%12#0: bytes = ((extract 1 1) bytes_from_storage#0)
let tmp%13#0: uint64 = (== tmp%12#0 0x08)
(assert tmp%13#0) // wrong 1st byte from storage
let tmp%15#0: bytes = (extract3 bytes_from_storage#0 2u 1u)
let tmp%15#0: bytes = ((extract 2 1) bytes_from_storage#0)
let tmp%16#0: uint64 = (== tmp%15#0 0x09)
(assert tmp%16#0) // wrong 2nd byte from storage
let tmp%17#0: uint64 = (btoi int_from_storage#0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,13 @@ contract test_cases.abi_routing.contract.Reference:
(assert tmp%6#0) // wrong application from storage
let tmp%7#0: uint64 = (== application_from_function#0 456u)
(assert tmp%7#0) // wrong application from function
let tmp%9#0: bytes = (extract3 bytes_from_storage#0 0u 1u)
let tmp%9#0: bytes = ((extract 0 1) bytes_from_storage#0)
let tmp%10#0: uint64 = (== tmp%9#0 0x07)
(assert tmp%10#0) // wrong 0th byte from storage
let tmp%12#0: bytes = (extract3 bytes_from_storage#0 1u 1u)
let tmp%12#0: bytes = ((extract 1 1) bytes_from_storage#0)
let tmp%13#0: uint64 = (== tmp%12#0 0x08)
(assert tmp%13#0) // wrong 1st byte from storage
let tmp%15#0: bytes = (extract3 bytes_from_storage#0 2u 1u)
let tmp%15#0: bytes = ((extract 2 1) bytes_from_storage#0)
let tmp%16#0: uint64 = (== tmp%15#0 0x09)
(assert tmp%16#0) // wrong 2nd byte from storage
let tmp%17#0: uint64 = (btoi int_from_storage#0)
Expand Down
6 changes: 3 additions & 3 deletions test_cases/abi_routing/out/contract_Reference.post_ssa.ir
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,13 @@ contract test_cases.abi_routing.contract.Reference:
(assert tmp%6#0) // wrong application from storage
let tmp%7#0: uint64 = (== application_from_function#0 456u)
(assert tmp%7#0) // wrong application from function
let tmp%9#0: bytes = (extract3 bytes_from_storage#0 0u 1u)
let tmp%9#0: bytes = ((extract 0 1) bytes_from_storage#0)
let tmp%10#0: uint64 = (== tmp%9#0 0x07)
(assert tmp%10#0) // wrong 0th byte from storage
let tmp%12#0: bytes = (extract3 bytes_from_storage#0 1u 1u)
let tmp%12#0: bytes = ((extract 1 1) bytes_from_storage#0)
let tmp%13#0: uint64 = (== tmp%12#0 0x08)
(assert tmp%13#0) // wrong 1st byte from storage
let tmp%15#0: bytes = (extract3 bytes_from_storage#0 2u 1u)
let tmp%15#0: bytes = ((extract 2 1) bytes_from_storage#0)
let tmp%16#0: uint64 = (== tmp%15#0 0x09)
(assert tmp%16#0) // wrong 2nd byte from storage
let tmp%17#0: uint64 = (btoi int_from_storage#0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,13 @@ contract test_cases.abi_routing.contract.Reference:
(assert tmp%6#0) // wrong application from storage
let tmp%7#0: uint64 = (== application_from_function#0 456u)
(assert tmp%7#0) // wrong application from function
let tmp%9#0: bytes = (extract3 bytes_from_storage#0 0u 1u)
let tmp%9#0: bytes = ((extract 0 1) bytes_from_storage#0)
let tmp%10#0: uint64 = (== tmp%9#0 0x07)
(assert tmp%10#0) // wrong 0th byte from storage
let tmp%12#0: bytes = (extract3 bytes_from_storage#0 1u 1u)
let tmp%12#0: bytes = ((extract 1 1) bytes_from_storage#0)
let tmp%13#0: uint64 = (== tmp%12#0 0x08)
(assert tmp%13#0) // wrong 1st byte from storage
let tmp%15#0: bytes = (extract3 bytes_from_storage#0 2u 1u)
let tmp%15#0: bytes = ((extract 2 1) bytes_from_storage#0)
let tmp%16#0: uint64 = (== tmp%15#0 0x09)
(assert tmp%16#0) // wrong 2nd byte from storage
let tmp%17#0: uint64 = (btoi int_from_storage#0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,13 @@ contract test_cases.abi_routing.contract.Reference:
(assert tmp%6#0) // wrong application from storage
let tmp%7#0: uint64 = (== application_from_function#0 456u)
(assert tmp%7#0) // wrong application from function
let tmp%9#0: bytes = (extract3 bytes_from_storage#0 0u 1u)
let tmp%9#0: bytes = ((extract 0 1) bytes_from_storage#0)
let tmp%10#0: uint64 = (== tmp%9#0 0x07)
(assert tmp%10#0) // wrong 0th byte from storage
let tmp%12#0: bytes = (extract3 bytes_from_storage#0 1u 1u)
let tmp%12#0: bytes = ((extract 1 1) bytes_from_storage#0)
let tmp%13#0: uint64 = (== tmp%12#0 0x08)
(assert tmp%13#0) // wrong 1st byte from storage
let tmp%15#0: bytes = (extract3 bytes_from_storage#0 2u 1u)
let tmp%15#0: bytes = ((extract 2 1) bytes_from_storage#0)
let tmp%16#0: uint64 = (== tmp%15#0 0x09)
(assert tmp%16#0) // wrong 2nd byte from storage
let tmp%17#0: uint64 = (btoi int_from_storage#0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,13 @@ contract test_cases.abi_routing.contract.Reference:
(assert tmp%6#0) // wrong application from storage
let tmp%7#0: uint64 = (== application_from_function#0 456u)
(assert tmp%7#0) // wrong application from function
let tmp%9#0: bytes = (extract3 bytes_from_storage#0 0u 1u)
let tmp%9#0: bytes = ((extract 0 1) bytes_from_storage#0)
let tmp%10#0: uint64 = (== tmp%9#0 0x07)
(assert tmp%10#0) // wrong 0th byte from storage
let tmp%12#0: bytes = (extract3 bytes_from_storage#0 1u 1u)
let tmp%12#0: bytes = ((extract 1 1) bytes_from_storage#0)
let tmp%13#0: uint64 = (== tmp%12#0 0x08)
(assert tmp%13#0) // wrong 1st byte from storage
let tmp%15#0: bytes = (extract3 bytes_from_storage#0 2u 1u)
let tmp%15#0: bytes = ((extract 2 1) bytes_from_storage#0)
let tmp%16#0: uint64 = (== tmp%15#0 0x09)
(assert tmp%16#0) // wrong 2nd byte from storage
let tmp%17#0: uint64 = (btoi int_from_storage#0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,13 @@ contract test_cases.abi_routing.contract.Reference:
(assert tmp%6#0) // wrong application from storage
let tmp%7#0: uint64 = (== application_from_function#0 456u)
(assert tmp%7#0) // wrong application from function
let tmp%9#0: bytes = (extract3 bytes_from_storage#0 0u 1u)
let tmp%9#0: bytes = ((extract 0 1) bytes_from_storage#0)
let tmp%10#0: uint64 = (== tmp%9#0 0x07)
(assert tmp%10#0) // wrong 0th byte from storage
let tmp%12#0: bytes = (extract3 bytes_from_storage#0 1u 1u)
let tmp%12#0: bytes = ((extract 1 1) bytes_from_storage#0)
let tmp%13#0: uint64 = (== tmp%12#0 0x08)
(assert tmp%13#0) // wrong 1st byte from storage
let tmp%15#0: bytes = (extract3 bytes_from_storage#0 2u 1u)
let tmp%15#0: bytes = ((extract 2 1) bytes_from_storage#0)
let tmp%16#0: uint64 = (== tmp%15#0 0x09)
(assert tmp%16#0) // wrong 2nd byte from storage
let tmp%17#0: uint64 = (btoi int_from_storage#0)
Expand Down
40 changes: 20 additions & 20 deletions test_cases/abi_routing/puya.log
Original file line number Diff line number Diff line change
Expand Up @@ -1441,26 +1441,26 @@ debug: Inserted [email protected][35]: 'store tmp%6#0 to l-st
debug: Replaced [email protected][37]: 'load tmp%6#0' with 'load tmp%6#0 from l-stack (no copy)'
debug: Inserted [email protected][42]: 'store tmp%7#0 to l-stack (copy)'
debug: Replaced [email protected][44]: 'load tmp%7#0' with 'load tmp%7#0 from l-stack (no copy)'
debug: Inserted [email protected][50]: 'store tmp%9#0 to l-stack (copy)'
debug: Replaced [email protected][52]: 'load tmp%9#0' with 'load tmp%9#0 from l-stack (no copy)'
debug: Inserted [email protected][55]: 'store tmp%10#0 to l-stack (copy)'
debug: Replaced [email protected][57]: 'load tmp%10#0' with 'load tmp%10#0 from l-stack (no copy)'
debug: Inserted [email protected][63]: 'store tmp%12#0 to l-stack (copy)'
debug: Replaced [email protected][65]: 'load tmp%12#0' with 'load tmp%12#0 from l-stack (no copy)'
debug: Inserted [email protected][68]: 'store tmp%13#0 to l-stack (copy)'
debug: Replaced [email protected][70]: 'load tmp%13#0' with 'load tmp%13#0 from l-stack (no copy)'
debug: Inserted [email protected][76]: 'store tmp%15#0 to l-stack (copy)'
debug: Replaced [email protected][78]: 'load tmp%15#0' with 'load tmp%15#0 from l-stack (no copy)'
debug: Inserted [email protected][81]: 'store tmp%16#0 to l-stack (copy)'
debug: Replaced [email protected][83]: 'load tmp%16#0' with 'load tmp%16#0 from l-stack (no copy)'
debug: Inserted [email protected][87]: 'store tmp%17#0 to l-stack (copy)'
debug: Replaced [email protected][89]: 'load tmp%17#0' with 'load tmp%17#0 from l-stack (no copy)'
debug: Inserted [email protected][92]: 'store tmp%18#0 to l-stack (copy)'
debug: Replaced [email protected][94]: 'load tmp%18#0' with 'load tmp%18#0 from l-stack (no copy)'
debug: Inserted [email protected][98]: 'store tmp%19#0 to l-stack (copy)'
debug: Replaced [email protected][100]: 'load tmp%19#0' with 'load tmp%19#0 from l-stack (no copy)'
debug: Inserted [email protected][103]: 'store tmp%20#0 to l-stack (copy)'
debug: Replaced [email protected][105]: 'load tmp%20#0' with 'load tmp%20#0 from l-stack (no copy)'
debug: Inserted [email protected][48]: 'store tmp%9#0 to l-stack (copy)'
debug: Replaced [email protected][50]: 'load tmp%9#0' with 'load tmp%9#0 from l-stack (no copy)'
debug: Inserted [email protected][53]: 'store tmp%10#0 to l-stack (copy)'
debug: Replaced [email protected][55]: 'load tmp%10#0' with 'load tmp%10#0 from l-stack (no copy)'
debug: Inserted [email protected][59]: 'store tmp%12#0 to l-stack (copy)'
debug: Replaced [email protected][61]: 'load tmp%12#0' with 'load tmp%12#0 from l-stack (no copy)'
debug: Inserted [email protected][64]: 'store tmp%13#0 to l-stack (copy)'
debug: Replaced [email protected][66]: 'load tmp%13#0' with 'load tmp%13#0 from l-stack (no copy)'
debug: Inserted [email protected][70]: 'store tmp%15#0 to l-stack (copy)'
debug: Replaced [email protected][72]: 'load tmp%15#0' with 'load tmp%15#0 from l-stack (no copy)'
debug: Inserted [email protected][75]: 'store tmp%16#0 to l-stack (copy)'
debug: Replaced [email protected][77]: 'load tmp%16#0' with 'load tmp%16#0 from l-stack (no copy)'
debug: Inserted [email protected][81]: 'store tmp%17#0 to l-stack (copy)'
debug: Replaced [email protected][83]: 'load tmp%17#0' with 'load tmp%17#0 from l-stack (no copy)'
debug: Inserted [email protected][86]: 'store tmp%18#0 to l-stack (copy)'
debug: Replaced [email protected][88]: 'load tmp%18#0' with 'load tmp%18#0 from l-stack (no copy)'
debug: Inserted [email protected][92]: 'store tmp%19#0 to l-stack (copy)'
debug: Replaced [email protected][94]: 'load tmp%19#0' with 'load tmp%19#0 from l-stack (no copy)'
debug: Inserted [email protected][97]: 'store tmp%20#0 to l-stack (copy)'
debug: Replaced [email protected][99]: 'load tmp%20#0' with 'load tmp%20#0 from l-stack (no copy)'
debug: Inserted [email protected][15]: 'store tmp%2#0 to l-stack (copy)'
debug: Replaced [email protected][18]: 'load tmp%2#0' with 'load tmp%2#0 from l-stack (no copy)'
debug: Inserted [email protected][25]: 'store tmp%4#0 to l-stack (copy)'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ contract test_cases.arc4_types.array.Arc4ArraysContract:
let tmp%52#0: uint64 = (== total#5 398u)
(assert tmp%52#0)
let aliased_static#0: bytes = (concat 0x 0x65)
let tmp%55#0: bytes = (extract3 aliased_static#0 0u 1u)
let tmp%55#0: bytes = ((extract 0 1) aliased_static#0)
let tmp%56#0: uint64 = (btoi tmp%55#0)
let index_is_in_bounds%58#0: uint64 = (< 0u 1u)
(assert index_is_in_bounds%58#0) // Index access is out of bounds
let tmp%60#0: bytes = (extract3 aliased_static#0 0u 1u)
let tmp%60#0: bytes = ((extract 0 1) aliased_static#0)
let tmp%61#0: uint64 = (btoi tmp%60#0)
let tmp%62#0: uint64 = (+ tmp%56#0 tmp%61#0)
let tmp%63#0: uint64 = (== tmp%62#0 202u)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ contract test_cases.arc4_types.array.Arc4ArraysContract:
block@19: // after_for_L49
let tmp%52#0: uint64 = (== total#5 398u)
(assert tmp%52#0)
let tmp%55#0: bytes = (extract3 0x65 0u 1u)
let tmp%55#0: bytes = ((extract 0 1) 0x65)
let tmp%56#0: uint64 = (btoi tmp%55#0)
let tmp%60#0: bytes = (extract3 0x65 0u 1u)
let tmp%60#0: bytes = ((extract 0 1) 0x65)
let tmp%61#0: uint64 = (btoi tmp%60#0)
let tmp%62#0: uint64 = (+ tmp%56#0 tmp%61#0)
let tmp%63#0: uint64 = (== tmp%62#0 202u)
Expand Down
Loading

0 comments on commit 2da337e

Please sign in to comment.