[PATCH] D44571: [CGP] Avoid segmentation fault when doing PHI node simplifications

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 16 09:30:27 PDT 2018


bjope created this revision.

Made PHI node simplifiations more robust in several ways:

- Minor refactoring to let the SimplificationTracker own the

sets with new PHI/Select nodes that are introduced. This is
maybe not mapping to the original intention with the
SimplificationTracker, but IMHO it encapsulates the logic behind
those sets a little bit better.

- MatchPhiNode can sometimes populate the Matched set with

several entries, where it maps one PHI node to different candidates
for replacement. The Matched set is changed into a SmallSetVector
to make sure we get a deterministic iteration when doing
the replacements.

- As described above we may get several different replacements

for a single PHI node. The loop in MatchPhiSet that is doing
the replacements could end up calling eraseFromParent several
times for the same PHI node, resulting in segmentation faults.
Now we simply skip already replaced PHI nodes when doing the
replacement in SimplificationTracker::ReplacePhi.

- It was really hard to track down the fault described above

(segementation fault due to doing eraseFromParent multiple
times for the same instruction). The fault was intermittent and
small changes in the code, or simply turning on -print-after-all
etc could make the problem go away. This was basically due to
the iteration over PhiNodesToMatch in MatchPhiSet no being
deterministic. Therefore I've changed the data structure for
the SimplificationTracker::AllPhiNodes into an SmallSetVector.
This gives a deterministic behavior.


Repository:
  rL LLVM

https://reviews.llvm.org/D44571

Files:
  lib/CodeGen/CodeGenPrepare.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44571.138725.patch
Type: text/x-patch
Size: 10101 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180316/85b27494/attachment.bin>


More information about the llvm-commits mailing list