Skip to content

Commit

Permalink
Optimizer: Implement removal of no-op MOVs
Browse files Browse the repository at this point in the history
  • Loading branch information
64kramsystem committed Oct 25, 2021
1 parent fdb8b85 commit d898afc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/fisk/optimizer.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
class Fisk
class Optimizer
def optimize(insn)
insn
case insn.insn.name
when Instructions::MOV.name
if insn.operands[0].register? && insn.operands[1].register? && insn.operands[0].name == insn.operands[1].name
return nil
end
end

return insn
end
end
end
10 changes: 10 additions & 0 deletions test/test_performance_optimization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,15 @@ def test_no_change
#
assert_equal buf.string, "\x4D\x89\xD1".b
end

def test_remove_no_op_instruction
buf = StringIO.new(''.b)

fisk.mov R9, R9

fisk.write_to buf

assert_equal buf.string, "".b
end
end
end

0 comments on commit d898afc

Please sign in to comment.