OSDN Git Service

[TargetLowering] Use HandleSDNodes to prevent nodes from being deleted by recursive...
authorCraig Topper <craig.topper@sifive.com>
Fri, 5 Mar 2021 06:30:38 +0000 (22:30 -0800)
committerTom Stellard <tstellar@redhat.com>
Tue, 9 Mar 2021 04:15:54 +0000 (20:15 -0800)
commitbff59aca162ef16d7634dc9df39f1f3af31ecb93
treef64bea68cd4420db09e65f46f567a83718b5fc5f
parenta123beacce408af8c2de1f39d522ac6b6c4b5d1b
[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

(cherry picked from commit 74e6030bcbcc8e628f9a99a424342a0c656456f9)
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
llvm/test/CodeGen/X86/pr49393.ll [new file with mode: 0644]