Skip to content

Commit

Permalink
fix: Don't raise on div 0 in optimizer as the operation might be pre-…
Browse files Browse the repository at this point in the history
…checked for != 0 in previous operations
  • Loading branch information
tristanmenzel committed Jan 31, 2024
1 parent 4d2eb31 commit 6d549ed
Show file tree
Hide file tree
Showing 93 changed files with 13,009 additions and 13,365 deletions.
340 changes: 169 additions & 171 deletions examples/amm/puya.log

Large diffs are not rendered by default.

340 changes: 169 additions & 171 deletions examples/auction/puya.log

Large diffs are not rendered by default.

340 changes: 169 additions & 171 deletions examples/calculator/puya.log

Large diffs are not rendered by default.

340 changes: 169 additions & 171 deletions examples/global_state/puya.log

Large diffs are not rendered by default.

361 changes: 182 additions & 179 deletions examples/hello_world/puya.log

Large diffs are not rendered by default.

340 changes: 169 additions & 171 deletions examples/local_state/puya.log

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions examples/sizes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ abi_routing 795 730
address_constant 43 43
amm 1198 1131
application 163 163
arc4_types/array 603 487
arc4_types/array 622 487
arc4_types/bool 322 59
arc4_types/dynamic_string_array 249 167
arc4_types/mutation 2886 1823
arc4_types/mutation 2926 1861
arc4_types/numeric 353 214
arc4_types/string 344 305
arc4_types/structs 291 221
Expand All @@ -26,7 +26,7 @@ conditional_execution 380 344
conditional_expressions 228 182
contains 155 156
edverify 39 33
enumeration 542 506
enumeration 633 586
everything 467 457
global_state 319 315
hello_world 19 18
Expand All @@ -37,21 +37,22 @@ less_simple 93 87
local_state/local_state_contract 319 314
local_state/local_state_with_offsets 332 326
match 486 467
nested_loops 228 203
scratch_slots 64 63
scratch_slots/contract2 64 63
nested_loops 369 203
reversed_iteration 783 618
scratch_slots 78 63
scratch_slots/contract2 78 63
simple 51 4
simplish 741 725
ssa 235 212
ssa2 49 46
ssa 267 212
ssa2 77 46
string_ops 150 148
stubs/biguint 158 140
stubs/bytes 645 4
stubs/uint64 366 4
transaction 685 677
tuple_support 434 306
tuple_support 455 326
unary 129 92
undefined_phi_args/baddie 346 346
unssa 433 378
voting/voting 1594 1530
unssa 473 420
voting/voting 1646 1565
with_reentrancy 259 240
340 changes: 169 additions & 171 deletions examples/voting/puya.log

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions src/puya/ir/optimize/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,9 @@ def try_simplify_arithmetic_ops(value: models.ValueProvider) -> models.ValueProv
c = a_const - b_const
case AVMOp.mul:
c = a_const * b_const
case AVMOp.div_floor:
if b_const == 0:
raise CodeError("// would fail at runtime (div 0)", b.source_location)
case AVMOp.div_floor if b_const != 0:
c = a_const // b_const
case AVMOp.mod:
if b_const == 0:
raise CodeError("mod would fail at runtime (div 0)", b.source_location)
case AVMOp.mod if b_const != 0:
c = a_const % b_const
case AVMOp.lt:
c = 1 if a_const < b_const else 0
Expand Down
340 changes: 169 additions & 171 deletions test_cases/abi_routing/puya.log

Large diffs are not rendered by default.

340 changes: 169 additions & 171 deletions test_cases/address_constant.puya.log

Large diffs are not rendered by default.

340 changes: 169 additions & 171 deletions test_cases/application/puya.log

Large diffs are not rendered by default.

2,003 changes: 983 additions & 1,020 deletions test_cases/arc4_types/out/mutation.approval.debug.teal

Large diffs are not rendered by default.

Loading

0 comments on commit 6d549ed

Please sign in to comment.