1 %AConst = constant int 123
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
10 void "unusedBool"(int * %x, int * %y)
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]
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
27 void "mergeConstants"(int * %x, int * %y)
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
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
52 int* "castconst"(float)
55 %castbig = cast ulong 99999999 to int
56 %castsmall = cast ulong 1 to int
57 %usebig = add int %castbig, %castsmall
59 %castglob = cast int* %AConst to long*
60 %dummyl = load long* %castglob
62 %castnull = cast ulong 0 to int*
68 ; Test branch-on-comparison-with-zero, in two ways:
70 ; 2. cannot be folded because result of comparison is used twice
72 void "testbool"(int, int) ; Def %0, %1
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
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
96 ; Test branch on floating point comparison
98 void "testfloatbool"(float %x, float %y) ; Def %0, %1 - float
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
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.
124 int "checkForward"(int %N, int* %A)
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.