llvm.org GIT mirror llvm / 7aaf5bf
Allow more cases of undef shuffle indices and add tests for them. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111226 91177308-0d34-0410-b5e6-96231b3b80d8 Bob Wilson 9 years ago
6 changed file(s) with 141 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
31473147 bool &ReverseVEXT, unsigned &Imm) {
31483148 unsigned NumElts = VT.getVectorNumElements();
31493149 ReverseVEXT = false;
3150
3151 // Assume that the first shuffle index is not UNDEF. Fail if it is.
3152 if (M[0] < 0)
3153 return false;
3154
31503155 Imm = M[0];
31513156
31523157 // If this is a VEXT shuffle, the immediate value is the index of the first
31623167 ReverseVEXT = true;
31633168 }
31643169
3170 if (M[i] < 0) continue; // ignore UNDEF indices
31653171 if (ExpectedElt != static_cast(M[i]))
31663172 return false;
31673173 }
31873193
31883194 unsigned NumElts = VT.getVectorNumElements();
31893195 unsigned BlockElts = M[0] + 1;
3196 // If the first shuffle index is UNDEF, be optimistic.
3197 if (M[0] < 0)
3198 BlockElts = BlockSize / EltSz;
31903199
31913200 if (BlockSize <= EltSz || BlockSize != BlockElts * EltSz)
31923201 return false;
31933202
31943203 for (unsigned i = 0; i < NumElts; ++i) {
3195 if ((unsigned) M[i] !=
3196 (i - i%BlockElts) + (BlockElts - 1 - i%BlockElts))
3204 if (M[i] < 0) continue; // ignore UNDEF indices
3205 if ((unsigned) M[i] != (i - i%BlockElts) + (BlockElts - 1 - i%BlockElts))
31973206 return false;
31983207 }
31993208
32093218 unsigned NumElts = VT.getVectorNumElements();
32103219 WhichResult = (M[0] == 0 ? 0 : 1);
32113220 for (unsigned i = 0; i < NumElts; i += 2) {
3212 if ((unsigned) M[i] != i + WhichResult ||
3213 (unsigned) M[i+1] != i + NumElts + WhichResult)
3221 if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) ||
3222 (M[i+1] >= 0 && (unsigned) M[i+1] != i + NumElts + WhichResult))
32143223 return false;
32153224 }
32163225 return true;
32283237 unsigned NumElts = VT.getVectorNumElements();
32293238 WhichResult = (M[0] == 0 ? 0 : 1);
32303239 for (unsigned i = 0; i < NumElts; i += 2) {
3231 if (M[i] < 0) continue;
3232 if ((unsigned) M[i] != i + WhichResult ||
3233 (unsigned) M[i+1] != i + WhichResult)
3240 if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) ||
3241 (M[i+1] >= 0 && (unsigned) M[i+1] != i + WhichResult))
32343242 return false;
32353243 }
32363244 return true;
32453253 unsigned NumElts = VT.getVectorNumElements();
32463254 WhichResult = (M[0] == 0 ? 0 : 1);
32473255 for (unsigned i = 0; i != NumElts; ++i) {
3256 if (M[i] < 0) continue; // ignore UNDEF indices
32483257 if ((unsigned) M[i] != 2 * i + WhichResult)
32493258 return false;
32503259 }
32703279 for (unsigned j = 0; j != 2; ++j) {
32713280 unsigned Idx = WhichResult;
32723281 for (unsigned i = 0; i != Half; ++i) {
3273 if ((unsigned) M[i + j * Half] != Idx)
3282 int MIdx = M[i + j * Half];
3283 if (MIdx >= 0 && (unsigned) MIdx != Idx)
32743284 return false;
32753285 Idx += 2;
32763286 }
32933303 WhichResult = (M[0] == 0 ? 0 : 1);
32943304 unsigned Idx = WhichResult * NumElts / 2;
32953305 for (unsigned i = 0; i != NumElts; i += 2) {
3296 if ((unsigned) M[i] != Idx ||
3297 (unsigned) M[i+1] != Idx + NumElts)
3306 if ((M[i] >= 0 && (unsigned) M[i] != Idx) ||
3307 (M[i+1] >= 0 && (unsigned) M[i+1] != Idx + NumElts))
32983308 return false;
32993309 Idx += 1;
33003310 }
33193329 WhichResult = (M[0] == 0 ? 0 : 1);
33203330 unsigned Idx = WhichResult * NumElts / 2;
33213331 for (unsigned i = 0; i != NumElts; i += 2) {
3322 if ((unsigned) M[i] != Idx ||
3323 (unsigned) M[i+1] != Idx)
3332 if ((M[i] >= 0 && (unsigned) M[i] != Idx) ||
3333 (M[i+1] >= 0 && (unsigned) M[i+1] != Idx))
33243334 return false;
33253335 Idx += 1;
33263336 }
5353 ret <4 x i32> %tmp3
5454 }
5555
56 ; Undef shuffle indices should not prevent matching to VEXT:
57
58 define <8 x i8> @test_vextd_undef(<8 x i8>* %A, <8 x i8>* %B) nounwind {
59 ;CHECK: test_vextd_undef:
60 ;CHECK: vext
61 %tmp1 = load <8 x i8>* %A
62 %tmp2 = load <8 x i8>* %B
63 %tmp3 = shufflevector <8 x i8> %tmp1, <8 x i8> %tmp2, <8 x i32>
64 ret <8 x i8> %tmp3
65 }
66
67 define <16 x i8> @test_vextRq_undef(<16 x i8>* %A, <16 x i8>* %B) nounwind {
68 ;CHECK: test_vextRq_undef:
69 ;CHECK: vext
70 %tmp1 = load <16 x i8>* %A
71 %tmp2 = load <16 x i8>* %B
72 %tmp3 = shufflevector <16 x i8> %tmp1, <16 x i8> %tmp2, <16 x i32>
73 ret <16 x i8> %tmp3
74 }
75
110110 %tmp2 = shufflevector <16 x i8> %tmp1, <16 x i8> undef, <16 x i32>
111111 ret <16 x i8> %tmp2
112112 }
113
114 ; Undef shuffle indices should not prevent matching to VREV:
115
116 define <8 x i8> @test_vrev64D8_undef(<8 x i8>* %A) nounwind {
117 ;CHECK: test_vrev64D8_undef:
118 ;CHECK: vrev64.8
119 %tmp1 = load <8 x i8>* %A
120 %tmp2 = shufflevector <8 x i8> %tmp1, <8 x i8> undef, <8 x i32>
121 ret <8 x i8> %tmp2
122 }
123
124 define <8 x i16> @test_vrev32Q16_undef(<8 x i16>* %A) nounwind {
125 ;CHECK: test_vrev32Q16_undef:
126 ;CHECK: vrev32.16
127 %tmp1 = load <8 x i16>* %A
128 %tmp2 = shufflevector <8 x i16> %tmp1, <8 x i16> undef, <8 x i32>
129 ret <8 x i16> %tmp2
130 }
9494 %tmp5 = fadd <4 x float> %tmp3, %tmp4
9595 ret <4 x float> %tmp5
9696 }
97
98 ; Undef shuffle indices should not prevent matching to VTRN:
99
100 define <8 x i8> @vtrni8_undef(<8 x i8>* %A, <8 x i8>* %B) nounwind {
101 ;CHECK: vtrni8_undef:
102 ;CHECK: vtrn.8
103 ;CHECK-NEXT: vadd.i8
104 %tmp1 = load <8 x i8>* %A
105 %tmp2 = load <8 x i8>* %B
106 %tmp3 = shufflevector <8 x i8> %tmp1, <8 x i8> %tmp2, <8 x i32>
107 %tmp4 = shufflevector <8 x i8> %tmp1, <8 x i8> %tmp2, <8 x i32>
108 %tmp5 = add <8 x i8> %tmp3, %tmp4
109 ret <8 x i8> %tmp5
110 }
111
112 define <8 x i16> @vtrnQi16_undef(<8 x i16>* %A, <8 x i16>* %B) nounwind {
113 ;CHECK: vtrnQi16_undef:
114 ;CHECK: vtrn.16
115 ;CHECK-NEXT: vadd.i16
116 %tmp1 = load <8 x i16>* %A
117 %tmp2 = load <8 x i16>* %B
118 %tmp3 = shufflevector <8 x i16> %tmp1, <8 x i16> %tmp2, <8 x i32>
119 %tmp4 = shufflevector <8 x i16> %tmp1, <8 x i16> %tmp2, <8 x i32>
120 %tmp5 = add <8 x i16> %tmp3, %tmp4
121 ret <8 x i16> %tmp5
122 }
123
7272 %tmp5 = fadd <4 x float> %tmp3, %tmp4
7373 ret <4 x float> %tmp5
7474 }
75
76 ; Undef shuffle indices should not prevent matching to VUZP:
77
78 define <8 x i8> @vuzpi8_undef(<8 x i8>* %A, <8 x i8>* %B) nounwind {
79 ;CHECK: vuzpi8_undef:
80 ;CHECK: vuzp.8
81 ;CHECK-NEXT: vadd.i8
82 %tmp1 = load <8 x i8>* %A
83 %tmp2 = load <8 x i8>* %B
84 %tmp3 = shufflevector <8 x i8> %tmp1, <8 x i8> %tmp2, <8 x i32>
85 %tmp4 = shufflevector <8 x i8> %tmp1, <8 x i8> %tmp2, <8 x i32>
86 %tmp5 = add <8 x i8> %tmp3, %tmp4
87 ret <8 x i8> %tmp5
88 }
89
90 define <8 x i16> @vuzpQi16_undef(<8 x i16>* %A, <8 x i16>* %B) nounwind {
91 ;CHECK: vuzpQi16_undef:
92 ;CHECK: vuzp.16
93 ;CHECK-NEXT: vadd.i16
94 %tmp1 = load <8 x i16>* %A
95 %tmp2 = load <8 x i16>* %B
96 %tmp3 = shufflevector <8 x i16> %tmp1, <8 x i16> %tmp2, <8 x i32>
97 %tmp4 = shufflevector <8 x i16> %tmp1, <8 x i16> %tmp2, <8 x i32>
98 %tmp5 = add <8 x i16> %tmp3, %tmp4
99 ret <8 x i16> %tmp5
100 }
101
7272 %tmp5 = fadd <4 x float> %tmp3, %tmp4
7373 ret <4 x float> %tmp5
7474 }
75
76 ; Undef shuffle indices should not prevent matching to VZIP:
77
78 define <8 x i8> @vzipi8_undef(<8 x i8>* %A, <8 x i8>* %B) nounwind {
79 ;CHECK: vzipi8_undef:
80 ;CHECK: vzip.8
81 ;CHECK-NEXT: vadd.i8
82 %tmp1 = load <8 x i8>* %A
83 %tmp2 = load <8 x i8>* %B
84 %tmp3 = shufflevector <8 x i8> %tmp1, <8 x i8> %tmp2, <8 x i32>
85 %tmp4 = shufflevector <8 x i8> %tmp1, <8 x i8> %tmp2, <8 x i32>
86 %tmp5 = add <8 x i8> %tmp3, %tmp4
87 ret <8 x i8> %tmp5
88 }
89
90 define <16 x i8> @vzipQi8_undef(<16 x i8>* %A, <16 x i8>* %B) nounwind {
91 ;CHECK: vzipQi8_undef:
92 ;CHECK: vzip.8
93 ;CHECK-NEXT: vadd.i8
94 %tmp1 = load <16 x i8>* %A
95 %tmp2 = load <16 x i8>* %B
96 %tmp3 = shufflevector <16 x i8> %tmp1, <16 x i8> %tmp2, <16 x i32>
97 %tmp4 = shufflevector <16 x i8> %tmp1, <16 x i8> %tmp2, <16 x i32>
98 %tmp5 = add <16 x i8> %tmp3, %tmp4
99 ret <16 x i8> %tmp5
100 }
101