blob: 8a7348aa69af83ab02632becd6b76091d79ef4a6 [file] [log] [blame]
Vikram S. Advef6ee0d82001-10-18 00:22:02 +00001%AConst = constant int 123
2
Vikram S. Adve9bf65462001-09-18 13:10:26 +00003implementation
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;
10void "unusedBool"(int * %x, int * %y)
11begin
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
17end
18
19; A constant argument to a Phi produces a Cast instruction in the
Vikram S. Advefd0336e2001-10-01 00:23:12 +000020; 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
Vikram S. Adve9bf65462001-09-18 13:10:26 +000026;
27void "mergeConstants"(int * %x, int * %y)
28begin
Vikram S. Advefd0336e2001-10-01 00:23:12 +000029; <label>:0
Vikram S. Adve9bf65462001-09-18 13:10:26 +000030 br label %Top
Vikram S. Advefd0336e2001-10-01 00:23:12 +000031Top:
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 ]
Vikram S. Adve9bf65462001-09-18 13:10:26 +000036 br bool true, label %Top, label %Next
Vikram S. Advefd0336e2001-10-01 00:23:12 +000037Next:
Vikram S. Adve9bf65462001-09-18 13:10:26 +000038 br label %Top
39end
40
41
Vikram S. Advef6ee0d82001-10-18 00:22:02 +000042
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;
52int* "castconst"(float)
53begin
54 %castbig = cast ulong 99999999 to int
55 %castsmall = cast ulong 1 to int
56 %usebig = add int %castbig, %castsmall
57
58 %castglob = cast int* %AConst to long*
59 %dummyl = load long* %castglob
60
61 %castnull = cast ulong 0 to int*
62 ret int* %castnull
63end
64
65
66
Vikram S. Adve9bf65462001-09-18 13:10:26 +000067; Test branch-on-comparison-with-zero, in two ways:
68; 1. can be folded
69; 2. cannot be folded because result of comparison is used twice
70;
71void "testbool"(int, int) ; Def %0, %1
Chris Lattnerfe5e5842001-10-03 01:48:04 +000072 const int 0 ; Def 2
73 const int -4 ; Def 3
Vikram S. Adve9bf65462001-09-18 13:10:26 +000074begin
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
79
80loop:
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
86
87retlbl:
88 ret void
89end
90
91
92; Test branch on floating point comparison
93;
94void "testfloatbool"(float %x, float %y) ; Def %0, %1 - float
95begin
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
101goon:
102 ret void
103end
104
105
106; Test cases where an LLVM instruction requires no machine
107; instructions (e.g., cast int* to long). But there are 2 cases:
Vikram S. Advefd0336e2001-10-01 00:23:12 +0000108; 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
Vikram S. Adve9bf65462001-09-18 13:10:26 +0000114; copy instruction (add-with-0), but this copy should get coalesced
115; away by the register allocator.
116;
117int "checkForward"(int %N, int* %A)
118begin
119
120bb2: ;;<label>
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.
128 ret void
129end