This is an archive of the discontinued LLVM Phabricator instance.

[MachineSink] Fix for breaking phi edges with instructions with multiple defs
ClosedPublic

Authored by dmgreen on Apr 14 2020, 12:41 AM.

Details

Summary

BreakPHIEdge would be set based on whether the instruction needs to insert a new critical edge to allow sinking into a block where the uses are PHI nodes. But for instructions with multiple defs it would be reset on the second def, allowing the instruciton to sink where it should not.

Diff Detail

Event Timeline

dmgreen created this revision.Apr 14 2020, 12:41 AM

Hi Dave, thanks for fixing this. Probably good to mention in the description that this is fixing PR44981.
Some nits inlined.

llvm/lib/CodeGen/MachineSink.cpp
279–280

Fair enough, I am not that familiar with this code, but reading the example above for the first time, I didn't find it that informative, i.e. the description is clear, the example isn't really. But since you're making changes to how this works, it's probably best to add that here as a comment: that we only change the global value when we found a local one, and say something about that example IR.

dmgreen updated this revision to Diff 257356.Apr 14 2020, 8:44 AM

Thanks. I've tried to adjust the comment and changed the condition to use all_of.

With multiple defs we might end up with one def being used by phi nodes, and another not (but used/dominated by the same block). BreakPHIEdge seems to be checking for if _all_ uses are phi nodes in the same block, but I don't see a problem with only some being phis.

SjoerdMeijer accepted this revision.Apr 14 2020, 9:26 AM

Ah, yeah, cheers. And I like this a lot more now.
This LGTM, but please wait a day in case someone else has other opinions.

This revision is now accepted and ready to land.Apr 14 2020, 9:26 AM
lkail added a subscriber: lkail.Apr 16 2020, 7:28 AM

Ooops, I didn't see this patch and post another https://reviews.llvm.org/D78297. It can fix https://bugs.llvm.org/show_bug.cgi?id=45557. Thanks for the patch.

Ah, it looks like this came up in a couple of places now.

Let me go and commit this one to get it out of the way. We can see if it fixes both bugs..

fhahn added inline comments.Apr 16 2020, 8:51 AM
llvm/lib/CodeGen/MachineSink.cpp
282

nit: llvm:: not needed?

llvm/test/CodeGen/ARM/machine-sink-multidef.ll
2

nit: Would be great to have a MIR test for this :)

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptApr 16 2020, 8:55 AM
dmgreen marked an inline comment as done.Apr 16 2020, 12:49 PM
dmgreen added inline comments.
llvm/test/CodeGen/ARM/machine-sink-multidef.ll
2

Ah, I was committing before I got the message.

I'll see what I can cook up.