This is an archive of the discontinued LLVM Phabricator instance.

[IVDescriptors] Fix bug in checkOrderedReduction
ClosedPublic

Authored by anna on Jul 26 2021, 6:45 PM.

Details

Summary

The Exit instruction passed in for checking if it's an ordered reduction need not be
an FPAdd operation. We need to bail out at that point instead of
assuming it is an FPAdd (and hence has two operands). See added testcase.
It crashes without the patch because the Exit instruction is a phi with
exactly one operand.
This latent bug was exposed by 95346ba which added support for
multi-exit loops for vectorization.

Diff Detail

Event Timeline

anna created this revision.Jul 26 2021, 6:45 PM
anna requested review of this revision.Jul 26 2021, 6:45 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 26 2021, 6:45 PM
kmclaughlin accepted this revision.Jul 27 2021, 5:53 AM

Thank you for this fix, @anna - LGTM

llvm/test/Transforms/LoopVectorize/fp-reduction-crash.ll
2

nit: I don't think REQUIRES: asserts is necessary for this test?

This revision is now accepted and ready to land.Jul 27 2021, 5:53 AM
anna added inline comments.Jul 27 2021, 6:26 AM
llvm/test/Transforms/LoopVectorize/fp-reduction-crash.ll
2

This is to show that the failure only occurs in assertions enabled mode. It will not fail in any other mode.

To put it differently, if I first landed this testcase alone, it will succeed in non-assertion enabled mode and it isn't clear what the problem is (since we cannot add XFAIL).

This revision was landed with ongoing or failed builds.Jul 27 2021, 6:31 AM
This revision was automatically updated to reflect the committed changes.
fhahn added inline comments.Jul 27 2021, 7:10 AM
llvm/test/Transforms/LoopVectorize/fp-reduction-crash.ll
2

Can you add check lines to make sure the IR is transformed as expected? That way, we do not need to rely on the asserting causing the test to crash.

fhahn added inline comments.Jul 27 2021, 7:22 AM
llvm/test/Transforms/LoopVectorize/fp-reduction-crash.ll
2

actually, can the test be added to the file already containing order reduction tests, with a comment explaining what it checks? That will help make maintaining it easier.

anna added inline comments.Jul 27 2021, 8:03 AM
llvm/test/Transforms/LoopVectorize/fp-reduction-crash.ll
2

The reason it doesn't cause any failure in non-assertion mode is that this just checks and bails out without doing vectorization. The bail out was too late. That was the only reason this crash occurred.
So, the IR is not transformed for this reduction pattern - not sure what the CHECK-LINES will do. I will add a comment explaining what it checks and move it to the order-reduction tests.

fhahn added inline comments.Jul 29 2021, 10:28 AM
llvm/test/Transforms/LoopVectorize/fp-reduction-crash.ll
2

So, the IR is not transformed for this reduction pattern - not sure what the CHECK-LINES will do. I will add a comment explaining what it checks and move it to the order-reduction tests.

Sounds good to me, thanks!