From 76b1313e75a594f3a5e128fff2c2fa1a1d339309 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Thu, 4 Dec 2014 22:19:28 +0000 Subject: [PATCH] Add some tests for SimplifyCFG's TurnSwitchRangeIntoICmp(). NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223396 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../SimplifyCFG/switch-range-to-icmp.ll | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test/Transforms/SimplifyCFG/switch-range-to-icmp.ll diff --git a/test/Transforms/SimplifyCFG/switch-range-to-icmp.ll b/test/Transforms/SimplifyCFG/switch-range-to-icmp.ll new file mode 100644 index 00000000000..8bf2b04520b --- /dev/null +++ b/test/Transforms/SimplifyCFG/switch-range-to-icmp.ll @@ -0,0 +1,50 @@ +; RUN: opt %s -simplifycfg -S | FileCheck %s + +declare i32 @f(i32) + +define i32 @basic(i32 %x) { +; CHECK-LABEL: @basic +; CHECK: x.off = add i32 %x, -5 +; CHECK: %switch = icmp ult i32 %x.off, 3 +; CHECK: br i1 %switch, label %a, label %default + +entry: + switch i32 %x, label %default [ + i32 5, label %a + i32 6, label %a + i32 7, label %a + ] +default: + %0 = call i32 @f(i32 0) + ret i32 %0 +a: + %1 = call i32 @f(i32 1) + ret i32 %1 +} + + +define i32 @unreachable(i32 %x) { +; CHECK-LABEL: @unreachable +; CHECK: x.off = add i32 %x, -5 +; CHECK: %switch = icmp ult i32 %x.off, 3 +; CHECK: br i1 %switch, label %a, label %b + +entry: + switch i32 %x, label %unreachable [ + i32 5, label %a + i32 6, label %a + i32 7, label %a + i32 10, label %b + i32 20, label %b + i32 30, label %b + i32 40, label %b + ] +unreachable: + unreachable +a: + %0 = call i32 @f(i32 0) + ret i32 %0 +b: + %1 = call i32 @f(i32 1) + ret i32 %1 +}