summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms
diff options
context:
space:
mode:
authorSaleem Abdulrasool <compnerd@compnerd.org>2014-10-28 18:27:37 +0000
committerSaleem Abdulrasool <compnerd@compnerd.org>2014-10-28 18:27:37 +0000
commitd178ada55ea4cc5d71443ec27495092fbb72b230 (patch)
treeec71ccd72ffdb4eac61697c6c45fd9057d6e5e95 /llvm/test/Transforms
parent4f2fe82b6de2069ae48bd1e8df0e29826ad63351 (diff)
downloadbcm5719-llvm-d178ada55ea4cc5d71443ec27495092fbb72b230.tar.gz
bcm5719-llvm-d178ada55ea4cc5d71443ec27495092fbb72b230.zip
Transforms: reapply SVN r219899
This restores the commit from SVN r219899 with an additional change to ensure that the CodeGen is correct for the case that was identified as being incorrect (originally PR7272). In the case that during inlining we need to synthesize a value on the stack (i.e. for passing a value byval), then any function involving that alloca must be stripped of its tailness as the restriction that it does not access the parent's stack no longer holds. Unfortunately, a single alloca can cause a rippling effect through out the inlining as the value may be aliased or may be mutated through an escaped external call. As such, we simply track if an alloca has been introduced in the frame during inlining, and strip any tail calls. llvm-svn: 220811
Diffstat (limited to 'llvm/test/Transforms')
-rw-r--r--llvm/test/Transforms/Inline/byval-tail-call.ll2
-rw-r--r--llvm/test/Transforms/Inline/inline-tail.ll36
-rw-r--r--llvm/test/Transforms/Inline/inlined-allocas.ll58
-rw-r--r--llvm/test/Transforms/TailCallElim/basic.ll2
-rw-r--r--llvm/test/Transforms/TailCallElim/byval.ll34
5 files changed, 94 insertions, 38 deletions
diff --git a/llvm/test/Transforms/Inline/byval-tail-call.ll b/llvm/test/Transforms/Inline/byval-tail-call.ll
index 154f3974b58..95c31d2b826 100644
--- a/llvm/test/Transforms/Inline/byval-tail-call.ll
+++ b/llvm/test/Transforms/Inline/byval-tail-call.ll
@@ -34,7 +34,7 @@ define void @frob(i32* %x) {
; CHECK: %[[VAL:.*]] = load i32* %x
; CHECK: store i32 %[[VAL]], i32* %[[POS]]
; CHECK: {{^ *}}call void @ext(i32* %[[POS]]
-; CHECK: tail call void @ext(i32* null)
+; CHECK: {{^ *}}call void @ext(i32* null)
; CHECK: ret void
tail call void @qux(i32* byval %x)
ret void
diff --git a/llvm/test/Transforms/Inline/inline-tail.ll b/llvm/test/Transforms/Inline/inline-tail.ll
index b40328e0a27..565491adf5b 100644
--- a/llvm/test/Transforms/Inline/inline-tail.ll
+++ b/llvm/test/Transforms/Inline/inline-tail.ll
@@ -49,42 +49,6 @@ define void @test_musttail_basic_a(i32* %p) {
ret void
}
-; Don't insert lifetime end markers here, the lifetime is trivially over due
-; the return.
-; CHECK: define void @test_byval_a(
-; CHECK: musttail call void @test_byval_c(
-; CHECK-NEXT: ret void
-
-declare void @test_byval_c(i32* byval %p)
-define internal void @test_byval_b(i32* byval %p) {
- musttail call void @test_byval_c(i32* byval %p)
- ret void
-}
-define void @test_byval_a(i32* byval %p) {
- musttail call void @test_byval_b(i32* byval %p)
- ret void
-}
-
-; Don't insert a stack restore, we're about to return.
-; CHECK: define void @test_dynalloca_a(
-; CHECK: call i8* @llvm.stacksave(
-; CHECK: alloca i8, i32 %n
-; CHECK: musttail call void @test_dynalloca_c(
-; CHECK-NEXT: ret void
-
-declare void @escape(i8* %buf)
-declare void @test_dynalloca_c(i32* byval %p, i32 %n)
-define internal void @test_dynalloca_b(i32* byval %p, i32 %n) alwaysinline {
- %buf = alloca i8, i32 %n ; dynamic alloca
- call void @escape(i8* %buf) ; escape it
- musttail call void @test_dynalloca_c(i32* byval %p, i32 %n)
- ret void
-}
-define void @test_dynalloca_a(i32* byval %p, i32 %n) {
- musttail call void @test_dynalloca_b(i32* byval %p, i32 %n)
- ret void
-}
-
; We can't merge the returns.
; CHECK: define void @test_multiret_a(
; CHECK: musttail call void @test_multiret_c(
diff --git a/llvm/test/Transforms/Inline/inlined-allocas.ll b/llvm/test/Transforms/Inline/inlined-allocas.ll
new file mode 100644
index 00000000000..e2942816f13
--- /dev/null
+++ b/llvm/test/Transforms/Inline/inlined-allocas.ll
@@ -0,0 +1,58 @@
+; RUN: opt -dse -inline -S %s | FileCheck %s
+
+declare void @external(i32* byval)
+declare i32 @identity(i32* byval)
+
+; An alloca in the inlinee should not force the tail to be stripped
+
+define void @inlinee_with_alloca() {
+ %local = alloca i32
+ store i32 42, i32* %local, align 4
+ tail call void @external(i32* byval %local)
+ ret void
+}
+
+define void @inliner_without_alloca() {
+ tail call void @inlinee_with_alloca()
+ ret void
+}
+
+; CHECK-LABEL: inliner_without_alloca
+; CHECK-NEXT: %local.i = alloca i32
+; CHECK: store i32 42, i32* %local.i
+; CHECK: tail call void @external
+; CHECK: ret
+
+; An alloca in the inliner should not force the tail to be stripped
+
+define i32 @inliner_with_alloca() {
+ %local = alloca i32
+ store i32 42, i32* %local, align 4
+ %1 = tail call i32 @identity(i32* byval %local)
+ ret i32 %1
+}
+
+; CHECK-LABEL: inliner_with_alloca
+; CHECK: %local = alloca i32
+; CHECK: store i32 42, i32* %local
+; CHECK: %1 = tail call i32 @identity
+; CHECK: ret i32 %1
+
+; Force the synthesis of the value through the byval parameter.
+; The alloca should force the tail to be stripped
+
+define void @inlinee_with_passthru(i32* byval %value) {
+ tail call void @external(i32* byval %value)
+ ret void
+}
+
+define void @strip_tail(i32* %value) {
+ tail call void @inlinee_with_passthru(i32* %value)
+ ret void
+}
+
+; CHECK-LABEL: strip_tail
+; CHECK: %value1 = alloca i32
+; CHECK: {{^ *}}call void @external
+; CHECK: ret void
+
diff --git a/llvm/test/Transforms/TailCallElim/basic.ll b/llvm/test/Transforms/TailCallElim/basic.ll
index 8e9814b52bb..3b98f8c7967 100644
--- a/llvm/test/Transforms/TailCallElim/basic.ll
+++ b/llvm/test/Transforms/TailCallElim/basic.ll
@@ -147,7 +147,7 @@ cond_false:
; Don't tail call if a byval arg is captured.
define void @test9(i32* byval %a) {
; CHECK-LABEL: define void @test9(
-; CHECK: {{^ *}}call void @use(
+; CHECK: tail call void @use(
call void @use(i32* %a)
ret void
}
diff --git a/llvm/test/Transforms/TailCallElim/byval.ll b/llvm/test/Transforms/TailCallElim/byval.ll
new file mode 100644
index 00000000000..1150f7684e9
--- /dev/null
+++ b/llvm/test/Transforms/TailCallElim/byval.ll
@@ -0,0 +1,34 @@
+; RUN: opt -mtriple i386 -Os -S %s -o - | FileCheck %s
+; RUN: opt -mtriple x86_64 -Os -S %s -o - | FileCheck %s
+; RUN: opt -mtriple armv7 -Os -S %s -o - | FileCheck %s
+
+%struct.D16 = type { [16 x double] }
+
+declare void @_Z2OpP3D16PKS_S2_(%struct.D16*, %struct.D16*, %struct.D16*)
+
+define void @_Z7TestRefRK3D16S1_(%struct.D16* noalias sret %agg.result, %struct.D16* %RHS, %struct.D16* %LHS) {
+ %1 = alloca %struct.D16*, align 8
+ %2 = alloca %struct.D16*, align 8
+ store %struct.D16* %RHS, %struct.D16** %1, align 8
+ store %struct.D16* %LHS, %struct.D16** %2, align 8
+ %3 = load %struct.D16** %1, align 8
+ %4 = load %struct.D16** %2, align 8
+ call void @_Z2OpP3D16PKS_S2_(%struct.D16* %agg.result, %struct.D16* %3, %struct.D16* %4)
+ ret void
+}
+
+; CHECK: define void @_Z7TestRefRK3D16S1_({{.*}}) {
+; CHECK: tail call void @_Z2OpP3D16PKS_S2_(%struct.D16* %agg.result, %struct.D16* %RHS, %struct.D16* %LHS)
+; CHECK: ret void
+; CHECK: }
+
+define void @_Z7TestVal3D16S_(%struct.D16* noalias sret %agg.result, %struct.D16* byval align 8 %RHS, %struct.D16* byval align 8 %LHS) {
+ call void @_Z2OpP3D16PKS_S2_(%struct.D16* %agg.result, %struct.D16* %RHS, %struct.D16* %LHS)
+ ret void
+}
+
+; CHECK: define void @_Z7TestVal3D16S_({{.*}}) {
+; CHECK: tail call void @_Z2OpP3D16PKS_S2_(%struct.D16* %agg.result, %struct.D16* %RHS, %struct.D16* %LHS)
+; CHECK: ret void
+; CHECK: }
+
OpenPOWER on IntegriCloud