summaryrefslogtreecommitdiffstats
path: root/llvm/test/Analysis
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/test/Analysis')
-rw-r--r--llvm/test/Analysis/PhiValues/basic.ll282
-rw-r--r--llvm/test/Analysis/PhiValues/big_phi.ll78
-rw-r--r--llvm/test/Analysis/PhiValues/long_phi_chain.ll142
3 files changed, 502 insertions, 0 deletions
diff --git a/llvm/test/Analysis/PhiValues/basic.ll b/llvm/test/Analysis/PhiValues/basic.ll
new file mode 100644
index 00000000000..ca013828368
--- /dev/null
+++ b/llvm/test/Analysis/PhiValues/basic.ll
@@ -0,0 +1,282 @@
+; RUN: opt < %s -passes='print<phi-values>' -disable-output 2>&1 | FileCheck %s
+
+@X = common global i32 0
+
+; CHECK-LABEL: PHI Values for function: simple
+define void @simple(i32* %ptr) {
+entry:
+ br i1 undef, label %if, label %else
+
+if:
+ br label %end
+
+else:
+ br label %end
+
+end:
+; CHECK: PHI %phi1 has values:
+; CHECK-DAG: i32 0
+; CHECK-DAG: i32 1
+ %phi1 = phi i32 [ 0, %if ], [ 1, %else ]
+; CHECK: PHI %phi2 has values:
+; CHECK-DAG: @X
+; CHECK-DAG: %ptr
+ %phi2 = phi i32* [ @X, %if ], [ %ptr, %else ]
+ ret void
+}
+
+; CHECK-LABEL: PHI Values for function: chain
+define void @chain() {
+entry:
+ br i1 undef, label %if1, label %else1
+
+if1:
+ br label %middle
+
+else1:
+ br label %middle
+
+middle:
+; CHECK: PHI %phi1 has values:
+; CHECK-DAG: i32 0
+; CHECK-DAG: i32 1
+ %phi1 = phi i32 [ 0, %if1 ], [ 1, %else1 ]
+ br i1 undef, label %if2, label %else2
+
+if2:
+ br label %end
+
+else2:
+ br label %end
+
+end:
+; CHECK: PHI %phi2 has values:
+; CHECK-DAG: i32 0
+; CHECK-DAG: i32 1
+; CHECK-DAG: i32 2
+ %phi2 = phi i32 [ %phi1, %if2 ], [ 2, %else2 ]
+ ret void
+}
+
+; CHECK-LABEL: PHI Values for function: no_values
+define void @no_values() {
+entry:
+ ret void
+
+unreachable:
+; CHECK: PHI %phi has values:
+; CHECK-DAG: NONE
+ %phi = phi i32 [ %phi, %unreachable ]
+ br label %unreachable
+}
+
+; CHECK-LABEL: PHI Values for function: simple_loop
+define void @simple_loop() {
+entry:
+ br label %loop
+
+loop:
+; CHECK: PHI %phi has values:
+; CHECK-DAG: i32 0
+ %phi = phi i32 [ 0, %entry ], [ %phi, %loop ]
+ br i1 undef, label %loop, label %end
+
+end:
+ ret void
+}
+
+; CHECK-LABEL: PHI Values for function: complex_loop
+define void @complex_loop() {
+entry:
+ br i1 undef, label %loop, label %end
+
+loop:
+; CHECK: PHI %phi1 has values:
+; CHECK-DAG: i32 0
+; CHECK-DAG: i32 1
+ %phi1 = phi i32 [ 0, %entry ], [ %phi2, %then ]
+ br i1 undef, label %if, label %else
+
+if:
+ br label %then
+
+else:
+ br label %then
+
+then:
+; CHECK: PHI %phi2 has values:
+; CHECK-DAG: i32 0
+; CHECK-DAG: i32 1
+ %phi2 = phi i32 [ %phi1, %if ], [ 1, %else ]
+ br i1 undef, label %loop, label %end
+
+end:
+; CHECK: PHI %phi3 has values:
+; CHECK-DAG: i32 0
+; CHECK-DAG: i32 1
+; CHECK-DAG: i32 2
+ %phi3 = phi i32 [ 2, %entry ], [ %phi2, %then ]
+ ret void
+}
+
+; CHECK-LABEL: PHI Values for function: strange_loop
+define void @strange_loop() {
+entry:
+ br i1 undef, label %ifelse, label %inloop
+
+loop:
+; CHECK: PHI %phi1 has values:
+; CHECK-DAG: i32 0
+; CHECK-DAG: i32 1
+; CHECK-DAG: i32 2
+; CHECK-DAG: i32 3
+ %phi1 = phi i32 [ %phi3, %if ], [ 0, %else ], [ %phi2, %inloop ]
+ br i1 undef, label %inloop, label %end
+
+inloop:
+; CHECK: PHI %phi2 has values:
+; CHECK-DAG: i32 0
+; CHECK-DAG: i32 1
+; CHECK-DAG: i32 2
+; CHECK-DAG: i32 3
+ %phi2 = phi i32 [ %phi1, %loop ], [ 1, %entry ]
+ br i1 undef, label %ifelse, label %loop
+
+ifelse:
+; CHECK: PHI %phi3 has values:
+; CHECK-DAG: i32 2
+; CHECK-DAG: i32 3
+ %phi3 = phi i32 [ 2, %entry ], [ 3, %inloop ]
+ br i1 undef, label %if, label %else
+
+if:
+ br label %loop
+
+else:
+ br label %loop
+
+end:
+ ret void
+}
+
+; CHECK-LABEL: PHI Values for function: mutual_loops
+define void @mutual_loops() {
+entry:
+ br i1 undef, label %loop1, label %loop2
+
+loop1:
+; CHECK: PHI %phi1 has values:
+; CHECK-DAG: 0
+; CHECK-DAG: 1
+; CHECK-DAG: 2
+; CHECK-DAG: 3
+; CHECK-DAG: 4
+ %phi1 = phi i32 [ 0, %entry ], [ %phi2, %loop1.then ], [ %phi3, %loop2.if ]
+ br i1 undef, label %loop1.if, label %loop1.else
+
+loop1.if:
+ br i1 undef, label %loop1.then, label %loop2
+
+loop1.else:
+ br label %loop1.then
+
+loop1.then:
+; CHECK: PHI %phi2 has values:
+; CHECK-DAG: 0
+; CHECK-DAG: 1
+; CHECK-DAG: 2
+; CHECK-DAG: 3
+; CHECK-DAG: 4
+ %phi2 = phi i32 [ 1, %loop1.if ], [ %phi1, %loop1.else ]
+ br i1 undef, label %loop1, label %end
+
+loop2:
+; CHECK: PHI %phi3 has values:
+; CHECK-DAG: 2
+; CHECK-DAG: 3
+; CHECK-DAG: 4
+ %phi3 = phi i32 [ 2, %entry ], [ %phi4, %loop2.then ], [ 3, %loop1.if ]
+ br i1 undef, label %loop2.if, label %loop2.else
+
+loop2.if:
+ br i1 undef, label %loop2.then, label %loop1
+
+loop2.else:
+ br label %loop2.then
+
+loop2.then:
+; CHECK: PHI %phi4 has values:
+; CHECK-DAG: 2
+; CHECK-DAG: 3
+; CHECK-DAG: 4
+ %phi4 = phi i32 [ 4, %loop2.if ], [ %phi3, %loop2.else ]
+ br i1 undef, label %loop2, label %end
+
+end:
+; CHECK: PHI %phi5 has values:
+; CHECK-DAG: 0
+; CHECK-DAG: 1
+; CHECK-DAG: 2
+; CHECK-DAG: 3
+; CHECK-DAG: 4
+ %phi5 = phi i32 [ %phi2, %loop1.then ], [ %phi4, %loop2.then ]
+ ret void
+}
+
+; CHECK-LABEL: PHI Values for function: nested_loops_several_values
+define void @nested_loops_several_values() {
+entry:
+ br label %loop1
+
+loop1:
+; CHECK: PHI %phi1 has values:
+; CHECK-DAG: i32 0
+; CHECK-DAG: %add
+ %phi1 = phi i32 [ 0, %entry ], [ %phi2, %loop2 ]
+ br i1 undef, label %loop2, label %end
+
+loop2:
+; CHECK: PHI %phi2 has values:
+; CHECK-DAG: i32 0
+; CHECK-DAG: %add
+ %phi2 = phi i32 [ %phi1, %loop1 ], [ %phi3, %loop3 ]
+ br i1 undef, label %loop3, label %loop1
+
+loop3:
+; CHECK: PHI %phi3 has values:
+; CHECK-DAG: i32 0
+; CHECK-DAG: %add
+ %phi3 = phi i32 [ %add, %loop3 ], [ %phi2, %loop2 ]
+ %add = add i32 %phi3, 1
+ br i1 undef, label %loop3, label %loop2
+
+end:
+ ret void
+}
+
+; CHECK-LABEL: PHI Values for function: nested_loops_one_value
+define void @nested_loops_one_value() {
+entry:
+ br label %loop1
+
+loop1:
+; CHECK: PHI %phi1 has values:
+; CHECK-DAG: i32 0
+ %phi1 = phi i32 [ 0, %entry ], [ %phi2, %loop2 ]
+ br i1 undef, label %loop2, label %end
+
+loop2:
+; CHECK: PHI %phi2 has values:
+; CHECK-DAG: i32 0
+ %phi2 = phi i32 [ %phi1, %loop1 ], [ %phi3, %loop3 ]
+ br i1 undef, label %loop3, label %loop1
+
+loop3:
+; CHECK: PHI %phi3 has values:
+; CHECK-DAG: i32 0
+ %phi3 = phi i32 [ 0, %loop3 ], [ %phi2, %loop2 ]
+ br i1 undef, label %loop3, label %loop2
+
+end:
+ ret void
+}
diff --git a/llvm/test/Analysis/PhiValues/big_phi.ll b/llvm/test/Analysis/PhiValues/big_phi.ll
new file mode 100644
index 00000000000..6f13098db60
--- /dev/null
+++ b/llvm/test/Analysis/PhiValues/big_phi.ll
@@ -0,0 +1,78 @@
+; RUN: opt < %s -passes='print<phi-values>' -disable-output 2>&1 | FileCheck %s
+
+; This test has a phi with a large number of incoming values that are all the
+; same phi, and that phi depends on this phi. This is to check that phi values
+; analysis doesn't repeatedly add a phis values to itself until it segfaults.
+
+; CHECK-LABEL: PHI Values for function: fn
+define void @fn(i8* %arg) {
+entry:
+ br label %for.body
+
+for.body:
+; CHECK: PHI %phi1 has values:
+; CHECK-DAG: i8* %arg
+; CHECK-DAG: i8* undef
+ %phi1 = phi i8* [ %arg, %entry ], [ %phi2, %end ]
+ switch i32 undef, label %end [
+ i32 1, label %bb1
+ i32 2, label %bb2
+ i32 3, label %bb3
+ i32 4, label %bb4
+ i32 5, label %bb5
+ i32 6, label %bb6
+ i32 7, label %bb7
+ i32 8, label %bb8
+ i32 9, label %bb9
+ i32 10, label %bb10
+ i32 11, label %bb11
+ i32 12, label %bb12
+ i32 13, label %bb13
+ ]
+
+bb1:
+ br label %end
+
+bb2:
+ br label %end
+
+bb3:
+ br label %end
+
+bb4:
+ br label %end
+
+bb5:
+ br label %end
+
+bb6:
+ br label %end
+
+bb7:
+ br label %end
+
+bb8:
+ br label %end
+
+bb9:
+ br label %end
+
+bb10:
+ br label %end
+
+bb11:
+ br label %end
+
+bb12:
+ br label %end
+
+bb13:
+ br label %end
+
+end:
+; CHECK: PHI %phi2 has values:
+; CHECK-DAG: i8* %arg
+; CHECK-DAG: i8* undef
+ %phi2 = phi i8* [ %phi1, %for.body ], [ %phi1, %bb1 ], [ %phi1, %bb2 ], [ %phi1, %bb3 ], [ %phi1, %bb4 ], [ %phi1, %bb5 ], [ %phi1, %bb6 ], [ %phi1, %bb7 ], [ undef, %bb8 ], [ %phi1, %bb9 ], [ %phi1, %bb10 ], [ %phi1, %bb11 ], [ %phi1, %bb12 ], [ %phi1, %bb13 ]
+ br label %for.body
+}
diff --git a/llvm/test/Analysis/PhiValues/long_phi_chain.ll b/llvm/test/Analysis/PhiValues/long_phi_chain.ll
new file mode 100644
index 00000000000..850c4f1d51e
--- /dev/null
+++ b/llvm/test/Analysis/PhiValues/long_phi_chain.ll
@@ -0,0 +1,142 @@
+; RUN: opt < %s -passes='print<phi-values>' -disable-output 2>&1 | FileCheck %s
+
+; This test uses a long chain of phis that take themselves as an operand, which causes
+; phi values analysis to segfault if it's not careful about that kind of thing.
+
+; CHECK-LABEL: PHI Values for function: fn
+define void @fn(i32* %arg) {
+entry:
+ br label %while1.cond
+
+while1.cond:
+; CHECK: PHI %phi1 has values:
+; CHECK: i32* %arg
+ %phi1 = phi i32* [ %arg, %entry ], [ %phi2, %while1.then ]
+ br i1 undef, label %while1.end, label %while1.body
+
+while1.body:
+ br i1 undef, label %while1.then, label %while1.if
+
+while1.if:
+ br label %while1.then
+
+while1.then:
+; CHECK: PHI %phi2 has values:
+; CHECK: i32* %arg
+ %phi2 = phi i32* [ %arg, %while1.if ], [ %phi1, %while1.body ]
+ br label %while1.cond
+
+while1.end:
+ br label %while2.cond1
+
+while2.cond1:
+; CHECK: PHI %phi3 has values:
+; CHECK: i32* %arg
+ %phi3 = phi i32* [ %phi1, %while1.end ], [ %phi5, %while2.then ]
+ br i1 undef, label %while2.end, label %while2.body1
+
+while2.body1:
+ br i1 undef, label %while2.cond2, label %while2.then
+
+while2.cond2:
+; CHECK: PHI %phi4 has values:
+; CHECK: i32* %arg
+ %phi4 = phi i32* [ %phi3, %while2.body1 ], [ %phi4, %while2.if ]
+ br i1 undef, label %while2.then, label %while2.if
+
+while2.if:
+ br label %while2.cond2
+
+while2.then:
+; CHECK: PHI %phi5 has values:
+; CHECK: i32* %arg
+ %phi5 = phi i32* [ %phi3, %while2.body1 ], [ %phi4, %while2.cond2 ]
+ br label %while2.cond1
+
+while2.end:
+ br label %while3.cond1
+
+while3.cond1:
+; CHECK: PHI %phi6 has values:
+; CHECK: i32* %arg
+ %phi6 = phi i32* [ %phi3, %while2.end ], [ %phi7, %while3.cond2 ]
+ br i1 undef, label %while3.end, label %while3.cond2
+
+while3.cond2:
+; CHECK: PHI %phi7 has values:
+; CHECK: i32* %arg
+ %phi7 = phi i32* [ %phi6, %while3.cond1 ], [ %phi7, %while3.body ]
+ br i1 undef, label %while3.cond1, label %while3.body
+
+while3.body:
+ br label %while3.cond2
+
+while3.end:
+ br label %while4.cond1
+
+while4.cond1:
+; CHECK: PHI %phi8 has values:
+; CHECK: i32* %arg
+ %phi8 = phi i32* [ %phi6, %while3.end ], [ %phi10, %while4.then ]
+ br i1 undef, label %while4.end, label %while4.if
+
+while4.if:
+ br i1 undef, label %while4.cond2, label %while4.then
+
+while4.cond2:
+; CHECK: PHI %phi9 has values:
+; CHECK: i32* %arg
+ %phi9 = phi i32* [ %phi8, %while4.if ], [ %phi9, %while4.body ]
+ br i1 undef, label %while4.then, label %while4.body
+
+while4.body:
+ br label %while4.cond2
+
+while4.then:
+; CHECK: PHI %phi10 has values:
+; CHECK: i32* %arg
+ %phi10 = phi i32* [ %phi8, %while4.if ], [ %phi9, %while4.cond2 ]
+ br label %while4.cond1
+
+while4.end:
+ br label %while5.cond
+
+while5.cond:
+; CHECK: PHI %phi11 has values:
+; CHECK: i32* %arg
+ %phi11 = phi i32* [ %phi8, %while4.end ], [ %phi13, %while5.then ]
+ br i1 undef, label %while5.end, label %while5.body1
+
+while5.body1:
+ br i1 undef, label %while5.if, label %while5.then
+
+while5.if:
+; CHECK: PHI %phi12 has values:
+; CHECK: i32* %arg
+ %phi12 = phi i32* [ %phi11, %while5.body1 ], [ %phi12, %while5.body2 ]
+ br i1 undef, label %while5.then, label %while5.body2
+
+while5.body2:
+ br label %while5.if
+
+while5.then:
+; CHECK: PHI %phi13 has values:
+; CHECK: i32* %arg
+ %phi13 = phi i32* [ %phi11, %while5.body1 ], [ %phi12, %while5.if ]
+ br label %while5.cond
+
+while5.end:
+ br label %while6.cond1
+
+while6.cond1:
+; CHECK: PHI %phi14 has values:
+; CHECK: i32* %arg
+ %phi14 = phi i32* [ %phi11, %while5.end ], [ %phi14, %while6.cond1 ]
+ br i1 undef, label %while6.cond2, label %while6.cond1
+
+while6.cond2:
+; CHECK: PHI %phi15 has values:
+; CHECK: i32* %arg
+ %phi15 = phi i32* [ %phi14, %while6.cond1 ], [ %phi15, %while6.cond2 ]
+ br label %while6.cond2
+}
OpenPOWER on IntegriCloud