2017-08-02 06:20:41 +08:00
|
|
|
; RUN: llc -verify-machineinstrs < %s -relocation-model=pic | FileCheck %s
|
2012-06-08 23:38:21 +08:00
|
|
|
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"
|
|
|
|
|
|
|
|
@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 ]
|
2015-02-28 05:17:42 +08:00
|
|
|
%0 = load volatile i32, i32* @a, align 4
|
2012-06-08 23:38:21 +08:00
|
|
|
%add = add nsw i32 %0, %c
|
2013-05-01 01:52:57 +08:00
|
|
|
store volatile i32 %add, i32* @a, align 4
|
2012-06-08 23:38:21 +08:00
|
|
|
%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
|
2012-06-10 06:10:19 +08:00
|
|
|
; CHECK-NOT: or 3, 3, 3
|
2012-06-08 23:38:21 +08:00
|
|
|
; CHECK: mtctr
|
Implement PPC counter loops as a late IR-level pass
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).
llvm-svn: 181927
2013-05-16 05:37:41 +08:00
|
|
|
; CHECK-NOT: addi {[0-9]+}
|
2012-06-08 23:38:21 +08:00
|
|
|
; 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 ]
|
2015-02-28 05:17:42 +08:00
|
|
|
%0 = load volatile i32, i32* @a, align 4
|
2012-06-08 23:38:21 +08:00
|
|
|
%add = add nsw i32 %0, %c
|
2013-05-01 01:52:57 +08:00
|
|
|
store volatile i32 %add, i32* @a, align 4
|
2012-06-08 23:38:21 +08:00
|
|
|
%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
|
Implement PPC counter loops as a late IR-level pass
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).
llvm-svn: 181927
2013-05-16 05:37:41 +08:00
|
|
|
; CHECK-NOT: addi {[0-9]+}
|
2012-06-08 23:38:21 +08:00
|
|
|
; 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
|
2015-02-28 05:17:42 +08:00
|
|
|
%0 = load volatile i32, i32* @a, align 4
|
2012-06-08 23:38:21 +08:00
|
|
|
%add = add nsw i32 %0, %mul
|
2013-05-01 01:52:57 +08:00
|
|
|
store volatile i32 %add, i32* @a, align 4
|
2012-06-08 23:38:21 +08:00
|
|
|
%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
|
Implement PPC counter loops as a late IR-level pass
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).
llvm-svn: 181927
2013-05-16 05:37:41 +08:00
|
|
|
; CHECK-NOT: addi {[0-9]+}
|
2012-06-08 23:38:21 +08:00
|
|
|
; CHECK-NOT: cmplwi
|
|
|
|
; CHECK: bdnz
|
|
|
|
}
|
2014-12-28 03:45:38 +08:00
|
|
|
|
|
|
|
@tls_var = external thread_local global i8
|
|
|
|
|
2016-04-07 23:30:55 +08:00
|
|
|
define i32 @test4(i32 %inp) {
|
2014-12-28 03:45:38 +08:00
|
|
|
entry:
|
|
|
|
br label %for.body
|
|
|
|
|
|
|
|
for.body: ; preds = %for.body, %entry
|
2016-04-07 23:30:55 +08:00
|
|
|
%phi = phi i32 [ %dec, %for.body ], [ %inp, %entry ]
|
2014-12-28 03:45:38 +08:00
|
|
|
%load = ptrtoint i8* @tls_var to i32
|
2016-04-07 23:30:55 +08:00
|
|
|
%val = add i32 %load, %phi
|
2014-12-28 03:45:38 +08:00
|
|
|
%dec = add i32 %phi, -1
|
|
|
|
%cmp = icmp sgt i32 %phi, 1
|
|
|
|
br i1 %cmp, label %for.body, label %return
|
|
|
|
|
|
|
|
return: ; preds = %for.body
|
2016-04-07 23:30:55 +08:00
|
|
|
ret i32 %val
|
2014-12-28 03:45:38 +08:00
|
|
|
; CHECK-LABEL: @test4
|
2016-04-07 23:30:55 +08:00
|
|
|
; CHECK: mtctr
|
|
|
|
; CHECK: bdnz
|
|
|
|
; CHECK: __tls_get_addr
|
2014-12-28 03:45:38 +08:00
|
|
|
}
|