mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Fix bug where a<<1 was not immediately optimized, and other minor changes.
* Add a TODO. * Don't make two fold passes if DCR is off. * Remove comment about parentheses that no longer applies.
This commit is contained in:
parent
edbc240408
commit
2a617b34d0
2 changed files with 4 additions and 7 deletions
|
@ -510,15 +510,10 @@ class foldconst(object):
|
||||||
# Transforming << into multiply saves some bytes.
|
# Transforming << into multiply saves some bytes.
|
||||||
if child[1]['value'] & 31:
|
if child[1]['value'] & 31:
|
||||||
# x << 3 --> x * 8
|
# x << 3 --> x * 8
|
||||||
# Do we need parentheses for *? It depends on x
|
|
||||||
# e.g. x+3<<3 needs parentheses when converted to (x+3)*8
|
|
||||||
# We can have {<< {<< x y} 3} -> (x << y) * 8 but we can't
|
|
||||||
# have e.g. {<< {& x y} 3}; there will be explicit
|
|
||||||
# parentheses here always, so we don't need to worry.
|
|
||||||
|
|
||||||
# we have {<<, something, {CONST n}}
|
# we have {<<, something, {CONST n}}
|
||||||
# we transform it into {*, something, {CONST n}}
|
# we transform it into {*, something, {CONST n}}
|
||||||
node['nt'] = '*'
|
nt = node['nt'] = '*'
|
||||||
child[1]['value'] = 1 << (child[1]['value'] & 31)
|
child[1]['value'] = 1 << (child[1]['value'] & 31)
|
||||||
|
|
||||||
# Fall through to optimize product
|
# Fall through to optimize product
|
||||||
|
@ -624,6 +619,8 @@ class foldconst(object):
|
||||||
return
|
return
|
||||||
|
|
||||||
if nt in ('<', '>'):
|
if nt in ('<', '>'):
|
||||||
|
# TODO: If function domain is -1..INT_MAX, treat <0 as !=-1
|
||||||
|
|
||||||
# i>2147483647 to FALSE if SEF, otherwise convert to a&0
|
# i>2147483647 to FALSE if SEF, otherwise convert to a&0
|
||||||
# i<-2147483648 to FALSE if SEF, otherwise convert to a&0
|
# i<-2147483648 to FALSE if SEF, otherwise convert to a&0
|
||||||
a, b = 0, 1
|
a, b = 0, 1
|
||||||
|
|
|
@ -89,7 +89,7 @@ class optimizer(foldconst, renamer, deadcode):
|
||||||
|
|
||||||
# Make another fold pass, since RemoveDeadCode can embed expressions
|
# Make another fold pass, since RemoveDeadCode can embed expressions
|
||||||
# into other expressions and generate unoptimized code.
|
# into other expressions and generate unoptimized code.
|
||||||
if self.constfold:
|
if self.constfold and self.dcr:
|
||||||
self.FoldScript(warningpass=True)
|
self.FoldScript(warningpass=True)
|
||||||
|
|
||||||
if self.shrinknames:
|
if self.shrinknames:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue