Teach SimplifyCFG about magic pointer constants.
[oota-llvm.git] / test / Transforms / SimplifyCFG / MagicPointer.ll
1 ; Test that simplifycfg can create switch instructions from constant pointers.
2 ;
3 ; RUN: opt < %s -simplifycfg -S | FileCheck %s
4
5 ; CHECK: switch i64 %magicptr
6 ; CHECK: i64 0, label
7 ; CHECK: i64 1, label
8 ; CHECK: i64 2, label
9 ; CHECK: i64 3, label
10 ; CHECK: i64 4, label
11 ; CHECK-NOT: br
12 ; CHECK: }
13
14 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
15 target triple = "x86_64-apple-darwin10.0.0"
16
17 @.str = private constant [5 x i8] c"null\00"      ; <[5 x i8]*> [#uses=2]
18 @.str1 = private constant [4 x i8] c"one\00"      ; <[4 x i8]*> [#uses=2]
19 @.str2 = private constant [4 x i8] c"two\00"      ; <[4 x i8]*> [#uses=2]
20 @.str3 = private constant [5 x i8] c"four\00"     ; <[5 x i8]*> [#uses=2]
21
22 define void @f(i8* %x) nounwind ssp {
23 entry:
24   %tobool = icmp eq i8* %x, null                  ; <i1> [#uses=1]
25   br i1 %tobool, label %if.then, label %if.else
26
27 if.then:                                          ; preds = %entry
28   %call = call i32 @puts(i8* getelementptr inbounds ([5 x i8]* @.str, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
29   br label %if.end21
30
31 if.else:                                          ; preds = %entry
32   %cmp = icmp eq i8* %x, inttoptr (i64 1 to i8*)  ; <i1> [#uses=1]
33   br i1 %cmp, label %if.then2, label %if.else4
34
35 if.then2:                                         ; preds = %if.else
36   %call3 = call i32 @puts(i8* getelementptr inbounds ([4 x i8]* @.str1, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
37   br label %if.end20
38
39 if.else4:                                         ; preds = %if.else
40   %cmp6 = icmp eq i8* %x, inttoptr (i64 2 to i8*) ; <i1> [#uses=1]
41   br i1 %cmp6, label %if.then9, label %lor.lhs.false
42
43 lor.lhs.false:                                    ; preds = %if.else4
44   %cmp8 = icmp eq i8* %x, inttoptr (i64 3 to i8*) ; <i1> [#uses=1]
45   br i1 %cmp8, label %if.then9, label %if.else11
46
47 if.then9:                                         ; preds = %lor.lhs.false, %if.else4
48   %call10 = call i32 @puts(i8* getelementptr inbounds ([4 x i8]* @.str2, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
49   br label %if.end19
50
51 if.else11:                                        ; preds = %lor.lhs.false
52   %cmp13 = icmp eq i8* %x, inttoptr (i64 4 to i8*) ; <i1> [#uses=1]
53   br i1 %cmp13, label %if.then14, label %if.else16
54
55 if.then14:                                        ; preds = %if.else11
56   %call15 = call i32 @puts(i8* getelementptr inbounds ([5 x i8]* @.str3, i64 0, i64 0)) nounwind ; <i32> [#uses=0]
57   br label %if.end
58
59 if.else16:                                        ; preds = %if.else11
60   %call18 = call i32 @puts(i8* %x) nounwind       ; <i32> [#uses=0]
61   br label %if.end
62
63 if.end:                                           ; preds = %if.else16, %if.then14
64   br label %if.end19
65
66 if.end19:                                         ; preds = %if.end, %if.then9
67   br label %if.end20
68
69 if.end20:                                         ; preds = %if.end19, %if.then2
70   br label %if.end21
71
72 if.end21:                                         ; preds = %if.end20, %if.then
73   ret void
74 }
75
76 declare i32 @puts(i8*)