This is an archive of the discontinued LLVM Phabricator instance.

[CGP] Fix the remove of matched phis in complex addressing mode
ClosedPublic

Authored by skatkov on Feb 26 2018, 2:25 AM.

Details

Summary

When we replace the Phi we created with matched ones it is possible that
there are two identical phi nodes in IR. And matcher is smart enough to find that
new created phi matches both of them. So we try to replace our phi node with
matched ones twice and what is bad we delete our phi node twice causing a crash.

As soon as we found that we have two identical Phi nodes it makes sense to do
a clean-up and replace one phi node by other one.
The patch implements it.

Diff Detail

Repository
rL LLVM

Event Timeline

skatkov created this revision.Feb 26 2018, 2:25 AM
john.brawn added inline comments.Mar 6 2018, 8:11 AM
lib/CodeGen/CodeGenPrepare.cpp
2952 ↗(On Diff #135876)

MV.first has already been deleted by this point, and using the value of a deleted pointer is undefined behaviour (even if you're not dereferencing it). I think this can be solved by splitting this into two loops: one which just builds up DoneMatched (which would probably be clearer if you named it something like MatchedPHINodeMapping), and then a second which iterates over DoneMatched and does the actual replacing and erasing.

2955 ↗(On Diff #135876)

identiacal

identical

skatkov updated this revision to Diff 137328.Mar 6 2018, 11:03 PM

Please take a look.

This revision is now accepted and ready to land.Mar 8 2018, 2:30 AM
This revision was automatically updated to reflect the committed changes.