This is an archive of the discontinued LLVM Phabricator instance.

[LLVM][Uniformity] Fix error causing assert on some irreducible control flow
ClosedPublic

Authored by AlexM on Aug 15 2023, 12:36 PM.

Details

Summary

As the test case demonstrates, it is possible for a block to be identified as a
join point while not being the header of a reducible cycle. To address this,
when searching for the outermost cycle made divergent by branch outside it, we
first check for an irreducible outermost cycle before checking if the parent is
reducible.

Diff Detail

Event Timeline

AlexM created this revision.Aug 15 2023, 12:36 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 15 2023, 12:36 PM
AlexM updated this revision to Diff 550435.Aug 15 2023, 12:38 PM

cleanup test case

AlexM published this revision for review.Aug 15 2023, 12:39 PM
AlexM added a reviewer: sameerds.
Herald added a project: Restricted Project. · View Herald TranscriptAug 15 2023, 12:40 PM
sameerds requested changes to this revision.Aug 16 2023, 2:59 AM
sameerds added inline comments.
llvm/include/llvm/ADT/GenericUniformityImpl.h
950

We shouldn't remove the assert. Instead, this whole "if block" should be moved after the while loop below.

The reasoning is like this: When divergent paths enter an irreducible cycle, we assume that everything inside the cycle is divergent. But the way ModifiedPO works, every block inside the cycle gets marked as a join block. This is okay, because the exits get labelled as themselves which allows the traversal to find actual joins outside (or beyond) the cycle.

So when we want to check a join block inside a cycle C relative to a divergent branch outside of C, we should first check if there is an irreducible parent of C that does not contain the branch. If there is such a parent, then whether C is reducible is not relevant. If there is no irreducible parent, then we can check if C is reducible.

Returning early like the current code, by just checking the parent cycle looks like a bug because it fails to return the irreducible parent as the "cycle made divergent". But other join blocks in the irreducible parent will cause it to be eventually reported, so it's okay.

This revision now requires changes to proceed.Aug 16 2023, 2:59 AM
sameerds added a subscriber: Restricted Project.
AlexM updated this revision to Diff 550779.Aug 16 2023, 9:06 AM

Address comment; move if below while loop.

AlexM marked an inline comment as done.Aug 16 2023, 9:07 AM

Okay, makes sense. I've updated as suggested.

AlexM retitled this revision from [LLVM][Uniformity] Remove assert thrown on some irreducible control flow to [LLVM][Uniformity] Fix error causing assert on some irreducible control flow.Aug 16 2023, 9:10 AM
AlexM edited the summary of this revision. (Show Details)
sameerds accepted this revision.Aug 16 2023, 8:52 PM

Can you please reword the change description? Rather than talking about the code in terms of if/while, it's more helpful to talk about what is happening. For example, "we should first check for an irreducible outermost cycle before checking if the parent is reducible".

This revision is now accepted and ready to land.Aug 16 2023, 8:52 PM
AlexM edited the summary of this revision. (Show Details)Aug 17 2023, 10:56 AM

Okay, I've updated the description, @sameerds could you please submit this on my behalf?

@AlexM FYI: submitted a different fix in the same location: 4d081560cd3b6ac114aee15f50480dd978b55a44