summaryrefslogtreecommitdiff
path: root/test/Transforms/Reassociate
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-01-02 19:17:04 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-01-02 19:17:04 +0000
commitb915e9e0fc85ba6f398b3fab0db6a81a8913af94 (patch)
tree98b8f811c7aff2547cab8642daf372d6c59502fb /test/Transforms/Reassociate
parent6421cca32f69ac849537a3cff78c352195e99f1b (diff)
Notes
Diffstat (limited to 'test/Transforms/Reassociate')
-rw-r--r--test/Transforms/Reassociate/deadcode.ll37
-rw-r--r--test/Transforms/Reassociate/pr28367.ll28
-rw-r--r--test/Transforms/Reassociate/propagate-flags.ll14
-rw-r--r--test/Transforms/Reassociate/reassociate-deadinst.ll16
4 files changed, 95 insertions, 0 deletions
diff --git a/test/Transforms/Reassociate/deadcode.ll b/test/Transforms/Reassociate/deadcode.ll
new file mode 100644
index 0000000000000..866cf64d2a1f9
--- /dev/null
+++ b/test/Transforms/Reassociate/deadcode.ll
@@ -0,0 +1,37 @@
+; RUN: opt < %s -reassociate -disable-output
+
+; It has been detected that dead loops like the one in this test case can be
+; created by -jump-threading (it was detected by a csmith generated program).
+;
+; According to -verify this is valid input (even if it could be discussed if
+; the dead loop really satisfies SSA form).
+;
+; The problem found was that the -reassociate pass ends up in an infinite loop
+; when analysing the 'deadloop1' basic block. See "Bugzilla - Bug 30818".
+define void @deadloop1() {
+ br label %endlabel
+
+deadloop1:
+ %1 = xor i32 %2, 7
+ %2 = xor i32 %1, 8
+ br label %deadloop1
+
+endlabel:
+ ret void
+}
+
+
+; Another example showing that dead code could result in infinite loops in
+; reassociate pass. See "Bugzilla - Bug 30818".
+define void @deadloop2() {
+ br label %endlabel
+
+deadloop2:
+ %1 = and i32 %2, 7
+ %2 = and i32 %3, 8
+ %3 = and i32 %1, 6
+ br label %deadloop2
+
+endlabel:
+ ret void
+}
diff --git a/test/Transforms/Reassociate/pr28367.ll b/test/Transforms/Reassociate/pr28367.ll
new file mode 100644
index 0000000000000..55a6fcba26c4f
--- /dev/null
+++ b/test/Transforms/Reassociate/pr28367.ll
@@ -0,0 +1,28 @@
+; RUN: opt < %s -reassociate -S
+
+; PR28367
+
+; Check to make sure this test does not assert or segfault. If we get too
+; aggressive with retrying instructions it's possible to invalidate our
+; iterator. See PR28367 for complete details.
+
+define void @fn1(i32 %a, i1 %c, i32* %ptr) {
+entry:
+ br label %for.cond
+
+for.cond:
+ %d.0 = phi i32 [ 1, %entry ], [ 2, %for.body ]
+ br i1 %c, label %for.end, label %for.body
+
+for.body:
+ %sub1 = sub i32 %a, %d.0
+ %dead1 = add i32 %sub1, 1
+ %dead2 = mul i32 %dead1, 3
+ %dead3 = mul i32 %dead2, %sub1
+ %sub2 = sub nsw i32 0, %d.0
+ store i32 %sub2, i32* %ptr, align 4
+ br label %for.cond
+
+for.end:
+ ret void
+}
diff --git a/test/Transforms/Reassociate/propagate-flags.ll b/test/Transforms/Reassociate/propagate-flags.ll
new file mode 100644
index 0000000000000..b8987855f0e1c
--- /dev/null
+++ b/test/Transforms/Reassociate/propagate-flags.ll
@@ -0,0 +1,14 @@
+; RUN: opt < %s -reassociate -S | FileCheck %s
+
+; CHECK-LABEL: func
+; CHECK: fmul fast double
+; CHECK-NEXT: fmul fast double
+; CHECK-NEXT: ret
+
+define double @func(double %a, double %b) {
+entry:
+ %mul1 = fmul fast double %a, %a
+ %mul2 = fmul fast double %b, %b
+ %mul3 = fmul fast double %mul1, %mul2
+ ret double %mul3
+}
diff --git a/test/Transforms/Reassociate/reassociate-deadinst.ll b/test/Transforms/Reassociate/reassociate-deadinst.ll
new file mode 100644
index 0000000000000..df314d571d37a
--- /dev/null
+++ b/test/Transforms/Reassociate/reassociate-deadinst.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -inline -functionattrs -reassociate -S | FileCheck %s
+
+; CHECK-NOT: func1
+; CHECK-LABEL: main
+; CHECK-NEXT: ret void
+
+define internal i16 @func1() noinline #0 {
+ ret i16 0
+}
+
+define void @main(i16 %argc, i16** %argv) #0 {
+ %_tmp0 = call i16 @func1()
+ %_tmp2 = zext i16 %_tmp0 to i32
+ ret void
+}
+attributes #0 = { minsize nounwind optsize }