[all-commits] [llvm/llvm-project] 74e603: [TargetLowering] Use HandleSDNodes to prevent node...

Craig Topper via All-commits all-commits at lists.llvm.org
Thu Mar 4 22:51:41 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 74e6030bcbcc8e628f9a99a424342a0c656456f9
      https://github.com/llvm/llvm-project/commit/74e6030bcbcc8e628f9a99a424342a0c656456f9
  Author: Craig Topper <craig.topper at sifive.com>
  Date:   2021-03-04 (Thu, 04 Mar 2021)

  Changed paths:
    M llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
    A llvm/test/CodeGen/X86/pr49393.ll

  Log Message:
  -----------
  [TargetLowering] Use HandleSDNodes to prevent nodes from being deleted by recursive calls in getNegatedExpression.

For binary or ternary ops we call getNegatedExpression multiple
times and then compare costs. While we're doing this we need to
hold a node from the first call across the second call, but its
not yet attached to the DAG. Its possible the second call creates
an identical node and then decides it didn't need it so will try
to delete it if it has no uses. This can cause a reference to the
node we're holding further up the call stack to become invalidated.

To prevent this, we can use a HandleSDNode to artifically give
the node a use without connecting it to the DAG.

I've used a std::list of HandleSDNodes so we can create handles
only when we have a node to hold. HandleSDNode does not have
default constructor and cannot be copied or moved.

Fixes PR49393.

Reviewed By: spatel

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




More information about the All-commits mailing list