[LLVMdev] Unnecessary moves after sign-extension in 2-address target

Greg McGary greg at mcgary.org
Tue Apr 21 16:02:38 PDT 2009

Dan Gohman wrote:
> On Apr 19, 2009, at 6:15 PM, Greg McGary wrote:
>> Because sextb_r and sextw_r have destination tied to source operands,
>> TwoAddressInstructionPass thinks it needs a copy.  However, since the
>> sext kills its source, the copy is unnecessary.  Why does this happen?
>> Is TwoAddressInstructionPass relying on a later pass to notice this  
>> and
>> transform it again?
> Yes, the later pass is the coalescer. It would be worthwhile to
> understand why it is not coalescing the copies.

I discovered a curious phenomenon:

The copies are necessary because TwoAddressInstructionPass commutes
the second add.  When I suppress the commute, the movs disappear and
the code became optimal.  It seems the two-address commuter is either buggy
or inherently short-sighted/simple-minded and paints itself into a corner.

How do you recommend I approach this problem?


More information about the llvm-dev mailing list