Skip to content
Snippets Groups Projects
Commit 8c9efd40 authored by Jayke Meijer's avatar Jayke Meijer
Browse files

Changed algebraic transformations to more generic form.

parent 5aba6a1e
No related branches found
No related tags found
No related merge requests found
......@@ -220,11 +220,11 @@ def copy_propagation(block):
def algebraic_transformations(block):
"""
Change ineffective or useless algebraic transformations. Handled are:
- x = x + 0 -> remove
- x = x - 0 -> remove
- x = x * 1 -> remove
- x = x * 0 -> x = 0
- x = x * 2 -> x = x << 1
- x = y + 0 -> x = y
- x = y - 0 -> x = y
- x = y * 1 -> x = y
- x = y * 0 -> x = 0
- x = y * 2 -> x = x << 1
"""
changed = False
......@@ -232,10 +232,10 @@ def algebraic_transformations(block):
s = block.read()
if (s.is_command('addu') or s.is_command('subu')) and s[2] == 0:
block.replace(1, [])
block.replace(1, [S('command', 'move', s[0], s[1])])
changed = True
elif s.is_command('mult') and s[2] == 1:
block.replace(1, [])
block.replace(1, [S('command', 'move', s[0], s[1])])
changed = True
elif s.is_command('mult') and s[2] == 0:
block.replace(1, [S('command', 'li', '$1', to_hex(0))])
......
......@@ -78,7 +78,8 @@ class TestOptimizeAdvanced(unittest.TestCase):
self.assertTrue(algebraic_transformations(block))
self.assertEqual(block.statements, [self.foo,
self.bar])
S('command', 'move', '$1', '$2'),
self.bar])
def test_algebraic_transforms_add1(self):
arguments = [self.foo,
......@@ -96,7 +97,8 @@ class TestOptimizeAdvanced(unittest.TestCase):
self.assertTrue(algebraic_transformations(block))
self.assertEqual(block.statements, [self.foo,
self.bar])
S('command', 'move', '$1', '$2'),
self.bar])
def test_algebraic_transforms_sub1(self):
arguments = [self.foo,
......@@ -124,7 +126,8 @@ class TestOptimizeAdvanced(unittest.TestCase):
self.assertTrue(algebraic_transformations(block))
self.assertEqual(block.statements, [self.foo,
self.bar])
S('command', 'move', '$1', '$2'),
self.bar])
def test_algebraic_transforms_mult2(self):
block = B([self.foo,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment