[PATCH] D119088: [DAG] Fix in ReplaceAllUsesOfValuesWith

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 6 11:04:23 PST 2022


bjope created this revision.
bjope added reviewers: RKSimon, niravd, spatel, craig.topper, lattner.
Herald added a subscriber: hiraditya.
bjope requested review of this revision.
Herald added a project: LLVM.

When doing SelectionDAG::ReplaceAllUsesOfValuesWith a worklist is
prepared containing all users that should be updated. Then we use
the RemoveNodeFromCSEMaps/AddModifiedNodeToCSEMaps helpers to handle
recursive CSE updates while doing the replacements.

This patch aims at solving a problem that could arise if the recursive
CSE updates would result in an SDNode present in the worklist is being
removed as a side-effect of morphing a prio user in the worklist.

To examplify such a scenario, imagine that we have these nodes in
the DAG

  t12: i64 = add t8, t11
  t13: i64 = add t12, t8
  t14: i64 = add t11, t11
  t15: i64 = add t14, t8
  t16: i64 = sub t13, t15

and that the t8 uses should be replaced by t11. An initial worklist
(listing the users that should be morphed) could be [t12, t13, t15].
When updating t12 we get

  t12: i64 = add t11, t11

which results in a CSE update that replaces t14 by t12, so we get

  t15: i64 = add t12, t8

which results in a CSE update that replaces t13 by t12, so we get

  t16: i64 = sub t12, t15

and then t13 is removed given that it was the last use of t13.

So when being done with the updates triggered by rewriting the use
of t8 in t12 the t13 node no longer exist. And we used to end up
hitting an assertion when continuing with the worklist aiming at
replacing the t8 uses in t13.

The solution is based on using a DAGUpdateListener, making sure that
we prune a user from the worklist if it is removed during the
recursive CSE updates.

The bug was found using an OOT target. I think the problem is quite
old, even if the particular intree target reproducer added in this
patch seem to pass when using LLVM 13.0.0.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119088

Files:
  llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
  llvm/test/CodeGen/AArch64/bbi-63928-ReplaceAllUsesOfValuesWith.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119088.406267.patch
Type: text/x-patch
Size: 4621 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220206/8f6d6d8d/attachment.bin>


More information about the llvm-commits mailing list