[PATCH] D140417: [SelectionDAG] Fix EmitCopyFromReg for cloned nodes

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 20 09:54:26 PST 2022


foad created this revision.
foad added a reviewer: AMDGPU.
Herald added subscribers: kosarev, ecnelises, kerbowa, hiraditya, jvesely.
Herald added a project: All.
foad requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Change EmitCopyFromReg to check all users of cloned nodes (as well as
non-cloned nodes) instead of assuming that they all copy the defined
value back to the same physical register.

This partially reverts 968e2e7b3db1 (svn r62356) which claimed:

  CreateVirtualRegisters does trivial copy coalescing. If a node def is
  used by a single CopyToReg, it reuses the virtual register assigned to
  the CopyToReg. This won't work for SDNode that is a clone or is itself
  cloned. Disable this optimization for those nodes or it can end up
  with non-SSA machine instructions.

This is true for CreateVirtualRegisters but r62356 also updated
EmitCopyFromReg where it is not true. Firstly EmitCopyFromReg only
coalesces physical register copies, so the concern about SSA form does
not apply. Secondly making the loop over users in EmitCopyFromReg
conditional on `!IsClone && !IsCloned` breaks the handling of cloned
nodes, because it leaves MatchReg set to true by default, so it assumes
that all users will copy the defined value back to the same physical
register instead of actually checking.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140417

Files:
  llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
  llvm/test/CodeGen/AMDGPU/bug-sdag-emitcopyfromreg.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140417.484306.patch
Type: text/x-patch
Size: 5524 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221220/e2835802/attachment.bin>


More information about the llvm-commits mailing list