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)
54 %castbig = cast ulong 99999999 to int
55 %castsmall = cast ulong 1 to int
56 %usebig = add int %castbig, %castsmall
58 %castglob = cast int* %AConst to long*
59 %dummyl = load long* %castglob
61 %castnull = cast ulong 0 to int*
67 ; Test branch-on-comparison-with-zero, in two ways:
69 ; 2. cannot be folded because result of comparison is used twice
71 void "testbool"(int, int) ; Def %0, %1
75 add int %0, %1 ; Def 4
76 sub int %4, %3 ; Def 5
77 setle int %5, %2 ; Def 0 - bool plane
78 br bool %0, label %retlbl, label %loop
81 add int %0, %1 ; Def 6
82 sub int %4, %3 ; Def 7
83 setle int %7, %2 ; Def 1 - bool
84 not bool %1 ; Def 2 - bool. first use of bool %1
85 br bool %1, label %loop, label %0 ; second use of bool %1
92 ; Test branch on floating point comparison
94 void "testfloatbool"(float %x, float %y) ; Def %0, %1 - float
96 %p = add float %x, %y ; Def 2 - float
97 %z = sub float %x, %y ; Def 3 - float
98 %b = setle float %p, %z ; Def 0 - bool
99 %c = not bool %b ; Def 1 - bool
100 br bool %b, label %0, label %goon
106 ; Test cases where an LLVM instruction requires no machine
107 ; instructions (e.g., cast int* to long). But there are 2 cases:
108 ; 1. If the result register has only a single use and the use is in the
109 ; same basic block, the operand will be copy-propagated during
110 ; instruction selection.
111 ; 2. If the result register has multiple uses or is in a different
112 ; basic block, it cannot (or will not) be copy propagated during
113 ; instruction selection. It will generate a
114 ; copy instruction (add-with-0), but this copy should get coalesced
115 ; away by the register allocator.
117 int "checkForward"(int %N, int* %A)
121 %reg114 = shl int %N, ubyte 2 ;;
122 %cast115 = cast int %reg114 to int* ;; reg114 will be propagated
123 %reg116 = add int* %A, %cast115 ;;
124 %reg118 = load int* %reg116 ;;
125 %cast117 = cast int %reg118 to long ;; reg118 will be copied 'cos
126 %reg159 = add long 1234567, %cast117 ;; cast117 has 2 uses, here
127 %reg160 = add long 7654321, %cast117 ;; and here.