This is an archive of the discontinued LLVM Phabricator instance.

[FLANG] Support all arrays for LoopVersioning
ClosedPublic

Authored by Leporacanthicus on May 22 2023, 12:38 PM.

Details

Summary

This patch makes more than 2D arrays work, with a fix for the way that
loop index is calculated. Removing the restriction of number of
dimensions.

This also changes the way that the actual index is calculated, such that
the stride is used rather than the extent of the previous dimension. Some
tests failed without fixing this - this was likely a latent bug in the
2D version too, but found in a test using 3D arrays, so wouldn't
have been found with 2D only. This introduces a division on the index
calculation - however it should be a nice and constant value allowing
a shift to be used to actually divide - or otherwise removed by using
other methods to calculate the result. In analysing code generated with
optimisation at -O3, there are no divides produced.

Some minor refactoring to avoid repeatedly asking for the "rank" of the
array being worked on.

This improves some of the SPEC-2017 ROMS code, in the same way as the
limited 2D array improvements - less overhead spent calculating array
indices in the inner-most loop and better use of vector-instructions.

Diff Detail

Event Timeline

Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 22 2023, 12:38 PM
Leporacanthicus requested review of this revision.May 22 2023, 12:38 PM

Updates in this revision:

  • Don't start with a zero and add/multiply that into the index calculation.
  • Don't ask for the Nth dims in N-dimensional array (unless N = 1)
  • Fix up tests to match the updated code-gen.
  • Remove hard-coded value in tests that shouldn't be checked.

Update to fix pre-commit build - Small Vector needs size.

Fix yet another small-vector issue.

Update index calculation yet again. Some tests failed - use stride for index calculation
and divide by itemsize at the end.

Remove upper limit of rank altogether.

Leporacanthicus retitled this revision from [FLANG] Support 3D arrays for LoopVersioning to [FLANG] Support all arrays for LoopVersioning.May 30 2023, 6:02 AM
Leporacanthicus edited the summary of this revision. (Show Details)
flang/lib/Optimizer/Transforms/LoopVersioning.cpp
251–277

A comment (with a fortran-level example for 3D) on how the address is computed will be helpful.

It can be something simple like

a(i,j) = a(i*NJ + j)
This revision is now accepted and ready to land.May 30 2023, 7:39 AM
Leporacanthicus edited the summary of this revision. (Show Details)

Update comment

This revision was automatically updated to reflect the committed changes.