[ModuloSchedule] Peel out prologs and epilogs, generate actual code
Summary:
This extends the PeelingModuloScheduleExpander to generate prolog and epilog code,
and correctly stitch uses through the prolog, kernel, epilog DAG.
The key concept in this patch is to ensure that all transforms are *local*; only a
function of a block and its immediate predecessor and successor. By defining the problem in this way
we can inductively rewrite the entire DAG using only local knowledge that is easy to
reason about.
For example, we assume that all prologs and epilogs are near-perfect clones of the
steady-state kernel. This means that if a block has an instruction that is predicated out,
we can redirect all users of that instruction to that equivalent instruction in our
immediate predecessor. As all blocks are clones, every instruction must have an equivalent in
every other block.
Similarly we can make the assumption by construction that if a value defined in a block is used
outside that block, the only possible user is its immediate successors. We maintain this
even for values that are used outside the loop by creating a limited form of LCSSA.
This code isn't small, but it isn't complex.
Enabled a bunch of testing from Hexagon. There are a couple of tests not enabled yet;
I'm about 80% sure there isn't buggy codegen but the tests are checking for patterns
that we don't produce. Those still need a bit more investigation. In the meantime we
(Google) are happy with the code produced by this on our downstream SMS implementation,
and believe it generates correct code.
Subscribers: mgorny, hiraditya, jsji, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D68205
llvm-svn: 373462
2019-10-02 20:46:44 +08:00
|
|
|
# RUN: llc -mtriple=hexagon -run-pass pipeliner -debug-only=pipeliner %s -o /dev/null 2>&1 -pipeliner-experimental-cg=true | FileCheck %s
|
2019-04-12 05:57:51 +08:00
|
|
|
# REQUIRES: asserts
|
|
|
|
|
|
|
|
# Test that the loop carried dependence check correctly identifies a recurrence.
|
|
|
|
|
|
|
|
# CHECK: Rec NodeSet
|
|
|
|
# CHECK: Rec NodeSet
|
|
|
|
# CHECK: Rec NodeSet
|
|
|
|
# CHECK: Rec NodeSet
|
|
|
|
# CHECK-NEXT: SU(4)
|
|
|
|
# CHECK-NEXT: SU(6)
|
|
|
|
|
|
|
|
--- |
|
|
|
|
|
|
|
|
%struct.A = type { i16, i16 }
|
|
|
|
|
|
|
|
define i32 @test(%struct.A* noalias nocapture %s, i16* noalias nocapture readonly %r, i32 %n) {
|
|
|
|
entry:
|
|
|
|
%cmp19 = icmp eq i32 %n, 2
|
|
|
|
br i1 %cmp19, label %for.end, label %for.body.preheader
|
|
|
|
|
|
|
|
for.body.preheader:
|
|
|
|
%0 = add i32 %n, -2
|
|
|
|
%cgep = getelementptr %struct.A, %struct.A* %s, i32 2, i32 1
|
|
|
|
%scevgep1 = bitcast i16* %cgep to %struct.A*
|
|
|
|
%cgep9 = getelementptr i16, i16* %r, i32 2
|
|
|
|
br label %for.body
|
|
|
|
|
|
|
|
for.body:
|
|
|
|
%lsr.iv7 = phi i16* [ %cgep9, %for.body.preheader ], [ %cgep12, %for.body ]
|
|
|
|
%lsr.iv2 = phi %struct.A* [ %scevgep1, %for.body.preheader ], [ %cgep11, %for.body ]
|
|
|
|
%lsr.iv = phi i32 [ %0, %for.body.preheader ], [ %lsr.iv.next, %for.body ]
|
|
|
|
%sum.020 = phi i32 [ %add7, %for.body ], [ 0, %for.body.preheader ]
|
|
|
|
%lsr.iv24 = bitcast %struct.A* %lsr.iv2 to i16*
|
|
|
|
%1 = load i16, i16* %lsr.iv7, align 2
|
|
|
|
%conv = sext i16 %1 to i32
|
|
|
|
%cgep10 = getelementptr i16, i16* %lsr.iv24, i32 -4
|
|
|
|
%2 = load i16, i16* %cgep10, align 2
|
|
|
|
%conv2 = sext i16 %2 to i32
|
|
|
|
%add = add i16 %1, 10
|
|
|
|
store i16 %add, i16* %lsr.iv24, align 2
|
|
|
|
%add6 = add i32 %sum.020, %conv
|
|
|
|
%add7 = add i32 %add6, %conv2
|
|
|
|
%lsr.iv.next = add i32 %lsr.iv, -1
|
|
|
|
%cmp = icmp eq i32 %lsr.iv.next, 0
|
|
|
|
%cgep11 = getelementptr %struct.A, %struct.A* %lsr.iv2, i32 1
|
|
|
|
%cgep12 = getelementptr i16, i16* %lsr.iv7, i32 1
|
|
|
|
br i1 %cmp, label %for.end, label %for.body
|
|
|
|
|
|
|
|
for.end:
|
|
|
|
%sum.0.lcssa = phi i32 [ 0, %entry ], [ %add7, %for.body ]
|
|
|
|
ret i32 %sum.0.lcssa
|
|
|
|
}
|
|
|
|
|
|
|
|
...
|
|
|
|
---
|
|
|
|
name: test
|
|
|
|
tracksRegLiveness: true
|
|
|
|
|
|
|
|
body: |
|
|
|
|
bb.0:
|
|
|
|
successors: %bb.3, %bb.1
|
|
|
|
liveins: $r0, $r1, $r2
|
|
|
|
|
|
|
|
%14:intregs = COPY $r2
|
|
|
|
%13:intregs = COPY $r1
|
|
|
|
%12:intregs = COPY $r0
|
|
|
|
%16:predregs = C2_cmpeqi %14, 2
|
|
|
|
%15:intregs = A2_tfrsi 0
|
|
|
|
J2_jumpt killed %16, %bb.3, implicit-def dead $pc
|
|
|
|
J2_jump %bb.1, implicit-def dead $pc
|
|
|
|
|
|
|
|
bb.1:
|
|
|
|
successors: %bb.2
|
|
|
|
|
|
|
|
%0:intregs = A2_addi %14, -2
|
|
|
|
%1:intregs = A2_addi %12, 10
|
|
|
|
%2:intregs = A2_addi %13, 4
|
|
|
|
%17:intregs = A2_tfrsi 0
|
|
|
|
%23:intregs = COPY %0
|
|
|
|
J2_loop0r %bb.2, %23, implicit-def $lc0, implicit-def $sa0, implicit-def $usr
|
|
|
|
|
|
|
|
bb.2 (address-taken):
|
|
|
|
successors: %bb.3, %bb.2
|
|
|
|
|
|
|
|
%3:intregs = PHI %2, %bb.1, %10, %bb.2
|
|
|
|
%4:intregs = PHI %1, %bb.1, %9, %bb.2
|
|
|
|
%6:intregs = PHI %17, %bb.1, %7, %bb.2
|
|
|
|
%18:intregs, %10:intregs = L2_loadrh_pi %3, 2 :: (load 2 from %ir.lsr.iv7)
|
|
|
|
%19:intregs = L2_loadrh_io %4, -8 :: (load 2 from %ir.cgep10)
|
|
|
|
%20:intregs = A2_addi %18, 10
|
|
|
|
S2_storerh_io %4, 0, killed %20 :: (store 2 into %ir.lsr.iv24)
|
|
|
|
%7:intregs = M2_acci %19, %6, %18
|
|
|
|
%9:intregs = A2_addi %4, 4
|
|
|
|
ENDLOOP0 %bb.2, implicit-def $pc, implicit-def $lc0, implicit $sa0, implicit $lc0
|
|
|
|
J2_jump %bb.3, implicit-def dead $pc
|
|
|
|
|
|
|
|
bb.3:
|
|
|
|
%11:intregs = PHI %15, %bb.0, %7, %bb.2
|
|
|
|
$r0 = COPY %11
|
|
|
|
PS_jmpret $r31, implicit-def dead $pc, implicit $r0
|
|
|
|
|
|
|
|
...
|