This is an archive of the discontinued LLVM Phabricator instance.

[Polly][Optimizer] Apply user-directed unrolling.
ClosedPublic

Authored by Meinersbur on Mar 4 2021, 1:47 PM.

Details

Summary

Make Polly look for unrolling metadata (https://llvm.org/docs/TransformMetadata.html#loop-unrolling) that is usually only interpreted by the LoopUnroll pass and apply it to the SCoP's schedule.

While not that useful by itself (there already is an unroll pass), it introduces mechanism to apply arbitrary loop transformation directives in arbitrary order to the schedule. Transformations are applied until no more directives are found. Since ISL's rescheduling would discard the manual transformations and it is assumed that when the user specifies the sequence of transformations, they do not want any other transformations to apply. Applying user-directed transformations can be controlled using the -polly-pragma-based-opts switch and is enabled by default.

This does not influence the SCoP detection heuristic. As a consequence, loop that do not fulfill SCoP requirements or the initial profitability heuristic will be ignored. -polly-process-unprofitable can be used to disable the latter.

Other than manually editing the IR, there is currently no way for the user to add loop transformations in an order other than the order in the default pipeline, or transformations other than the one supported by clang's LoopHint. See the unroll_double.ll test as example that clang currently is unable to emit. My own extension of #pragma clang loop allowing an arbitrary order and additional transformations is available here: https://github.com/meinersbur/llvm-project/tree/pragma-clang-loop. An effort to upstream this functionality as #pragma clang transform (because #pragma clang loop has an implicit transformation order defined by the loop pipeline) is D69088.

Additional transformations from my downstream pragma-clang-loop branch are tiling, interchange, reversal, unroll-and-jam, thread-parallelization and array packing. Unroll was chosen because it uses already-defined metadata and does not require correctness checks.

Diff Detail

Event Timeline

Meinersbur created this revision.Mar 4 2021, 1:47 PM
Meinersbur requested review of this revision.Mar 4 2021, 1:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 4 2021, 1:47 PM
Meinersbur updated this revision to Diff 328300.Mar 4 2021, 1:55 PM
  • Undo unintentional LLVM change
This revision is now accepted and ready to land.Mar 9 2021, 5:45 AM

Thanks for the review. I was waiting a bit to see whether others want to have a look as well. I will commit this soon.

This revision was landed with ongoing or failed builds.Mar 15 2021, 11:07 AM
This revision was automatically updated to reflect the committed changes.

Hi, it seems that unroll_double.ll is failing on our clang builders (https://luci-milo.appspot.com/p/fuchsia/builders/ci/clang-linux-x64/b8852671182559485616):

FAIL: Polly :: ScheduleOptimizer/ManualOptimization/unroll_double.ll (557 of 1169)
******************** TEST 'Polly :: ScheduleOptimizer/ManualOptimization/unroll_double.ll' FAILED ********************
Script:
--
: 'RUN: at line 1';   opt  -polly-process-unprofitable  -polly-remarks-minimal  -polly-use-llvm-names  -polly-import-jscop-dir=/b/s/w/ir/x/w/llvm-project/polly/test/ScheduleOptimizer/ManualOptimization  -polly-codegen-verify  -polly-opt-isl -analyze < /b/s/w/ir/x/w/llvm-project/polly/test/ScheduleOptimizer/ManualOptimization/unroll_double.ll | FileCheck /b/s/w/ir/x/w/llvm-project/polly/test/ScheduleOptimizer/ManualOptimization/unroll_double.ll --match-full-lines
--
Exit Code: 1

Command Output (stderr):
--
/b/s/w/ir/x/w/llvm-project/polly/test/ScheduleOptimizer/ManualOptimization/unroll_double.ll:43:10: error: CHECK: expected string not found in input
; CHECK: - filter: "{ Stmt_body[2] }"
         ^
<stdin>:10:30: note: scanning from here
 - filter: "{ Stmt_body[1] }"
                             ^
<stdin>:11:2: note: possible intended match here
 - filter: "{ Stmt_body[5] }"
 ^

Input file: <stdin>
Check file: /b/s/w/ir/x/w/llvm-project/polly/test/ScheduleOptimizer/ManualOptimization/unroll_double.ll

-dump-input=help explains the following input dump.

Input was:
<<<<<<
            .
            .
            .
            5: child: 
            6:  sequence: 
            7:  - filter: "{ Stmt_body[0] }" 
            8:  - filter: "{ Stmt_body[3] }" 
            9:  - filter: "{ Stmt_body[2] }" 
           10:  - filter: "{ Stmt_body[1] }" 
check:43'0                                  X error: no match found
           11:  - filter: "{ Stmt_body[5] }" 
check:43'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
check:43'1      ?                             possible intended match
           12:  - filter: "{ Stmt_body[7] }" 
check:43'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           13:  - filter: "{ Stmt_body[4] }" 
check:43'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           14:  - filter: "{ Stmt_body[6] }" 
check:43'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           15:  - filter: "{ Stmt_body[10] }" 
check:43'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
           16:  - filter: "{ Stmt_body[8] }" 
check:43'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            .
            .
            .
>>>>>>

Would you mind taking a look? Thanks.

Thank you for notifying me. Should be fixed in rGf51427afb5333e5dd2eb04ea4630037667c64553. Please report back if it still does not work.