blob: 6be90ff0bdf9fa60d82c0a2ca92e3372c7854b36 [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
Vikram S. Adve4bec7fa2002-03-18 03:52:31 +000054; <label>:0
Vikram S. Advef6ee0d82001-10-18 00:22:02 +000055 %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
64end
65
66
67
Vikram S. Adve9bf65462001-09-18 13:10:26 +000068; 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;
72void "testbool"(int, int) ; Def %0, %1
Chris Lattnerfe5e5842001-10-03 01:48:04 +000073 const int 0 ; Def 2
74 const int -4 ; Def 3
Vikram S. Adve9bf65462001-09-18 13:10:26 +000075begin
Vikram S. Adve4bec7fa2002-03-18 03:52:31 +000076; <label>:0
77 br label %Top
78Top:
Vikram S. Adve9bf65462001-09-18 13:10:26 +000079 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
84loop:
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
Vikram S. Adve4bec7fa2002-03-18 03:52:31 +000089 br bool %1, label %loop, label %Top ; second use of bool %1
Vikram S. Adve9bf65462001-09-18 13:10:26 +000090
91retlbl:
92 ret void
93end
94
95
96; Test branch on floating point comparison
97;
98void "testfloatbool"(float %x, float %y) ; Def %0, %1 - float
99begin
Vikram S. Adve4bec7fa2002-03-18 03:52:31 +0000100; <label>:0
101 br label %Top
102Top:
Vikram S. Adve9bf65462001-09-18 13:10:26 +0000103 %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
Vikram S. Adve4bec7fa2002-03-18 03:52:31 +0000107 br bool %b, label %Top, label %goon
Vikram S. Adve9bf65462001-09-18 13:10:26 +0000108goon:
109 ret void
110end
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:
Vikram S. Advefd0336e2001-10-01 00:23:12 +0000115; 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
Vikram S. Adve9bf65462001-09-18 13:10:26 +0000121; copy instruction (add-with-0), but this copy should get coalesced
122; away by the register allocator.
123;
124int "checkForward"(int %N, int* %A)
125begin
126
127bb2: ;;<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
136end