https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65515
--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Created attachment 35124 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35124&action=edit gcc5-pr65515.patch Lightly tested fix. Basically, most of DFS::DFS_write_tree is now moved into a loop in DFS::DFS, and for most worklist items we see them twice, once with NULL w.cstate (that will result in pushing further worklist items to the stack) and then again with non-NULL w.cstate (which is the part of DFS_write_tree at the end of function. The patch reorders the processing of trees embedded in a tree, we'll process the last inserted once before the earlier inserted ones for the same tree, not sure if that is a problem or not, but from the DFS POV they are all children of the same tree. If that would be a problem, it would be possible to rewrite DFS_write_tree_body to call DFS_write_tree in reverse order. But I hope it isn't a problem.