[PATCH] D61157: [GlobalISel] Fix constrainOperandRegClass to insert copies in the right position for reg definitions

Marcello Maggioni via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 25 15:56:58 PDT 2019


kariddi created this revision.
kariddi added reviewers: aditya_nandakumar, volkan.
Herald added subscribers: llvm-commits, Petar.Avramovic, kristof.beyls, rovka.
Herald added a project: LLVM.

There is a pretty big bug in constrainOperandRegClass when called to constrain a definition and it requires to create a new virtual register and add a corrective COPY.

When the constraining happens on a use the COPY needs to be before the instruction that contains the MachineOperand, but if we are constraining a definition it actually needs to be added after the instruction.
In addition, the COPY needs to have its operands flipped (in the use case we are copying from the old unconstrained register to the new constrained register, while in the definition case we are copying from the new constrained register that the instruction defines to the old unconstrained register).

This apparently never triggered because no globalisel backends today seem to need the constraining of a definition, but it does on an out-of-tree backend.

This patch fixes that and in addition I moved the logic to insert the copy from constrainRegToClass() to constrainOperandRegClass() as it really belonged to the second one (the first seem to be working exclusively with pure register numbers without any concept of which instruction uses it, while the second it is actually called to constrain a very specific operand and so there we already have all the information about insertion points and if it is a definition or a use of such a register)


Repository:
  rL LLVM

https://reviews.llvm.org/D61157

Files:
  include/llvm/CodeGen/GlobalISel/Utils.h
  lib/CodeGen/GlobalISel/InstructionSelector.cpp
  lib/CodeGen/GlobalISel/Utils.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61157.196742.patch
Type: text/x-patch
Size: 7838 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190425/0d91f277/attachment.bin>


More information about the llvm-commits mailing list