blob: d937387a58c76b8694ac1f6d25ec3be72a60cc76 [file] [log] [blame]
Vikram S. Adve9bf65462001-09-18 13:10:26 +00001implementation
2
3; A SetCC whose result is used should produce instructions to
4; compute the boolean value in a register. One whose result
5; is unused will only generate the condition code but not
6; the boolean result.
7;
8void "unusedBool"(int * %x, int * %y)
9begin
10; <label>:0 ; [#uses=0]
11 seteq int * %x, %y ; <bool>:0 [#uses=1]
12 not bool %0 ; <bool>:1 [#uses=0]
13 setne int * %x, %y ; <bool>:2 [#uses=0]
14 ret void
15end
16
17; A constant argument to a Phi produces a Cast instruction in the
Vikram S. Advefd0336e2001-10-01 00:23:12 +000018; corresponding predecessor basic block. This checks a few things:
19; -- phi arguments coming from the bottom of the same basic block
20; (they should not be forward substituted in the machine code!)
21; -- code generation for casts of various types
22; -- use of immediate fields for integral constants of different sizes
23; -- branch on a constant condition
Vikram S. Adve9bf65462001-09-18 13:10:26 +000024;
25void "mergeConstants"(int * %x, int * %y)
26begin
Vikram S. Advefd0336e2001-10-01 00:23:12 +000027; <label>:0
Vikram S. Adve9bf65462001-09-18 13:10:26 +000028 br label %Top
Vikram S. Advefd0336e2001-10-01 00:23:12 +000029Top:
30 phi int [ 0, %0 ], [ 1, %Top ], [ 524288, %Next ]
31 phi float [ 0.0, %0 ], [ 1.0, %Top ], [ 2.0, %Next ]
32 phi double [ 0.5, %0 ], [ 1.5, %Top ], [ 2.5, %Next ]
33 phi bool [ true, %0 ], [ false,%Top ], [ true, %Next ]
Vikram S. Adve9bf65462001-09-18 13:10:26 +000034 br bool true, label %Top, label %Next
Vikram S. Advefd0336e2001-10-01 00:23:12 +000035Next:
Vikram S. Adve9bf65462001-09-18 13:10:26 +000036 br label %Top
37end
38
39
40; Test branch-on-comparison-with-zero, in two ways:
41; 1. can be folded
42; 2. cannot be folded because result of comparison is used twice
43;
44void "testbool"(int, int) ; Def %0, %1
45 int 0 ; Def 2
46 int -4 ; Def 3
47begin
48 add int %0, %1 ; Def 4
49 sub int %4, %3 ; Def 5
50 setle int %5, %2 ; Def 0 - bool plane
51 br bool %0, label %retlbl, label %loop
52
53loop:
54 add int %0, %1 ; Def 6
55 sub int %4, %3 ; Def 7
56 setle int %7, %2 ; Def 1 - bool
57 not bool %1 ; Def 2 - bool. first use of bool %1
58 br bool %1, label %loop, label %0 ; second use of bool %1
59
60retlbl:
61 ret void
62end
63
64
65; Test branch on floating point comparison
66;
67void "testfloatbool"(float %x, float %y) ; Def %0, %1 - float
68begin
69 %p = add float %x, %y ; Def 2 - float
70 %z = sub float %x, %y ; Def 3 - float
71 %b = setle float %p, %z ; Def 0 - bool
72 %c = not bool %b ; Def 1 - bool
73 br bool %b, label %0, label %goon
74goon:
75 ret void
76end
77
78
79; Test cases where an LLVM instruction requires no machine
80; instructions (e.g., cast int* to long). But there are 2 cases:
Vikram S. Advefd0336e2001-10-01 00:23:12 +000081; 1. If the result register has only a single use and the use is in the
82; same basic block, the operand will be copy-propagated during
83; instruction selection.
84; 2. If the result register has multiple uses or is in a different
85; basic block, it cannot (or will not) be copy propagated during
86; instruction selection. It will generate a
Vikram S. Adve9bf65462001-09-18 13:10:26 +000087; copy instruction (add-with-0), but this copy should get coalesced
88; away by the register allocator.
89;
90int "checkForward"(int %N, int* %A)
91begin
92
93bb2: ;;<label>
94 %reg114 = shl int %N, ubyte 2 ;;
95 %cast115 = cast int %reg114 to int* ;; reg114 will be propagated
96 %reg116 = add int* %A, %cast115 ;;
97 %reg118 = load int* %reg116 ;;
98 %cast117 = cast int %reg118 to long ;; reg118 will be copied 'cos
99 %reg159 = add long 1234567, %cast117 ;; cast117 has 2 uses, here
100 %reg160 = add long 7654321, %cast117 ;; and here.
101 ret void
102end