summaryrefslogtreecommitdiffstats
path: root/llvm/test
diff options
context:
space:
mode:
authorEvgeny Astigeevich <evgeny.astigeevich@arm.com>2016-04-21 08:54:08 +0000
committerEvgeny Astigeevich <evgeny.astigeevich@arm.com>2016-04-21 08:54:08 +0000
commitfd89fe0dd3639b76aa3a38240e9175f0d07a2d3d (patch)
treefda1f03e9bbb4a0933643f86de1d004e65267ac4 /llvm/test
parent21690db05aedd0f8126f03dadb4d604968568b99 (diff)
downloadbcm5719-llvm-fd89fe0dd3639b76aa3a38240e9175f0d07a2d3d.tar.gz
bcm5719-llvm-fd89fe0dd3639b76aa3a38240e9175f0d07a2d3d.zip
[AArch64][CodeGen] Fix of PR27158: incorrect peephole optimization in AArch64InstrInfo::optimizeCompareInstr
AArch64InstrInfo::optimizeCompareInstr has bug PR27158 which causes generation of incorrect code. A compare instruction is substituted with another instruction which does not produce the same flags as the original compare instruction. This patch contains: 1. Fix of the bug. 2. A regression test in MIR. 3. A new test to check that SUBS is replaced by SUB. Differential Revision: http://reviews.llvm.org/D18838 llvm-svn: 266969
Diffstat (limited to 'llvm/test')
-rw-r--r--llvm/test/CodeGen/AArch64/arm64-regress-opt-cmp.mir41
-rw-r--r--llvm/test/CodeGen/AArch64/subs-to-sub-opt.ll23
2 files changed, 64 insertions, 0 deletions
diff --git a/llvm/test/CodeGen/AArch64/arm64-regress-opt-cmp.mir b/llvm/test/CodeGen/AArch64/arm64-regress-opt-cmp.mir
new file mode 100644
index 00000000000..525c8e140ca
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/arm64-regress-opt-cmp.mir
@@ -0,0 +1,41 @@
+# RUN: llc -mtriple=aarch64-linux-gnu -run-pass peephole-opts %s 2>&1 | FileCheck %s
+# CHECK: %1 = ANDWri {{.*}}
+# CHECK-NEXT: %wzr = SUBSWri {{.*}}
+--- |
+ define i32 @test01() nounwind {
+ entry:
+ %0 = select i1 true, i32 1, i32 0
+ %1 = and i32 %0, 65535
+ %2 = icmp ugt i32 %1, 0
+ br i1 %2, label %if.then, label %if.end
+
+ if.then: ; preds = %entry
+ ret i32 1
+
+ if.end: ; preds = %entry
+ ret i32 0
+ }
+...
+---
+name: test01
+registers:
+ - { id: 0, class: gpr32 }
+ - { id: 1, class: gpr32common }
+body: |
+ bb.0.entry:
+ successors: %bb.2.if.end, %bb.1.if.then
+
+ %0 = MOVi32imm 1
+ %1 = ANDWri killed %1, 15
+ %wzr = SUBSWri killed %1, 0, 0, implicit-def %nzcv
+ Bcc 9, %bb.2.if.end, implicit %nzcv
+
+ bb.1.if.then:
+ %w0 = MOVi32imm 1
+ RET_ReallyLR implicit %w0
+
+ bb.2.if.end:
+ %w0 = MOVi32imm 0
+ RET_ReallyLR implicit %w0
+
+...
diff --git a/llvm/test/CodeGen/AArch64/subs-to-sub-opt.ll b/llvm/test/CodeGen/AArch64/subs-to-sub-opt.ll
new file mode 100644
index 00000000000..f33e24e777f
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/subs-to-sub-opt.ll
@@ -0,0 +1,23 @@
+; RUN: llc -mtriple=aarch64-linux-gnu -O3 -o - %s | FileCheck %s
+
+@a = external global i8, align 1
+@b = external global i8, align 1
+
+; Test that SUBS is replaced by SUB if condition flags are not used.
+define i32 @test01() nounwind {
+; CHECK: ldrb {{.*}}
+; CHECK-NEXT: ldrb {{.*}}
+; CHECK-NEXT: sub {{.*}}
+; CHECK-NEXT: cmn {{.*}}
+entry:
+ %0 = load i8, i8* @a, align 1
+ %conv = zext i8 %0 to i32
+ %1 = load i8, i8* @b, align 1
+ %conv1 = zext i8 %1 to i32
+ %s = sub nsw i32 %conv1, %conv
+ %cmp0 = icmp eq i32 %s, -1
+ %cmp1 = sext i1 %cmp0 to i8
+ store i8 %cmp1, i8* @a
+ ret i32 0
+}
+
OpenPOWER on IntegriCloud