New testcase
[oota-llvm.git] / test / select.ll
1 %AConst    = constant int 123
2
3 implementation
4
5 ; A SetCC whose result is used should produce instructions to
6 ; compute the boolean value in a register.  One whose result
7 ; is unused will only generate the condition code but not
8 ; the boolean result.
9
10 void "unusedBool"(int * %x, int * %y)
11 begin
12 ; <label>:0                             ;               [#uses=0]
13         seteq int * %x, %y              ; <bool>:0      [#uses=1]
14         not bool %0                     ; <bool>:1      [#uses=0]
15         setne int * %x, %y              ; <bool>:2      [#uses=0]
16         ret void
17 end
18
19 ; A constant argument to a Phi produces a Cast instruction in the
20 ; corresponding predecessor basic block.  This checks a few things:
21 ; -- phi arguments coming from the bottom of the same basic block
22 ;    (they should not be forward substituted in the machine code!)
23 ; -- code generation for casts of various types
24 ; -- use of immediate fields for integral constants of different sizes
25 ; -- branch on a constant condition
26
27 void "mergeConstants"(int * %x, int * %y)
28 begin
29 ; <label>:0
30         br label %Top
31 Top:
32         phi int    [ 0,    %0 ], [ 1,    %Top ], [ 524288, %Next ]
33         phi float  [ 0.0,  %0 ], [ 1.0,  %Top ], [ 2.0,    %Next ]
34         phi double [ 0.5,  %0 ], [ 1.5,  %Top ], [ 2.5,    %Next ]
35         phi bool   [ true, %0 ], [ false,%Top ], [ true,   %Next ]
36         br bool true, label %Top, label %Next
37 Next:
38         br label %Top
39 end
40
41
42
43 ; A constant argument to a cast used only once should be forward substituted
44 ; and loaded where needed, which happens is:
45 ; -- User of cast has no immediate field
46 ; -- User of cast has immediate field but constant is too large to fit
47 ;    or constant is not resolved until later (e.g., global address)
48 ; -- User of cast uses it as a call arg. or return value so it is an implicit
49 ;    use but has to be loaded into a virtual register so that the reg.
50 ;    allocator can allocate the appropriate phys. reg. for it
51 ;  
52 int* "castconst"(float)
53 begin
54 ; <label>:0
55         %castbig   = cast ulong 99999999 to int
56         %castsmall = cast ulong 1        to int
57         %usebig    = add int %castbig, %castsmall
58                 
59         %castglob = cast int* %AConst to long*
60         %dummyl   = load long* %castglob
61         
62         %castnull = cast ulong 0 to int*
63         ret int* %castnull
64 end
65
66
67
68 ; Test branch-on-comparison-with-zero, in two ways:
69 ; 1. can be folded
70 ; 2. cannot be folded because result of comparison is used twice
71 ;
72 void "testbool"(int, int)   ; Def %0, %1
73         const int 0          ; Def 2
74         const int -4         ; Def 3
75 begin
76 ; <label>:0
77         br label %Top
78 Top:
79         add int %0, %1    ; Def 4
80         sub int %4, %3    ; Def 5
81         setle int %5, %2  ; Def 0 - bool plane
82         br bool %0, label %retlbl, label %loop
83
84 loop:
85         add int %0, %1    ; Def 6
86         sub int %4, %3    ; Def 7
87         setle int %7, %2  ; Def 1 - bool
88         not bool %1               ; Def 2 - bool. first use of bool %1
89         br bool %1, label %loop, label %Top   ;  second use of bool %1
90
91 retlbl:
92         ret void
93 end
94
95
96 ; Test branch on floating point comparison
97 ;
98 void "testfloatbool"(float %x, float %y)   ; Def %0, %1 - float
99 begin
100 ; <label>:0
101         br label %Top
102 Top:
103         %p = add float %x, %y    ; Def 2 - float
104         %z = sub float %x, %y    ; Def 3 - float
105         %b = setle float %p, %z  ; Def 0 - bool
106         %c = not bool %b         ; Def 1 - bool
107         br bool %b, label %Top, label %goon
108 goon:
109         ret void
110 end
111
112
113 ; Test cases where an LLVM instruction requires no machine
114 ; instructions (e.g., cast int* to long).  But there are 2 cases:
115 ; 1. If the result register has only a single use and the use is in the
116 ;    same basic block, the operand will be copy-propagated during
117 ;    instruction selection.
118 ; 2. If the result register has multiple uses or is in a different
119 ;    basic block, it cannot (or will not) be copy propagated during
120 ;    instruction selection.  It will generate a
121 ;    copy instruction (add-with-0), but this copy should get coalesced
122 ;    away by the register allocator.
123 ;
124 int "checkForward"(int %N, int* %A)
125 begin
126
127 bb2:            ;;<label>
128         %reg114 = shl int %N, ubyte 2           ;;
129         %cast115 = cast int %reg114 to int*     ;; reg114 will be propagated
130         %reg116 = add int* %A, %cast115         ;;
131         %reg118 = load int* %reg116             ;;
132         %cast117 = cast int %reg118 to long     ;; reg118 will be copied 'cos
133         %reg159 = add long 1234567, %cast117    ;;  cast117 has 2 uses, here
134         %reg160 = add long 7654321, %cast117    ;;  and here.
135         ret void
136 end