mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-27 13:30:05 +00:00
b1fd3cd78f
The old PPCCTRLoops pass, like the Hexagon pass version from which it was derived, could only handle some simple loops in canonical form. We cannot directly adapt the new Hexagon hardware loops pass, however, because the Hexagon pass contains a fundamental assumption that non-constant-trip-count loops will contain a guard, and this is not always true (the result being that incorrect negative counts can be generated). With this commit, we replace the pass with a late IR-level pass which makes use of SE to calculate the backedge-taken counts and safely generate the loop-count expressions (including any necessary max() parts). This IR level pass inserts custom intrinsics that are lowered into the desired decrement-and-branch instructions. The most fragile part of this new implementation is that interfering uses of the counter register must be detected on the IR level (and, on PPC, this also includes any indirect branches in addition to function calls). Also, to make all of this work, we need a variant of the mtctr instruction that is marked as having side effects. Without this, machine-code level CSE, DCE, etc. illegally transform the resulting code. Hopefully, this can be improved in the future. This new pass is smaller than the original (and much smaller than the new Hexagon hardware loops pass), and can handle many additional cases correctly. In addition, the preheader-creation code has been copied from LoopSimplify, and after we decide on where it belongs, this code will be refactored so that it can be explicitly shared (making this implementation even smaller). The new test-case files ctrloop-{le,lt,ne}.ll have been adapted from tests for the new Hexagon pass. There are a few classes of loops that this pass does not transform (noted by FIXMEs in the files), but these deficiencies can be addressed within the SE infrastructure (thus helping many other passes as well). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181927 91177308-0d34-0410-b5e6-96231b3b80d8
76 lines
2.2 KiB
LLVM
76 lines
2.2 KiB
LLVM
target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v128:128:128-n32:64"
|
|
target triple = "powerpc64-unknown-freebsd10.0"
|
|
; RUN: llc < %s -march=ppc64 | FileCheck %s
|
|
|
|
@a = common global i32 0, align 4
|
|
|
|
define void @test1(i32 %c) nounwind {
|
|
entry:
|
|
br label %for.body
|
|
|
|
for.body: ; preds = %for.body, %entry
|
|
%i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
|
|
%0 = load volatile i32* @a, align 4
|
|
%add = add nsw i32 %0, %c
|
|
store volatile i32 %add, i32* @a, align 4
|
|
%inc = add nsw i32 %i.01, 1
|
|
%exitcond = icmp eq i32 %inc, 2048
|
|
br i1 %exitcond, label %for.end, label %for.body
|
|
|
|
for.end: ; preds = %for.body
|
|
ret void
|
|
; CHECK: @test1
|
|
; CHECK-NOT: or 3, 3, 3
|
|
; CHECK: mtctr
|
|
; CHECK-NOT: addi {[0-9]+}
|
|
; CHECK-NOT: cmplwi
|
|
; CHECK: bdnz
|
|
}
|
|
|
|
define void @test2(i32 %c, i32 %d) nounwind {
|
|
entry:
|
|
%cmp1 = icmp sgt i32 %d, 0
|
|
br i1 %cmp1, label %for.body, label %for.end
|
|
|
|
for.body: ; preds = %entry, %for.body
|
|
%i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
|
|
%0 = load volatile i32* @a, align 4
|
|
%add = add nsw i32 %0, %c
|
|
store volatile i32 %add, i32* @a, align 4
|
|
%inc = add nsw i32 %i.02, 1
|
|
%exitcond = icmp eq i32 %inc, %d
|
|
br i1 %exitcond, label %for.end, label %for.body
|
|
|
|
for.end: ; preds = %for.body, %entry
|
|
ret void
|
|
; CHECK: @test2
|
|
; CHECK: mtctr
|
|
; CHECK-NOT: addi {[0-9]+}
|
|
; CHECK-NOT: cmplwi
|
|
; CHECK: bdnz
|
|
}
|
|
|
|
define void @test3(i32 %c, i32 %d) nounwind {
|
|
entry:
|
|
%cmp1 = icmp sgt i32 %d, 0
|
|
br i1 %cmp1, label %for.body, label %for.end
|
|
|
|
for.body: ; preds = %entry, %for.body
|
|
%i.02 = phi i32 [ %inc, %for.body ], [ 0, %entry ]
|
|
%mul = mul nsw i32 %i.02, %c
|
|
%0 = load volatile i32* @a, align 4
|
|
%add = add nsw i32 %0, %mul
|
|
store volatile i32 %add, i32* @a, align 4
|
|
%inc = add nsw i32 %i.02, 1
|
|
%exitcond = icmp eq i32 %inc, %d
|
|
br i1 %exitcond, label %for.end, label %for.body
|
|
|
|
for.end: ; preds = %for.body, %entry
|
|
ret void
|
|
; CHECK: @test3
|
|
; CHECK: mtctr
|
|
; CHECK-NOT: addi {[0-9]+}
|
|
; CHECK-NOT: cmplwi
|
|
; CHECK: bdnz
|
|
}
|