[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 -march=hexagon -rdf-opt=0 -disable-hexagon-misched -hexagon-initial-cfg-cleanup=0 -lsr-setupcost-depth-limit=1 < %s -pipeliner-experimental-cg=true | FileCheck %s
|
2018-03-21 03:35:09 +08:00
|
|
|
|
|
|
|
; Test that we generate the correct code when a loop carried value
|
|
|
|
; is scheduled one stage earlier than it's use. The code in
|
|
|
|
; isLoopCarried was returning false in this case, and the generated
|
|
|
|
; code was missing an copy.
|
|
|
|
|
|
|
|
; CHECK: loop0(.LBB0_[[LOOP:.]],
|
|
|
|
; CHECK: .LBB0_[[LOOP]]:
|
|
|
|
; CHECK: += mpy([[REG0:(r[0-9]+)]],r{{[0-9]+}})
|
|
|
|
; CHECK: [[REG0]] = r{{[0-9]+}}
|
|
|
|
; CHECK-NOT: [[REG0]] = memw
|
|
|
|
; CHECK: endloop0
|
|
|
|
|
|
|
|
@g0 = external global [256 x i32], align 8
|
|
|
|
|
|
|
|
define void @f0() #0 {
|
|
|
|
b0:
|
|
|
|
br label %b1
|
|
|
|
|
|
|
|
b1: ; preds = %b1, %b0
|
|
|
|
br i1 undef, label %b2, label %b1
|
|
|
|
|
|
|
|
b2: ; preds = %b1
|
|
|
|
br label %b3
|
|
|
|
|
|
|
|
b3: ; preds = %b3, %b2
|
|
|
|
%v0 = phi i32* [ getelementptr inbounds ([256 x i32], [256 x i32]* @g0, i32 0, i32 0), %b2 ], [ %v1, %b3 ]
|
|
|
|
%v1 = getelementptr i32, i32* %v0, i32 6
|
|
|
|
br i1 undef, label %b4, label %b3
|
|
|
|
|
|
|
|
b4: ; preds = %b3
|
|
|
|
br i1 undef, label %b6, label %b5
|
|
|
|
|
|
|
|
b5: ; preds = %b5, %b4
|
|
|
|
%v2 = phi i64 [ %v19, %b5 ], [ undef, %b4 ]
|
|
|
|
%v3 = phi i32* [ %v8, %b5 ], [ %v1, %b4 ]
|
|
|
|
%v4 = phi i32 [ %v9, %b5 ], [ undef, %b4 ]
|
|
|
|
%v5 = phi i32 [ %v11, %b5 ], [ undef, %b4 ]
|
|
|
|
%v6 = phi i32 [ %v5, %b5 ], [ undef, %b4 ]
|
|
|
|
%v7 = phi i32 [ %v10, %b5 ], [ 0, %b4 ]
|
|
|
|
%v8 = getelementptr i32, i32* %v3, i32 1
|
|
|
|
%v9 = add nsw i32 %v4, 1
|
|
|
|
%v10 = load i32, i32* %v8, align 4
|
|
|
|
%v11 = load i32, i32* null, align 4
|
|
|
|
%v12 = sext i32 %v6 to i64
|
|
|
|
%v13 = sext i32 %v10 to i64
|
|
|
|
%v14 = sext i32 %v7 to i64
|
|
|
|
%v15 = mul nsw i64 %v14, %v12
|
|
|
|
%v16 = add i64 %v12, %v2
|
|
|
|
%v17 = add i64 %v16, %v13
|
|
|
|
%v18 = add i64 %v17, 0
|
|
|
|
%v19 = add i64 %v18, %v15
|
|
|
|
%v20 = icmp eq i32 %v9, 128
|
|
|
|
br i1 %v20, label %b6, label %b5
|
|
|
|
|
|
|
|
b6: ; preds = %b5, %b4
|
|
|
|
%v21 = phi i64 [ undef, %b4 ], [ %v19, %b5 ]
|
|
|
|
unreachable
|
|
|
|
}
|
|
|
|
|
|
|
|
attributes #0 = { nounwind "target-cpu"="hexagonv62" }
|