This is an archive of the discontinued LLVM Phabricator instance.

[ConstantHoisting] Fix bug where constant materialization could insert into EH pad
ClosedPublic

Authored by Holman on Jan 19 2021, 9:27 PM.

Details

Summary

If the incoming block to a phi node is an EH pad, then we will materialize into an EH pad, which is not supposed to happen. To fix this, I added a check to see if incoming block of a phi node is an EH pad before using it as the insertion point.

Diff Detail

Event Timeline

Holman created this revision.Jan 19 2021, 9:27 PM
Holman requested review of this revision.Jan 19 2021, 9:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 19 2021, 9:27 PM

This bug is causing Edge builds to fail when using new builds of Clang, so I would appreciate if someone could please take a look.

Also, CI failures look unrelated to this change and I was not able to repro them if I rebase change onto latest main.

nikic added a subscriber: nikic.Jan 21 2021, 11:48 AM

This needs a test case. See llvm/test/Transforms/ConstantHoisting for existing tests for this pass.

rnk added a comment.Jan 21 2021, 1:19 PM

Out of curiosity, have you bisected this to a particular change?

llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
190

Are you sure you meant to shadow the outer variable here? InsertionBlock will be null in the case you are trying to handle, a phi, preceded by a catchswitch, and I'm not sure what DT->getNode(nullptr) returns.

In D95019#2513466, @rnk wrote:

Out of curiosity, have you bisected this to a particular change?

I haven't. It was crashing LTO build so repro was time consuming. I was trying to find recent changes that might have allowed more hoisting to happen, but there wasn't anything obvious to me. We took a compiler drop around 11/25 and then the next one we took on 1/3 was failing.

llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
190

Good catch, thanks! I originally just copy/pasted the EH loop when I was testing and must have introduced that bug when I refactored.

This needs a test case. See llvm/test/Transforms/ConstantHoisting for existing tests for this pass.

I'm working on a test case, but my repro was massive, and hand writing the IR for this is a bit tricky.

Holman updated this revision to Diff 318310.Jan 21 2021, 1:57 PM

Fix shadowing bug.

Holman updated this revision to Diff 319087.Jan 25 2021, 12:26 PM

Added a unit test

Looks like my new test is passing in CI, but Debian CI is failing for some unrelated reason.

Holman updated this revision to Diff 320191.Jan 29 2021, 12:34 PM

Address clang-tidy comment.

This revision was not accepted when it landed; it landed in state Needs Review.Feb 1 2021, 11:24 AM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.