This is an archive of the discontinued LLVM Phabricator instance.

[SimpleLoopUnswitch] Fix SCEV invalidation for unswitchTrivialSwitch
ClosedPublic

Authored by bjope on Mar 27 2023, 7:17 AM.

Details

Summary

When doing a trivial unswitch of a switch statement the code need
to "invalidate SCEVs for the outermost loop reached by any of the
exits", as indicated by code comments.

Depending on if we find such an outermost loop or not we can limit
the invalidation to some sub-loops or the full loop-nest. As shown
in the added test case there seem to have been some bugs in the code
that was finding the "outermost loop", so we could end up invalidating
too few loops.

Seems like commit 1bf8ae17f5e2714c8c87978 introduce the bug by
moving the code that invalidates the loops above some of the code
that computed 'OuterL'. This patch fixes that by also moving that
computation of 'OuterL' so that we compute 'OuterL' properly before
we use it for the SCEV invalidation.

Diff Detail

Event Timeline

bjope created this revision.Mar 27 2023, 7:17 AM
bjope requested review of this revision.Mar 27 2023, 7:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 27 2023, 7:17 AM
fhahn accepted this revision.Mar 27 2023, 11:57 PM

LGTM, thanks for tracking down a test case for this!

llvm/test/Transforms/SimpleLoopUnswitch/update-scev-2.ll
8

I think it is probably better to avoid including a stack trace here, as it may go stable. Just staying it will fail verification would be sufficient.

This revision is now accepted and ready to land.Mar 27 2023, 11:57 PM
This revision was landed with ongoing or failed builds.Mar 28 2023, 12:42 AM
This revision was automatically updated to reflect the committed changes.