Merge pull request #6935 from ethereum/subMaxValueXNotXRule

Add optimization rule SUB(~0, X) -> NOT(X).
This commit is contained in:
chriseth
2019-06-17 14:42:49 +02:00
committed by GitHub
3 changed files with 28 additions and 0 deletions
@@ -0,0 +1,26 @@
from rule import Rule
from opcodes import *
"""
Rule:
SUB(~0, X) -> NOT(X)
Requirements:
"""
rule = Rule()
n_bits = 256
# Input vars
X = BitVec('X', n_bits)
# Constants
ZERO = BitVecVal(0, n_bits)
# Non optimized result
nonopt = SUB(~ZERO, X)
# Optimized result
opt = NOT(X)
rule.check(nonopt, opt)