summaryrefslogtreecommitdiffstats
path: root/llvm/test/CodeGen/AArch64
diff options
context:
space:
mode:
authorAyonam Ray <ayonam@rrlogic.co.in>2019-01-29 12:01:32 +0000
committerAyonam Ray <ayonam@rrlogic.co.in>2019-01-29 12:01:32 +0000
commit4272af9b3e7f55fc15e2ff704f46d76d69134d40 (patch)
tree46d03efb17d6dd0252b9ac38eb9c5a5a4c1e9fe2 /llvm/test/CodeGen/AArch64
parent2601aa54069256f89bffecf34f513fe75272b526 (diff)
downloadbcm5719-llvm-4272af9b3e7f55fc15e2ff704f46d76d69134d40.tar.gz
bcm5719-llvm-4272af9b3e7f55fc15e2ff704f46d76d69134d40.zip
[CodeGen] Omit range checks from jump tables when lowering switches with unreachable default
During the lowering of a switch that would result in the generation of a jump table, a range check is performed before indexing into the jump table, for the switch value being outside the jump table range and a conditional branch is inserted to jump to the default block. In case the default block is unreachable, this conditional jump can be omitted. This patch implements omitting this conditional branch for unreachable defaults. Review ID: D52002 Reviewers: Hans Wennborg, Eli Freidman, Roman Lebedev llvm-svn: 352484
Diffstat (limited to 'llvm/test/CodeGen/AArch64')
-rw-r--r--llvm/test/CodeGen/AArch64/switch-unreachable-default.ll124
1 files changed, 124 insertions, 0 deletions
diff --git a/llvm/test/CodeGen/AArch64/switch-unreachable-default.ll b/llvm/test/CodeGen/AArch64/switch-unreachable-default.ll
new file mode 100644
index 00000000000..e0819bda254
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/switch-unreachable-default.ll
@@ -0,0 +1,124 @@
+; RUN: llc -O3 -o - %s | FileCheck %s
+
+; Test that the output in the presence of an unreachable default does not have
+; a compare and branch at the top of the switch to handle the default case.
+
+target triple = "aarch64-unknown-linux-gnu"
+
+; Function Attrs: nounwind
+define void @fn(i4) {
+ switch i4 %0, label %default [
+ i4 0, label %case_0
+ i4 1, label %case_1
+ i4 2, label %case_2
+ i4 3, label %case_3
+ i4 4, label %case_4
+ i4 5, label %case_5
+ ]
+
+; CHECK-LABEL: fn:
+; CHECK-NOT: sub
+; CHECK-NOT: cmp
+; CHECK-NOT: b.hi
+; CHECK: ldr {{x[0-9]+}}, [{{x[0-9]+}}, {{x[0-9]+}}, lsl #3]
+; CHECK: br {{x[0-9]+}}
+
+default:
+ unreachable
+
+case_0:
+ tail call void @handle_case_00(i4 %0) #2
+ br label %return_label
+
+case_1:
+ tail call void @handle_case_01(i4 %0) #2
+ br label %return_label
+
+case_2:
+ tail call void @handle_case_02(i4 %0) #2
+ br label %return_label
+
+case_3:
+ tail call void @handle_case_03(i4 %0) #2
+ br label %return_label
+
+case_4:
+ tail call void @handle_case_04(i4 %0) #2
+ br label %return_label
+
+case_5:
+ tail call void @handle_case_05(i4 %0) #2
+ br label %return_label
+
+return_label:
+ ret void
+}
+
+declare void @handle_case_00(i4)
+declare void @handle_case_01(i4)
+declare void @handle_case_02(i4)
+declare void @handle_case_03(i4)
+declare void @handle_case_04(i4)
+declare void @handle_case_05(i4)
+; RUN: llc -O3 -o - %s | FileCheck %s
+
+; Test that the output in the presence of an unreachable default does not have
+; a compare and branch at the top of the switch to handle the default case.
+
+target triple = "aarch64-unknown-linux-gnu"
+
+; Function Attrs: nounwind
+define void @fn(i4) {
+ switch i4 %0, label %default [
+ i4 0, label %case_0
+ i4 1, label %case_1
+ i4 2, label %case_2
+ i4 3, label %case_3
+ i4 4, label %case_4
+ i4 5, label %case_5
+ ]
+
+; CHECK-LABEL: fn:
+; CHECK-NOT: sub
+; CHECK-NOT: cmp
+; CHECK-NOT: b.hi
+; CHECK: ldr {{x[0-9]+}}, [{{x[0-9]+}}, {{x[0-9]+}}, lsl #3]
+; CHECK: br {{x[0-9]+}}
+
+default:
+ unreachable
+
+case_0:
+ tail call void @handle_case_00(i4 %0) #2
+ br label %return_label
+
+case_1:
+ tail call void @handle_case_01(i4 %0) #2
+ br label %return_label
+
+case_2:
+ tail call void @handle_case_02(i4 %0) #2
+ br label %return_label
+
+case_3:
+ tail call void @handle_case_03(i4 %0) #2
+ br label %return_label
+
+case_4:
+ tail call void @handle_case_04(i4 %0) #2
+ br label %return_label
+
+case_5:
+ tail call void @handle_case_05(i4 %0) #2
+ br label %return_label
+
+return_label:
+ ret void
+}
+
+declare void @handle_case_00(i4)
+declare void @handle_case_01(i4)
+declare void @handle_case_02(i4)
+declare void @handle_case_03(i4)
+declare void @handle_case_04(i4)
+declare void @handle_case_05(i4)
OpenPOWER on IntegriCloud