[PATCH] D36224: [CodeGen} Conditionally replace subregister uses when processing tied operands

Jesper Antonsson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 2 08:39:59 PDT 2017


JesperAntonsson created this revision.
Herald added a subscriber: wdng.

This fixes a bug in the TwoAddressInstruction pass. I work with an out-of-tree target, so I can't provide tests, but this code line was incorrectly handled:

`%vreg3<def,tied1> = subh_a16_a32_aNhDst_formatDstN32 %vreg1:hi16<tied0>, %vreg1:hi16, pred:0, pred:%noreg, pred:0, %CCReg<imp-def,dead>, %cuc<imp-use>; aNh_0_7:%vreg3 aN32_0_7:%vreg1`

it was transformed by TwoAddress into:

`%vreg3<def,tied1> = subh_a16_a32_aNhDst_formatDstN32 %vreg3<tied0>, %vreg3:hi16, pred:0, pred:%noreg, pred:0, %CCReg<imp-def,dead>, %cuc<imp-use>; aNh_0_7:%vreg3`

The problem is with this resulting operand: %vreg3:hi16. Since the transformation coalesced %vreg1 into %vreg3 which is a register of a subregister type, the hi16 should have been removed for the second, untied source operand, just as it was for the first one. (Much later, this gives rise to an assert in VirtRegRewriter.)

There was a bugfix commit 279804 made a year ago that touched the code that handle this and that bugfix I think broke this particular case. My take is that the subregister specification needs to be dropped conditionally, based on whether there was a transformation to a subregister type or not.


https://reviews.llvm.org/D36224

Files:
  lib/CodeGen/TwoAddressInstructionPass.cpp


Index: lib/CodeGen/TwoAddressInstructionPass.cpp
===================================================================
--- lib/CodeGen/TwoAddressInstructionPass.cpp
+++ lib/CodeGen/TwoAddressInstructionPass.cpp
@@ -1586,7 +1586,8 @@
             RemovedKillFlag = true;
           }
           MO.setReg(LastCopiedReg);
-          MO.setSubReg(MO.getSubReg());
+          if (SubRegB)
+            MO.setSubReg(0);
         }
       }
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36224.109350.patch
Type: text/x-patch
Size: 440 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170802/c0497731/attachment.bin>


More information about the llvm-commits mailing list