This is an archive of the discontinued LLVM Phabricator instance.

[WIP][SimplifyCFG] Replace FoldTwoEntryPHINode i1 hack with a different hack.
AbandonedPublic

Authored by efriedma on Jul 22 2021, 1:47 PM.

Details

Summary

Both of these hacks are designed to handle @test9 in llvm/test/Transforms/SimplifyCFG/switch_create.ll (and a duplicate copy of the test in switch_create-custom-dl.ll). There are side-effects on a couple other tests, but nothing really significant, as far as I can tell, except for two-entry-phi-node.ll.

The new test two-entry-phi-node.ll seems to test i1 heuristic itself, but doesn't really give any hint why we want that heuristic.

I'd appreciate any feedback if this makes sense, or if anyone has testcases that showcase the practical effects of the heuristic. I have an internal testcase where killing off the i1 heuristic helps, but it's not in a state where I can post it.

(See also discussion at https://reviews.llvm.org/rG5419b671375c)

Diff Detail

Event Timeline

efriedma created this revision.Jul 22 2021, 1:47 PM
efriedma requested review of this revision.Jul 22 2021, 1:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 22 2021, 1:47 PM

I like this, it's far less fragile,
but as https://bugs.llvm.org/show_bug.cgi?id=51149 reports,
there are some bad performance concerns with FoldTwoEntryPHINode,
and in fact i just tuned/fixed heuristic in rG7ef6f019090f3979fa345105b9ac95ac589c6cf9
to workaround them.

Presumably FoldTwoEntryPHINode is missing some other profitability check.
Not sure about plain build, but we could at least try to use branch weights.

As far as I can tell, there's nothing specifically wrong with flattening i1 values. Maybe we're slightly underestimating the cost of some of these i1 logic ops on x86? The more general issue is some combination of flattening the CFG too aggressively, and not unflattening aggressively enough before SelectionDAG, I think. Unfortunately, that's a delicate area to mess with; any change will inevitably break something.

As far as I can tell, there's nothing specifically wrong with flattening i1 values. Maybe we're slightly underestimating the cost of some of these i1 logic ops on x86? The more general issue is some combination of flattening the CFG too aggressively, and not unflattening aggressively enough before SelectionDAG, I think. Unfortunately, that's a delicate area to mess with; any change will inevitably break something.

I agree with everything said above.

I guess, then, the question is what order we want to do things in. Do we land this essentially as-is, then try to come up with a more reliable way to handle the cases that fall out? Or do we put this on hold until we have improvements to cost estimation and/or CFG unflattening?

I guess, then, the question is what order we want to do things in. Do we land this essentially as-is, then try to come up with a more reliable way to handle the cases that fall out? Or do we put this on hold until we have improvements to cost estimation and/or CFG unflattening?

If this goes in as-is right now, @wmi will re-raise https://bugs.llvm.org/show_bug.cgi?id=51149
If that's fine, then let's do it, else i guess we need to try to do some legwork first.
Let me see if i can add some branch weights checks to these transforms first.

Since we'll probably be unfortunate enough to have to deal with perf regressions anyways,
my plan is to merge FoldTwoEntryPHINode and SpeculativelyExecuteBB enhancing their collective functionality
and dropping the hacks.

Matt added a subscriber: Matt.Jan 7 2022, 8:58 AM
efriedma abandoned this revision.Mar 3 2022, 10:29 AM

This is obsolete, I think.

Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2022, 10:29 AM

This is obsolete, I think.

Funny enough, i just looked at removing that hack yesterday, and it breaks quite a lot of tests,
including that one phase ordering one about function merging.

llvm/lib/Transforms/Utils/SimplifyCFG.cpp