Switch lowering: fix assert in buildBitTests (PR23738)
[oota-llvm.git] / test / CodeGen / X86 / switch.ll
index d50eabaa261866bf70146ab1f5188300df236277..a4dece65479c68a17216382007619f743ddfe799 100644 (file)
@@ -9,18 +9,19 @@ entry:
     i32 3, label %bb0
     i32 1, label %bb1
     i32 4, label %bb1
-    i32 5, label %bb0
+    i32 5, label %bb2
   ]
 bb0: tail call void @g(i32 0) br label %return
 bb1: tail call void @g(i32 1) br label %return
+bb2: tail call void @g(i32 1) br label %return
 return: ret void
 
 ; Should be lowered as straight compares in -O0 mode.
 ; NOOPT-LABEL: basic
-; NOOPT: subl $3, %eax
-; NOOPT: je
 ; NOOPT: subl $1, %eax
 ; NOOPT: je
+; NOOPT: subl $3, %eax
+; NOOPT: je
 ; NOOPT: subl $4, %eax
 ; NOOPT: je
 ; NOOPT: subl $5, %eax
@@ -58,6 +59,14 @@ return: ret void
 ; CHECK: jae
 ; CHECK: cmpl $3
 ; CHECK: ja
+
+; We do this even at -O0, because it's cheap and makes codegen faster.
+; NOOPT-LABEL: simple_ranges
+; NOOPT: subl $4
+; NOOPT: jb
+; NOOPT: addl $-100
+; NOOPT: subl $4
+; NOOPT: jb
 }
 
 
@@ -525,3 +534,18 @@ return: ret void
 ; CHECK-NOT: cmpl
 ; CHECK: cmpl $99
 }
+
+
+define void @pr23738(i4 %x) {
+entry:
+  switch i4 %x, label %bb0 [
+    i4 0, label %bb1
+    i4 1, label %bb1
+    i4 -5, label %bb1
+  ]
+bb0: tail call void @g(i32 0) br label %return
+bb1: tail call void @g(i32 1) br label %return
+return: ret void
+; Don't assert due to truncating the bitwidth (64) to i4 when checking
+; that the bit-test range fits in a word.
+}