[all-commits] [llvm/llvm-project] 43a91a: [SelectionDAG] Don't create illegally-typed nodes ...

Fraser Cormack via All-commits all-commits at lists.llvm.org
Wed Mar 30 05:29:34 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 43a91a8474f55241404199f6b8798ac6467c2687
      https://github.com/llvm/llvm-project/commit/43a91a8474f55241404199f6b8798ac6467c2687
  Author: Fraser Cormack <fraser at codeplay.com>
  Date:   2022-03-30 (Wed, 30 Mar 2022)

  Changed paths:
    M llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
    A llvm/test/CodeGen/RISCV/rvv/constant-folding-crash.ll

  Log Message:
  -----------
  [SelectionDAG] Don't create illegally-typed nodes while constant folding

This patch fixes a (seemingly very rare) crash during vector constant
folding introduced in D113300.

Normally, during legalization, if we create an illegally-typed node during
a failed attempt at constant folding it's cleaned up before being
visited, due to it having no uses.

If, however, an illegally-typed node is created during one round of
legalization and isn't cleaned up, it's possible for a second round of
legalization to create new illegally-typed nodes which add extra uses to
the old illegal nodes. This means that we can end up visiting the old
nodes before they're known to be dead, at which point we crash.

I'm not happy about this fix. Creating illegal types at all seems like a
bad idea, but we all-too-often rely on illegal constants being
successfully folded and being fixed up afterwards. However, we can't
rely on constant folding actually happening, and we don't have a
foolproof way of peering into the future.

Perhaps the correct fix is to revisit the node-iteration order during
legalization, ensuring we visit all uses of nodes before the nodes
themselves. Or alternatively we could try and clean up dead nodes
immediately after failing constant folding.

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D122382




More information about the All-commits mailing list