This is an archive of the discontinued LLVM Phabricator instance.

[SimplifyCFG] Prohibit hoisting of llvm.deoptimize calls
ClosedPublic

Authored by dmakogon on Dec 6 2022, 8:34 AM.

Details

Summary

This prohibits hoisiting identical llvm.deoptimize calls from 'then' and 'else' blocks of a conditional branch.
This fixes a crash that happened because we didn't hoist the return instructions together with the llvm.deoptimize calls, so the verifier would crash.

Diff Detail

Event Timeline

dmakogon created this revision.Dec 6 2022, 8:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 6 2022, 8:34 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
dmakogon requested review of this revision.Dec 6 2022, 8:34 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 6 2022, 8:34 AM
dmakogon edited the summary of this revision. (Show Details)Dec 6 2022, 8:36 AM
mkazantsev added inline comments.Dec 6 2022, 11:37 PM
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
1521

To me it looks like overkill. As far as I understand the problem, the crash happens when we hoist the deoptimize call which is then not followed by return after this hoisting. Hoisting any other instruction is perfectly legal, and it also reduces code size. Let's make the fix as non-invasive as possible.

I still think that the requirement to have deoptimize immediately followed by return is useless and weird, but it's out of scope of this one. Until cancelled, we should sustain it.

mkazantsev requested changes to this revision.Dec 6 2022, 11:38 PM
This revision now requires changes to proceed.Dec 6 2022, 11:38 PM
dmakogon updated this revision to Diff 480785.Dec 6 2022, 11:46 PM
dmakogon retitled this revision from [SimplifyCFG] Prohibit hoisting from deoptimize blocks to [SimplifyCFG] Prohibit hoisting of llvm.deoptimize calls.
dmakogon edited the summary of this revision. (Show Details)

Instead of prohibiting hoisting from deoptimize blocks, just disallow hoisiting of llvm.deoptimize calls

mkazantsev accepted this revision.Dec 6 2022, 11:52 PM

That will do, please wait a day or two if anyone has concerns.

This revision is now accepted and ready to land.Dec 6 2022, 11:52 PM
dmakogon marked an inline comment as done.Dec 7 2022, 12:37 AM
fhahn accepted this revision.Dec 7 2022, 4:37 AM

LGTM, thanks! Would be good to simplify the bundle if possible.

llvm/test/Transforms/SimplifyCFG/dont-hoist-deoptimize.ll
31

Is this massive bundle needed or can it be reduced?

Same for the bundle below.

dmakogon marked an inline comment as done.Dec 9 2022, 2:45 AM
dmakogon added inline comments.
llvm/test/Transforms/SimplifyCFG/dont-hoist-deoptimize.ll
31

Yeah, they may be reduced. Thanks! Landed reduced version

This revision was automatically updated to reflect the committed changes.
dmakogon marked an inline comment as done.