This is an archive of the discontinued LLVM Phabricator instance.

[WinEH] Fix two cases where instructions can incorrectly be inserted into EH pads
ClosedPublic

Authored by andrew.w.kaylor on Nov 19 2015, 1:12 PM.

Details

Summary

I came across two cases where instructions were being inserted above EH pad instructions that don't allow non-PHI instructions before the terminator. In one case, CodeGenPrepare was trying to sink a bitcast into a catchpad. In another case, GVN was trying to PRE a load in front of a catchpadend.

The precise conditions under which these circumstances arise are a bit involved, I think. I saw it on a branched project while compiling template-based code and couldn't come up with reduced C++ code that reproduces the problem on trunk, but both of the new IR test cases I'm adding failed for me before I applied my code changes.

Diff Detail

Repository
rL LLVM

Event Timeline

andrew.w.kaylor retitled this revision from to [WinEH] Fix two cases where instructions can incorrectly be inserted into EH pads.
andrew.w.kaylor updated this object.
andrew.w.kaylor set the repository for this revision to rL LLVM.
andrew.w.kaylor added a subscriber: llvm-commits.
majnemer edited edge metadata.Nov 19 2015, 1:20 PM

I'd commit these as two different commits seeing as how they are independent of each other.

lib/CodeGen/CodeGenPrepare.cpp
732–735 ↗(On Diff #40698)

Likewise, I'd change this to simply be UserBB->getTerminator()->isEHPad()

lib/Transforms/Scalar/GVN.cpp
1557–1560 ↗(On Diff #40698)

I believe this can be simplified to if (Pred->getTerminator()->isEHPad()) because the only case where this comes up is when the terminator is also an EH pad.

andrew.w.kaylor edited edge metadata.

Simplified isEHPad condition as suggested.

I'm happy to commit these changes separately. You are correct that they are functionally independent. It seemed like it would be easier to review them together given how similar the cases are. Will Phabricator me unhappy with me if I try to tag two different commits with the same differential revision?

majnemer accepted this revision.Nov 23 2015, 9:58 AM
majnemer edited edge metadata.

I think phab will tolerate two reference to the same differential just fine.

This revision is now accepted and ready to land.Nov 23 2015, 9:58 AM
This revision was automatically updated to reflect the committed changes.