[llvm-dev] TwoAddressInstructionPass::isProfitableToConv3Addr()

Steve King via llvm-dev llvm-dev at lists.llvm.org
Tue Sep 29 08:57:59 PDT 2015


On Tue, Sep 29, 2015 at 2:00 AM, Jonas Paulsson via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> I have cases of instruction pairs, where one is cheaper 2-address, and the
> other 3-address. I would like to select the 2-addr instruction during isel,
> but use the 3-addr instruction to avoid a copy if possible.
> I would like to say "If 3-addr version would avoid a copy, use it!". Does
> anyone else have a similar situation?

Hi Jonas - Not what you asked for, but stick with 3-addr instructions,
then convert opportunistically to two-addr as a late pass.  This
approach reduces complexity since you need no longer worry about
surrounding instructions to make the 3->2 conversion.  In other words,
convert FOO A,B,B ---> FOO A,B where you find them.  Worked great in
my target.

>
> To do this, one would need to check the kill-flag on the tied use operand.
> If it is not killed, one can assume that the use and dst registers overlap,
> and therefore the copy is needed for the two-address form. The kill flags
> would however need to be recomputed by TwoAddr pass, since
> LiveVariables clear them.

All this is the complexity you can avoid.

HTH,
-steve


More information about the llvm-dev mailing list