WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

Commit 70156e10 authored by John Zhang's avatar John Zhang
Browse files

Boolean flag optimisation

remove the redundant ZEXT and EQ instructions
parent a2a343c2
Optimise on the pattern:
%cmp_res = CMPOP %a %b
%res = ZEXT <@i8> %cmp_res
%con = EQ %res @1_i8
BRANCH2 %con %blk1(...) %blk2(...)
by removing the SELECT and EQ instructions.
def _has_pattern(blk):
ops = blk.operations
assert len(ops) >= 4
last4 = ops[-4:]
assert last4[0].opname == 'mu_cmpop'
assert last4[1].opname == 'mu_convop' and last4[1].args[0].value == 'ZEXT'
assert last4[2].opname == 'mu_cmpop' and last4[2].args[0].value == 'EQ'
assert last4[3].opname == 'mu_branch2'
op_cmp, op_zext, op_eq, op_branch2 = last4
assert op_cmp.result is op_zext.args[2]
assert op_zext.result is op_eq.args[1]
assert op_eq.result is op_branch2.args[0]
return True
except AssertionError:
return False
def optimise(graphs):
for g in graphs:
for blk in g.iterblocks():
if _has_pattern(blk):
ops = blk.operations
br2 = ops[-1]
br2.args[0] = ops[-4].result
blk.operations = ops[:-3] + [ops[-1]]
from rpython.translator.interactive import Translation
from rpython.translator.mu.opt import boolflag
from rpython.translator.mu.test.test_mutyper import graph_of
from rpython.translator.mu.tool.textgraph import print_graph
def test_boolflag():
def f(x):
if x > 1:
return 3
return 0
t = Translation(f, [int], backend='mu')
g = graph_of(f, t)
assert boolflag._has_pattern(g.startblock)
assert not boolflag._has_pattern(g.startblock)
assert [op.opname for op in g.startblock.operations] == ['mu_cmpop', 'mu_branch2']
ops = g.startblock.operations
assert ops[1].args[0] is ops[0].result
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment