Skip to content

Commit

Permalink
feat: Optimise constant mod expressions and pre-check for div 0 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanmenzel committed Jan 31, 2024
1 parent 8788798 commit 24c5020
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/puya/ir/optimize/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,13 @@ def try_simplify_arithmetic_ops(value: models.ValueProvider) -> models.ValueProv
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)
c = a_const // b_const
case AVMOp.mod:
if b_const == 0:
raise CodeError("mod would fail at runtime (div 0)", b.source_location)
c = a_const % b_const
case AVMOp.lt:
c = 1 if a_const < b_const else 0
case AVMOp.lte:
Expand Down

0 comments on commit 24c5020

Please sign in to comment.