Page MenuHomePhabricator

Change subtract with immediate instruction alias to use existing instruction definition.
ClosedPublic

Authored by vmedic on Apr 10 2014, 5:27 AM.

Details

Summary

Current definition of subtract with immediate instruction aliases uses CodeGenOnly defined instructions and post matcher expansion methods to emit real instructions add with immediate. However, they can directly alias add with immediate instruction and remove unnecessary definitions and code in MipsAsmParser.cpp. This patch makes no change in functionality, just removes unnecessary definitions and code.

Diff Detail

Event Timeline

LGTM.
This is a side note and something we need to fix in the future. The transformation that we do in MipsAsmParser.cpp:parseInvNum isn't entirely correct as it doesn't taking into account the size of the operands. For example, subu $2,-32768 is equivalent to addu $2, $2, 32768 but 32768 isn't encodable. We should load the immediate into $at and then use $at in the arithmetic instruction. While we don't do this, shall we emit an error message so that we don't end up with a wrong encoded immediate ?

Yes, the number should be parsed as immediate and then converted according to the size, that was the idea behind complex expansion. However, I'm facing difficulties with aliases right now, since the number of operands in alias may not correspond the number of operands in definition and that causes access violation.

Yes, the number should be parsed as immediate and then converted according to the size

This is probably what you meant but just to be sure: It should be parsed as a generic integer, tested as an integer of the right size, then rendered to the MCInst as a generic integer. You only need to override the predicate function.

Yes, that is what I meant in general, but I need to make some tests to see weather the inverted or original value is more suitable for size check and later conversion.

dsanders accepted this revision.Apr 14 2014, 8:59 AM

LGTM.

vmedic closed this revision.Dec 1 2014, 7:43 AM