James Y Knight | 7c90506 | 2015-11-23 21:33:58 +0000 | [diff] [blame] | 1 | ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 2 | ; RUN: llc -mtriple=x86_64-unknown-unknown -mattr=+sse4.1 < %s | FileCheck %s |
Simon Pilgrim | 2415144 | 2016-09-07 13:40:03 +0000 | [diff] [blame] | 3 | |
Sanjay Patel | 8a5f981 | 2016-10-30 18:04:19 +0000 | [diff] [blame] | 4 | define i32 @and_self(i32 %x) { |
| 5 | ; CHECK-LABEL: and_self: |
| 6 | ; CHECK: # BB#0: |
Sanjay Patel | 8a5f981 | 2016-10-30 18:04:19 +0000 | [diff] [blame] | 7 | ; CHECK-NEXT: movl %edi, %eax |
| 8 | ; CHECK-NEXT: retq |
| 9 | %and = and i32 %x, %x |
| 10 | ret i32 %and |
| 11 | } |
| 12 | |
| 13 | define <4 x i32> @and_self_vec(<4 x i32> %x) { |
| 14 | ; CHECK-LABEL: and_self_vec: |
| 15 | ; CHECK: # BB#0: |
Sanjay Patel | 8a5f981 | 2016-10-30 18:04:19 +0000 | [diff] [blame] | 16 | ; CHECK-NEXT: retq |
| 17 | %and = and <4 x i32> %x, %x |
| 18 | ret <4 x i32> %and |
| 19 | } |
| 20 | |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 21 | ; |
| 22 | ; Verify that the DAGCombiner is able to fold a vector AND into a blend |
| 23 | ; if one of the operands to the AND is a vector of all constants, and each |
| 24 | ; constant element is either zero or all-ones. |
Simon Pilgrim | 2415144 | 2016-09-07 13:40:03 +0000 | [diff] [blame] | 25 | ; |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 26 | |
| 27 | define <4 x i32> @test1(<4 x i32> %A) { |
Chandler Carruth | 52332dc | 2015-02-04 00:58:37 +0000 | [diff] [blame] | 28 | ; CHECK-LABEL: test1: |
| 29 | ; CHECK: # BB#0: |
| 30 | ; CHECK-NEXT: pxor %xmm1, %xmm1 |
| 31 | ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3,4,5,6,7] |
| 32 | ; CHECK-NEXT: retq |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 33 | %1 = and <4 x i32> %A, <i32 -1, i32 0, i32 0, i32 0> |
| 34 | ret <4 x i32> %1 |
| 35 | } |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 36 | |
| 37 | define <4 x i32> @test2(<4 x i32> %A) { |
Chandler Carruth | 52332dc | 2015-02-04 00:58:37 +0000 | [diff] [blame] | 38 | ; CHECK-LABEL: test2: |
| 39 | ; CHECK: # BB#0: |
| 40 | ; CHECK-NEXT: pxor %xmm1, %xmm1 |
| 41 | ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3],xmm1[4,5,6,7] |
| 42 | ; CHECK-NEXT: retq |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 43 | %1 = and <4 x i32> %A, <i32 0, i32 -1, i32 0, i32 0> |
| 44 | ret <4 x i32> %1 |
| 45 | } |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 46 | |
| 47 | define <4 x i32> @test3(<4 x i32> %A) { |
Chandler Carruth | 52332dc | 2015-02-04 00:58:37 +0000 | [diff] [blame] | 48 | ; CHECK-LABEL: test3: |
| 49 | ; CHECK: # BB#0: |
| 50 | ; CHECK-NEXT: pxor %xmm1, %xmm1 |
| 51 | ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm1[0,1,2,3],xmm0[4,5],xmm1[6,7] |
| 52 | ; CHECK-NEXT: retq |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 53 | %1 = and <4 x i32> %A, <i32 0, i32 0, i32 -1, i32 0> |
| 54 | ret <4 x i32> %1 |
| 55 | } |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 56 | |
| 57 | define <4 x i32> @test4(<4 x i32> %A) { |
Chandler Carruth | 52332dc | 2015-02-04 00:58:37 +0000 | [diff] [blame] | 58 | ; CHECK-LABEL: test4: |
| 59 | ; CHECK: # BB#0: |
| 60 | ; CHECK-NEXT: pxor %xmm1, %xmm1 |
| 61 | ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm1[0,1,2,3,4,5],xmm0[6,7] |
| 62 | ; CHECK-NEXT: retq |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 63 | %1 = and <4 x i32> %A, <i32 0, i32 0, i32 0, i32 -1> |
| 64 | ret <4 x i32> %1 |
| 65 | } |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 66 | |
| 67 | define <4 x i32> @test5(<4 x i32> %A) { |
Chandler Carruth | 52332dc | 2015-02-04 00:58:37 +0000 | [diff] [blame] | 68 | ; CHECK-LABEL: test5: |
| 69 | ; CHECK: # BB#0: |
| 70 | ; CHECK-NEXT: pxor %xmm1, %xmm1 |
| 71 | ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3],xmm0[4,5],xmm1[6,7] |
| 72 | ; CHECK-NEXT: retq |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 73 | %1 = and <4 x i32> %A, <i32 -1, i32 0, i32 -1, i32 0> |
| 74 | ret <4 x i32> %1 |
| 75 | } |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 76 | |
| 77 | define <4 x i32> @test6(<4 x i32> %A) { |
Chandler Carruth | 52332dc | 2015-02-04 00:58:37 +0000 | [diff] [blame] | 78 | ; CHECK-LABEL: test6: |
| 79 | ; CHECK: # BB#0: |
| 80 | ; CHECK-NEXT: pxor %xmm1, %xmm1 |
| 81 | ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3],xmm1[4,5],xmm0[6,7] |
| 82 | ; CHECK-NEXT: retq |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 83 | %1 = and <4 x i32> %A, <i32 0, i32 -1, i32 0, i32 -1> |
| 84 | ret <4 x i32> %1 |
| 85 | } |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 86 | |
| 87 | define <4 x i32> @test7(<4 x i32> %A) { |
Chandler Carruth | 52332dc | 2015-02-04 00:58:37 +0000 | [diff] [blame] | 88 | ; CHECK-LABEL: test7: |
| 89 | ; CHECK: # BB#0: |
| 90 | ; CHECK-NEXT: pxor %xmm1, %xmm1 |
| 91 | ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm1[0,1,2,3],xmm0[4,5,6,7] |
| 92 | ; CHECK-NEXT: retq |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 93 | %1 = and <4 x i32> %A, <i32 0, i32 0, i32 -1, i32 -1> |
| 94 | ret <4 x i32> %1 |
| 95 | } |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 96 | |
| 97 | define <4 x i32> @test8(<4 x i32> %A) { |
Chandler Carruth | 52332dc | 2015-02-04 00:58:37 +0000 | [diff] [blame] | 98 | ; CHECK-LABEL: test8: |
| 99 | ; CHECK: # BB#0: |
| 100 | ; CHECK-NEXT: pxor %xmm1, %xmm1 |
| 101 | ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3,4,5],xmm0[6,7] |
| 102 | ; CHECK-NEXT: retq |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 103 | %1 = and <4 x i32> %A, <i32 -1, i32 0, i32 0, i32 -1> |
| 104 | ret <4 x i32> %1 |
| 105 | } |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 106 | |
| 107 | define <4 x i32> @test9(<4 x i32> %A) { |
Chandler Carruth | 52332dc | 2015-02-04 00:58:37 +0000 | [diff] [blame] | 108 | ; CHECK-LABEL: test9: |
| 109 | ; CHECK: # BB#0: |
| 110 | ; CHECK-NEXT: movq {{.*#+}} xmm0 = xmm0[0],zero |
| 111 | ; CHECK-NEXT: retq |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 112 | %1 = and <4 x i32> %A, <i32 -1, i32 -1, i32 0, i32 0> |
| 113 | ret <4 x i32> %1 |
| 114 | } |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 115 | |
| 116 | define <4 x i32> @test10(<4 x i32> %A) { |
Chandler Carruth | 52332dc | 2015-02-04 00:58:37 +0000 | [diff] [blame] | 117 | ; CHECK-LABEL: test10: |
| 118 | ; CHECK: # BB#0: |
| 119 | ; CHECK-NEXT: pxor %xmm1, %xmm1 |
| 120 | ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3,4,5],xmm1[6,7] |
| 121 | ; CHECK-NEXT: retq |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 122 | %1 = and <4 x i32> %A, <i32 0, i32 -1, i32 -1, i32 0> |
| 123 | ret <4 x i32> %1 |
| 124 | } |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 125 | |
| 126 | define <4 x i32> @test11(<4 x i32> %A) { |
Chandler Carruth | 52332dc | 2015-02-04 00:58:37 +0000 | [diff] [blame] | 127 | ; CHECK-LABEL: test11: |
| 128 | ; CHECK: # BB#0: |
| 129 | ; CHECK-NEXT: pxor %xmm1, %xmm1 |
| 130 | ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3,4,5,6,7] |
| 131 | ; CHECK-NEXT: retq |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 132 | %1 = and <4 x i32> %A, <i32 0, i32 -1, i32 -1, i32 -1> |
| 133 | ret <4 x i32> %1 |
| 134 | } |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 135 | |
| 136 | define <4 x i32> @test12(<4 x i32> %A) { |
Chandler Carruth | 52332dc | 2015-02-04 00:58:37 +0000 | [diff] [blame] | 137 | ; CHECK-LABEL: test12: |
| 138 | ; CHECK: # BB#0: |
| 139 | ; CHECK-NEXT: pxor %xmm1, %xmm1 |
| 140 | ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm0[0,1,2,3,4,5],xmm1[6,7] |
| 141 | ; CHECK-NEXT: retq |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 142 | %1 = and <4 x i32> %A, <i32 -1, i32 -1, i32 -1, i32 0> |
| 143 | ret <4 x i32> %1 |
| 144 | } |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 145 | |
| 146 | define <4 x i32> @test13(<4 x i32> %A) { |
Chandler Carruth | 52332dc | 2015-02-04 00:58:37 +0000 | [diff] [blame] | 147 | ; CHECK-LABEL: test13: |
| 148 | ; CHECK: # BB#0: |
| 149 | ; CHECK-NEXT: pxor %xmm1, %xmm1 |
| 150 | ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm0[0,1,2,3],xmm1[4,5],xmm0[6,7] |
| 151 | ; CHECK-NEXT: retq |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 152 | %1 = and <4 x i32> %A, <i32 -1, i32 -1, i32 0, i32 -1> |
| 153 | ret <4 x i32> %1 |
| 154 | } |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 155 | |
| 156 | define <4 x i32> @test14(<4 x i32> %A) { |
Chandler Carruth | 52332dc | 2015-02-04 00:58:37 +0000 | [diff] [blame] | 157 | ; CHECK-LABEL: test14: |
| 158 | ; CHECK: # BB#0: |
| 159 | ; CHECK-NEXT: pxor %xmm1, %xmm1 |
| 160 | ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3],xmm0[4,5,6,7] |
| 161 | ; CHECK-NEXT: retq |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 162 | %1 = and <4 x i32> %A, <i32 -1, i32 0, i32 -1, i32 -1> |
| 163 | ret <4 x i32> %1 |
| 164 | } |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 165 | |
| 166 | define <4 x i32> @test15(<4 x i32> %A, <4 x i32> %B) { |
Chandler Carruth | 52332dc | 2015-02-04 00:58:37 +0000 | [diff] [blame] | 167 | ; CHECK-LABEL: test15: |
| 168 | ; CHECK: # BB#0: |
| 169 | ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3],xmm0[4,5,6,7] |
| 170 | ; CHECK-NEXT: retq |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 171 | %1 = and <4 x i32> %A, <i32 -1, i32 0, i32 -1, i32 -1> |
| 172 | %2 = and <4 x i32> %B, <i32 0, i32 -1, i32 0, i32 0> |
| 173 | %3 = or <4 x i32> %1, %2 |
| 174 | ret <4 x i32> %3 |
| 175 | } |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 176 | |
| 177 | define <4 x i32> @test16(<4 x i32> %A, <4 x i32> %B) { |
Chandler Carruth | 52332dc | 2015-02-04 00:58:37 +0000 | [diff] [blame] | 178 | ; CHECK-LABEL: test16: |
| 179 | ; CHECK: # BB#0: |
| 180 | ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3],xmm0[4,5],xmm1[6,7] |
| 181 | ; CHECK-NEXT: retq |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 182 | %1 = and <4 x i32> %A, <i32 -1, i32 0, i32 -1, i32 0> |
| 183 | %2 = and <4 x i32> %B, <i32 0, i32 -1, i32 0, i32 -1> |
| 184 | %3 = or <4 x i32> %1, %2 |
| 185 | ret <4 x i32> %3 |
| 186 | } |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 187 | |
| 188 | define <4 x i32> @test17(<4 x i32> %A, <4 x i32> %B) { |
Chandler Carruth | 52332dc | 2015-02-04 00:58:37 +0000 | [diff] [blame] | 189 | ; CHECK-LABEL: test17: |
| 190 | ; CHECK: # BB#0: |
| 191 | ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3],xmm1[4,5],xmm0[6,7] |
| 192 | ; CHECK-NEXT: retq |
Andrea Di Biagio | ce46b97 | 2014-11-05 13:04:14 +0000 | [diff] [blame] | 193 | %1 = and <4 x i32> %A, <i32 0, i32 -1, i32 0, i32 -1> |
| 194 | %2 = and <4 x i32> %B, <i32 -1, i32 0, i32 -1, i32 0> |
| 195 | %3 = or <4 x i32> %1, %2 |
| 196 | ret <4 x i32> %3 |
| 197 | } |
Simon Pilgrim | 2415144 | 2016-09-07 13:40:03 +0000 | [diff] [blame] | 198 | |
| 199 | ; |
| 200 | ; fold (and (or x, C), D) -> D if (C & D) == D |
| 201 | ; |
| 202 | |
| 203 | define <2 x i64> @and_or_v2i64(<2 x i64> %a0) { |
| 204 | ; CHECK-LABEL: and_or_v2i64: |
| 205 | ; CHECK: # BB#0: |
Simon Pilgrim | a01ee07 | 2016-09-08 12:36:39 +0000 | [diff] [blame] | 206 | ; CHECK-NEXT: movaps {{.*#+}} xmm0 = [8,8] |
Simon Pilgrim | 2415144 | 2016-09-07 13:40:03 +0000 | [diff] [blame] | 207 | ; CHECK-NEXT: retq |
| 208 | %1 = or <2 x i64> %a0, <i64 255, i64 255> |
| 209 | %2 = and <2 x i64> %1, <i64 8, i64 8> |
| 210 | ret <2 x i64> %2 |
| 211 | } |
| 212 | |
| 213 | define <4 x i32> @and_or_v4i32(<4 x i32> %a0) { |
| 214 | ; CHECK-LABEL: and_or_v4i32: |
| 215 | ; CHECK: # BB#0: |
Simon Pilgrim | a01ee07 | 2016-09-08 12:36:39 +0000 | [diff] [blame] | 216 | ; CHECK-NEXT: movaps {{.*#+}} xmm0 = [3,3,3,3] |
Simon Pilgrim | 2415144 | 2016-09-07 13:40:03 +0000 | [diff] [blame] | 217 | ; CHECK-NEXT: retq |
| 218 | %1 = or <4 x i32> %a0, <i32 15, i32 15, i32 15, i32 15> |
| 219 | %2 = and <4 x i32> %1, <i32 3, i32 3, i32 3, i32 3> |
| 220 | ret <4 x i32> %2 |
| 221 | } |
Simon Pilgrim | 65cdc05 | 2016-09-07 14:00:52 +0000 | [diff] [blame] | 222 | |
| 223 | ; |
| 224 | ; known bits folding |
| 225 | ; |
| 226 | |
| 227 | define <2 x i64> @and_or_zext_v2i32(<2 x i32> %a0) { |
| 228 | ; CHECK-LABEL: and_or_zext_v2i32: |
| 229 | ; CHECK: # BB#0: |
Simon Pilgrim | cc7b4b5 | 2016-09-08 12:57:51 +0000 | [diff] [blame] | 230 | ; CHECK-NEXT: xorps %xmm0, %xmm0 |
Simon Pilgrim | 65cdc05 | 2016-09-07 14:00:52 +0000 | [diff] [blame] | 231 | ; CHECK-NEXT: retq |
| 232 | %1 = zext <2 x i32> %a0 to <2 x i64> |
| 233 | %2 = or <2 x i64> %1, <i64 1, i64 1> |
| 234 | %3 = and <2 x i64> %2, <i64 4294967296, i64 4294967296> |
| 235 | ret <2 x i64> %3 |
| 236 | } |
| 237 | |
| 238 | define <4 x i32> @and_or_zext_v4i16(<4 x i16> %a0) { |
| 239 | ; CHECK-LABEL: and_or_zext_v4i16: |
| 240 | ; CHECK: # BB#0: |
Simon Pilgrim | cc7b4b5 | 2016-09-08 12:57:51 +0000 | [diff] [blame] | 241 | ; CHECK-NEXT: xorps %xmm0, %xmm0 |
Simon Pilgrim | 65cdc05 | 2016-09-07 14:00:52 +0000 | [diff] [blame] | 242 | ; CHECK-NEXT: retq |
| 243 | %1 = zext <4 x i16> %a0 to <4 x i32> |
| 244 | %2 = or <4 x i32> %1, <i32 1, i32 1, i32 1, i32 1> |
| 245 | %3 = and <4 x i32> %2, <i32 65536, i32 65536, i32 65536, i32 65536> |
| 246 | ret <4 x i32> %3 |
| 247 | } |