Vikram S. Adve | 9bf6546 | 2001-09-18 13:10:26 +0000 | [diff] [blame] | 1 | implementation |
| 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 | ; |
| 8 | void "unusedBool"(int * %x, int * %y) |
| 9 | begin |
| 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 |
| 15 | end |
| 16 | |
| 17 | ; A constant argument to a Phi produces a Cast instruction in the |
Vikram S. Adve | fd0336e | 2001-10-01 00:23:12 +0000 | [diff] [blame] | 18 | ; 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. Adve | 9bf6546 | 2001-09-18 13:10:26 +0000 | [diff] [blame] | 24 | ; |
| 25 | void "mergeConstants"(int * %x, int * %y) |
| 26 | begin |
Vikram S. Adve | fd0336e | 2001-10-01 00:23:12 +0000 | [diff] [blame] | 27 | ; <label>:0 |
Vikram S. Adve | 9bf6546 | 2001-09-18 13:10:26 +0000 | [diff] [blame] | 28 | br label %Top |
Vikram S. Adve | fd0336e | 2001-10-01 00:23:12 +0000 | [diff] [blame] | 29 | Top: |
| 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. Adve | 9bf6546 | 2001-09-18 13:10:26 +0000 | [diff] [blame] | 34 | br bool true, label %Top, label %Next |
Vikram S. Adve | fd0336e | 2001-10-01 00:23:12 +0000 | [diff] [blame] | 35 | Next: |
Vikram S. Adve | 9bf6546 | 2001-09-18 13:10:26 +0000 | [diff] [blame] | 36 | br label %Top |
| 37 | end |
| 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 | ; |
| 44 | void "testbool"(int, int) ; Def %0, %1 |
Chris Lattner | fe5e584 | 2001-10-03 01:48:04 +0000 | [diff] [blame^] | 45 | const int 0 ; Def 2 |
| 46 | const int -4 ; Def 3 |
Vikram S. Adve | 9bf6546 | 2001-09-18 13:10:26 +0000 | [diff] [blame] | 47 | begin |
| 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 | |
| 53 | loop: |
| 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 | |
| 60 | retlbl: |
| 61 | ret void |
| 62 | end |
| 63 | |
| 64 | |
| 65 | ; Test branch on floating point comparison |
| 66 | ; |
| 67 | void "testfloatbool"(float %x, float %y) ; Def %0, %1 - float |
| 68 | begin |
| 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 |
| 74 | goon: |
| 75 | ret void |
| 76 | end |
| 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. Adve | fd0336e | 2001-10-01 00:23:12 +0000 | [diff] [blame] | 81 | ; 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. Adve | 9bf6546 | 2001-09-18 13:10:26 +0000 | [diff] [blame] | 87 | ; copy instruction (add-with-0), but this copy should get coalesced |
| 88 | ; away by the register allocator. |
| 89 | ; |
| 90 | int "checkForward"(int %N, int* %A) |
| 91 | begin |
| 92 | |
| 93 | bb2: ;;<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 |
| 102 | end |