| Chris Lattner | 74e9547 | 2002-05-06 05:43:36 +0000 | [diff] [blame] | 1 | ; This test makes sure that these instructions are properly eliminated. | 
|  | 2 | ; | 
|  | 3 |  | 
| Reid Spencer | d0e30dc | 2006-12-02 04:23:10 +0000 | [diff] [blame^] | 4 | ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine -disable-output && | 
|  | 5 | ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | not grep sh | 
| Chris Lattner | 74e9547 | 2002-05-06 05:43:36 +0000 | [diff] [blame] | 6 |  | 
|  | 7 | implementation | 
|  | 8 |  | 
| Chris Lattner | 87301bc | 2003-03-10 18:20:53 +0000 | [diff] [blame] | 9 | int %test1(int %A) { | 
| Chris Lattner | 74e9547 | 2002-05-06 05:43:36 +0000 | [diff] [blame] | 10 | %B = shl int %A, ubyte 0 | 
|  | 11 | ret int %B | 
|  | 12 | } | 
|  | 13 |  | 
| Chris Lattner | 87301bc | 2003-03-10 18:20:53 +0000 | [diff] [blame] | 14 | int %test2(ubyte %A) { | 
| Chris Lattner | 74e9547 | 2002-05-06 05:43:36 +0000 | [diff] [blame] | 15 | %B = shl int 0, ubyte %A | 
|  | 16 | ret int %B | 
|  | 17 | } | 
|  | 18 |  | 
| Chris Lattner | 87301bc | 2003-03-10 18:20:53 +0000 | [diff] [blame] | 19 | int %test3(int %A) { | 
| Chris Lattner | 74e9547 | 2002-05-06 05:43:36 +0000 | [diff] [blame] | 20 | %B = shr int %A, ubyte 0 | 
|  | 21 | ret int %B | 
|  | 22 | } | 
|  | 23 |  | 
| Chris Lattner | 87301bc | 2003-03-10 18:20:53 +0000 | [diff] [blame] | 24 | int %test4(ubyte %A) { | 
| Chris Lattner | 74e9547 | 2002-05-06 05:43:36 +0000 | [diff] [blame] | 25 | %B = shr int 0, ubyte %A | 
|  | 26 | ret int %B | 
|  | 27 | } | 
|  | 28 |  | 
| Chris Lattner | 87301bc | 2003-03-10 18:20:53 +0000 | [diff] [blame] | 29 | uint %test5(uint %A) { | 
| Chris Lattner | bcb8138 | 2002-05-06 16:11:31 +0000 | [diff] [blame] | 30 | %B = shr uint %A, ubyte 32  ;; shift all bits out | 
|  | 31 | ret uint %B | 
| Chris Lattner | 74e9547 | 2002-05-06 05:43:36 +0000 | [diff] [blame] | 32 | } | 
|  | 33 |  | 
| Chris Lattner | d97f054 | 2003-03-10 19:16:20 +0000 | [diff] [blame] | 34 | uint %test5a(uint %A) { | 
|  | 35 | %B = shl uint %A, ubyte 32  ;; shift all bits out | 
|  | 36 | ret uint %B | 
|  | 37 | } | 
|  | 38 |  | 
| Chris Lattner | 025e58d | 2002-09-10 23:03:10 +0000 | [diff] [blame] | 39 | uint %test6(uint %A) { | 
| Chris Lattner | bcbac5e | 2003-08-13 04:20:06 +0000 | [diff] [blame] | 40 | %B = shl uint %A, ubyte 1   ;; convert to an mul instruction | 
|  | 41 | %C = mul uint %B, 3 | 
|  | 42 | ret uint %C | 
| Chris Lattner | 025e58d | 2002-09-10 23:03:10 +0000 | [diff] [blame] | 43 | } | 
| Chris Lattner | ee5c8a9 | 2002-10-08 16:10:35 +0000 | [diff] [blame] | 44 |  | 
|  | 45 | int %test7(ubyte %A) { | 
|  | 46 | %B = shr int -1, ubyte %A   ;; Always equal to -1 | 
|  | 47 | ret int %B | 
|  | 48 | } | 
| Chris Lattner | d97f054 | 2003-03-10 19:16:20 +0000 | [diff] [blame] | 49 |  | 
|  | 50 | ubyte %test8(ubyte %A) {              ;; (A << 5) << 3 === A << 8 == 0 | 
|  | 51 | %B = shl ubyte %A, ubyte 5 | 
|  | 52 | %C = shl ubyte %B, ubyte 3 | 
|  | 53 | ret ubyte %C | 
|  | 54 | } | 
|  | 55 |  | 
|  | 56 | ubyte %test9(ubyte %A) {              ;; (A << 7) >> 7 === A & 1 | 
|  | 57 | %B = shl ubyte %A, ubyte 7 | 
|  | 58 | %C = shr ubyte %B, ubyte 7 | 
|  | 59 | ret ubyte %C | 
|  | 60 | } | 
|  | 61 |  | 
|  | 62 | ubyte %test10(ubyte %A) {              ;; (A >> 7) << 7 === A & 128 | 
|  | 63 | %B = shr ubyte %A, ubyte 7 | 
|  | 64 | %C = shl ubyte %B, ubyte 7 | 
|  | 65 | ret ubyte %C | 
|  | 66 | } | 
|  | 67 |  | 
| Chris Lattner | 9e2dc89 | 2003-07-24 18:38:09 +0000 | [diff] [blame] | 68 | ubyte %test11(ubyte %A) {              ;; (A >> 3) << 4 === (A & 0x1F) << 1 | 
| Chris Lattner | bcbac5e | 2003-08-13 04:20:06 +0000 | [diff] [blame] | 69 | %a = mul ubyte %A, 3 | 
|  | 70 | %B = shr ubyte %a, ubyte 3 | 
| Chris Lattner | d97f054 | 2003-03-10 19:16:20 +0000 | [diff] [blame] | 71 | %C = shl ubyte %B, ubyte 4 | 
|  | 72 | ret ubyte %C | 
|  | 73 | } | 
|  | 74 |  | 
| Chris Lattner | 9e2dc89 | 2003-07-24 18:38:09 +0000 | [diff] [blame] | 75 | int %test12(int %A) { | 
|  | 76 | %B = shr int %A, ubyte 8    ;; (A >> 8) << 8 === A & -256 | 
|  | 77 | %C = shl int %B, ubyte 8 | 
|  | 78 | ret int %C | 
|  | 79 | } | 
|  | 80 |  | 
|  | 81 | sbyte %test13(sbyte %A) {           ;; (A >> 3) << 4 === (A & -8) * 2 | 
| Chris Lattner | bcbac5e | 2003-08-13 04:20:06 +0000 | [diff] [blame] | 82 | %a = mul sbyte %A, 3 | 
|  | 83 | %B = shr sbyte %a, ubyte 3 | 
| Chris Lattner | 9e2dc89 | 2003-07-24 18:38:09 +0000 | [diff] [blame] | 84 | %C = shl sbyte %B, ubyte 4 | 
|  | 85 | ret sbyte %C | 
|  | 86 | } | 
| Chris Lattner | 699b952 | 2003-08-12 21:20:49 +0000 | [diff] [blame] | 87 |  | 
|  | 88 | uint %test14(uint %A) { | 
|  | 89 | %B = shr uint %A, ubyte 4 | 
|  | 90 | %C = or uint %B, 1234 | 
|  | 91 | %D = shl uint %C, ubyte 4   ;; D = ((B | 1234) << 4) === ((B << 4)|(1234 << 4) | 
|  | 92 | ret uint %D | 
|  | 93 | } | 
| Chris Lattner | e8c98de | 2003-08-12 21:22:51 +0000 | [diff] [blame] | 94 | uint %test14a(uint %A) { | 
|  | 95 | %B = shl uint %A, ubyte 4 | 
|  | 96 | %C = and uint %B, 1234 | 
|  | 97 | %D = shr uint %C, ubyte 4   ;; D = ((B | 1234) << 4) === ((B << 4)|(1234 << 4) | 
|  | 98 | ret uint %D | 
| Chris Lattner | 699b952 | 2003-08-12 21:20:49 +0000 | [diff] [blame] | 99 | } | 
| Chris Lattner | 24cd6b9 | 2004-04-09 23:47:24 +0000 | [diff] [blame] | 100 |  | 
|  | 101 | int %test15(bool %C) { | 
|  | 102 | %A = select bool %C, int 3, int 1 | 
|  | 103 | %V = shl int %A, ubyte 2 | 
|  | 104 | ret int %V | 
|  | 105 | } | 
|  | 106 |  | 
|  | 107 | int %test15a(bool %C) { | 
|  | 108 | %A = select bool %C, ubyte 3, ubyte 1 | 
|  | 109 | %V = shl int 64, ubyte %A | 
|  | 110 | ret int %V | 
|  | 111 | } | 
|  | 112 |  | 
| Chris Lattner | 6a02158 | 2004-05-25 06:30:49 +0000 | [diff] [blame] | 113 | bool %test16(int %X) { | 
|  | 114 | %tmp.3 = shr int %X, ubyte 4 | 
|  | 115 | %tmp.6 = and int %tmp.3, 1 | 
|  | 116 | %tmp.7 = setne int %tmp.6, 0  ;; X & 16 != 0 | 
|  | 117 | ret bool %tmp.7 | 
|  | 118 | } | 
| Chris Lattner | fbfb4d4 | 2004-09-27 16:21:26 +0000 | [diff] [blame] | 119 |  | 
|  | 120 | bool %test17(uint %A) { | 
|  | 121 | %B = shr uint %A, ubyte 3 | 
|  | 122 | %C = seteq uint %B, 1234 | 
|  | 123 | ret bool %C | 
|  | 124 | } | 
|  | 125 |  | 
|  | 126 | bool %test18(ubyte %A) { | 
|  | 127 | %B = shr ubyte %A, ubyte 7 | 
|  | 128 | %C = seteq ubyte %B, 123    ;; false | 
|  | 129 | ret bool %C | 
|  | 130 | } | 
|  | 131 |  | 
|  | 132 | bool %test19(int %A) { | 
|  | 133 | %B = shr int %A, ubyte 2 | 
|  | 134 | %C = seteq int %B, 0        ;; (X & -4) == 0 | 
|  | 135 | ret bool %C | 
|  | 136 | } | 
|  | 137 |  | 
|  | 138 | bool %test19a(int %A) { | 
|  | 139 | %B = shr int %A, ubyte 2 | 
|  | 140 | %C = seteq int %B, -1        ;; (X & -4) == -4 | 
|  | 141 | ret bool %C | 
|  | 142 | } | 
|  | 143 |  | 
|  | 144 | bool %test20(sbyte %A) { | 
|  | 145 | %B = shr sbyte %A, ubyte 7 | 
|  | 146 | %C = seteq sbyte %B, 123    ;; false | 
|  | 147 | ret bool %C | 
|  | 148 | } | 
| Chris Lattner | 3dd0ae6 | 2004-09-28 18:18:35 +0000 | [diff] [blame] | 149 |  | 
|  | 150 | bool %test21(ubyte %A) { | 
|  | 151 | %B = shl ubyte %A, ubyte 4 | 
|  | 152 | %C = seteq ubyte %B, 128 | 
|  | 153 | ret bool %C | 
|  | 154 | } | 
|  | 155 |  | 
|  | 156 | bool %test22(ubyte %A) { | 
|  | 157 | %B = shl ubyte %A, ubyte 4 | 
|  | 158 | %C = seteq ubyte %B, 0 | 
|  | 159 | ret bool %C | 
|  | 160 | } | 
|  | 161 |  | 
| Chris Lattner | 1524489f | 2005-05-06 04:11:32 +0000 | [diff] [blame] | 162 | sbyte %test23(int %A) { | 
|  | 163 | %B = shl int %A, ubyte 24  ;; casts not needed | 
|  | 164 | %C = shr int %B, ubyte 24 | 
|  | 165 | %D = cast int %C to sbyte | 
|  | 166 | ret sbyte %D | 
|  | 167 | } | 
| Chris Lattner | 5140c15 | 2005-05-08 17:31:24 +0000 | [diff] [blame] | 168 |  | 
|  | 169 | sbyte %test24(sbyte %X) { | 
|  | 170 | %Y = and sbyte %X, -5 ; ~4 | 
|  | 171 | %Z = shl sbyte %Y, ubyte 5 | 
|  | 172 | %Q = shr sbyte %Z, ubyte 5 | 
|  | 173 | ret sbyte %Q | 
|  | 174 | } | 
|  | 175 |  | 
| Chris Lattner | 1813aab | 2005-09-18 05:10:39 +0000 | [diff] [blame] | 176 | uint %test25(uint %tmp.2, uint %AA) { | 
|  | 177 | %x = shr uint %AA, ubyte 17 | 
|  | 178 | %tmp.3 = shr uint %tmp.2, ubyte 17              ; <uint> [#uses=1] | 
|  | 179 | %tmp.5 = add uint %tmp.3, %x            ; <uint> [#uses=1] | 
|  | 180 | %tmp.6 = shl uint %tmp.5, ubyte 17              ; <uint> [#uses=1] | 
|  | 181 | ret uint %tmp.6 | 
|  | 182 | } | 
|  | 183 |  | 
| Chris Lattner | 60d3002 | 2006-01-06 07:48:28 +0000 | [diff] [blame] | 184 | int %test26(uint %A) { ;; handle casts between shifts. | 
|  | 185 | %B = shr uint %A, ubyte 1 | 
|  | 186 | %C = cast uint %B to int | 
|  | 187 | %D = shl int %C, ubyte 1 | 
|  | 188 | ret int %D | 
|  | 189 | } | 
|  | 190 |  |