1 //===- VectorUtilsTest.cpp - VectorUtils tests ------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "llvm/Analysis/VectorUtils.h"
10 #include "llvm/Analysis/ValueTracking.h"
11 #include "llvm/AsmParser/Parser.h"
12 #include "llvm/IR/Function.h"
13 #include "llvm/IR/InstIterator.h"
14 #include "llvm/IR/IRBuilder.h"
15 #include "llvm/IR/LLVMContext.h"
16 #include "llvm/IR/Module.h"
17 #include "llvm/IR/NoFolder.h"
18 #include "llvm/Support/ErrorHandling.h"
19 #include "llvm/Support/SourceMgr.h"
20 #include "llvm/Support/KnownBits.h"
21 #include "gtest/gtest.h"
22 
23 using namespace llvm;
24 
25 namespace {
26 
27 class VectorUtilsTest : public testing::Test {
28 protected:
29   void parseAssembly(const char *Assembly) {
30     SMDiagnostic Error;
31     M = parseAssemblyString(Assembly, Error, Context);
32 
33     std::string errMsg;
34     raw_string_ostream os(errMsg);
35     Error.print("", os);
36 
37     // A failure here means that the test itself is buggy.
38     if (!M)
39       report_fatal_error(os.str());
40 
41     Function *F = M->getFunction("test");
42     if (F == nullptr)
43       report_fatal_error("Test must have a function named @test");
44 
45     A = nullptr;
46     for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
47       if (I->hasName()) {
48         if (I->getName() == "A")
49           A = &*I;
50       }
51     }
52     if (A == nullptr)
53       report_fatal_error("@test must have an instruction %A");
54   }
55 
56   LLVMContext Context;
57   std::unique_ptr<Module> M;
58   Instruction *A;
59 };
60 
61 struct BasicTest : public testing::Test {
62   LLVMContext Ctx;
63   std::unique_ptr<Module> M;
64   Function *F;
65   BasicBlock *BB;
66   IRBuilder<NoFolder> IRB;
67 
68   BasicTest()
69       : M(new Module("VectorUtils", Ctx)),
70         F(Function::Create(
71             FunctionType::get(Type::getVoidTy(Ctx), /* IsVarArg */ false),
72             Function::ExternalLinkage, "f", M.get())),
73         BB(BasicBlock::Create(Ctx, "entry", F)), IRB(BB) {}
74 };
75 
76 
77 } // namespace
78 
79 TEST_F(BasicTest, isSplat) {
80   Value *UndefVec = UndefValue::get(VectorType::get(IRB.getInt8Ty(), 4));
81   EXPECT_TRUE(isSplatValue(UndefVec));
82 
83   Constant *UndefScalar = UndefValue::get(IRB.getInt8Ty());
84   EXPECT_FALSE(isSplatValue(UndefScalar));
85 
86   Constant *ScalarC = IRB.getInt8(42);
87   EXPECT_FALSE(isSplatValue(ScalarC));
88 
89   Constant *OtherScalarC = IRB.getInt8(-42);
90   Constant *NonSplatC = ConstantVector::get({ScalarC, OtherScalarC});
91   EXPECT_FALSE(isSplatValue(NonSplatC));
92 
93   Value *SplatC = IRB.CreateVectorSplat(5, ScalarC);
94   EXPECT_TRUE(isSplatValue(SplatC));
95 
96   // FIXME: Constant splat analysis does not allow undef elements.
97   Constant *SplatWithUndefC = ConstantVector::get({ScalarC, UndefScalar});
98   EXPECT_FALSE(isSplatValue(SplatWithUndefC));
99 }
100 
101 TEST_F(VectorUtilsTest, isSplatValue_00) {
102   parseAssembly(
103       "define <2 x i8> @test(<2 x i8> %x) {\n"
104       "  %A = shufflevector <2 x i8> %x, <2 x i8> undef, <2 x i32> zeroinitializer\n"
105       "  ret <2 x i8> %A\n"
106       "}\n");
107   EXPECT_TRUE(isSplatValue(A));
108 }
109 
110 TEST_F(VectorUtilsTest, isSplatValue_11) {
111   parseAssembly(
112       "define <2 x i8> @test(<2 x i8> %x) {\n"
113       "  %A = shufflevector <2 x i8> %x, <2 x i8> undef, <2 x i32> <i32 1, i32 1>\n"
114       "  ret <2 x i8> %A\n"
115       "}\n");
116   EXPECT_TRUE(isSplatValue(A));
117 }
118 
119 TEST_F(VectorUtilsTest, isSplatValue_01) {
120   parseAssembly(
121       "define <2 x i8> @test(<2 x i8> %x) {\n"
122       "  %A = shufflevector <2 x i8> %x, <2 x i8> undef, <2 x i32> <i32 0, i32 1>\n"
123       "  ret <2 x i8> %A\n"
124       "}\n");
125   EXPECT_FALSE(isSplatValue(A));
126 }
127 
128 // FIXME: Constant (mask) splat analysis does not allow undef elements.
129 
130 TEST_F(VectorUtilsTest, isSplatValue_0u) {
131   parseAssembly(
132       "define <2 x i8> @test(<2 x i8> %x) {\n"
133       "  %A = shufflevector <2 x i8> %x, <2 x i8> undef, <2 x i32> <i32 0, i32 undef>\n"
134       "  ret <2 x i8> %A\n"
135       "}\n");
136   EXPECT_FALSE(isSplatValue(A));
137 }
138 
139 TEST_F(VectorUtilsTest, isSplatValue_Binop) {
140   parseAssembly(
141       "define <2 x i8> @test(<2 x i8> %x) {\n"
142       "  %v0 = shufflevector <2 x i8> %x, <2 x i8> undef, <2 x i32> <i32 0, i32 0>\n"
143       "  %v1 = shufflevector <2 x i8> %x, <2 x i8> undef, <2 x i32> <i32 1, i32 1>\n"
144       "  %A = udiv <2 x i8> %v0, %v1\n"
145       "  ret <2 x i8> %A\n"
146       "}\n");
147   EXPECT_TRUE(isSplatValue(A));
148 }
149 
150 TEST_F(VectorUtilsTest, isSplatValue_Binop_ConstantOp0) {
151   parseAssembly(
152       "define <2 x i8> @test(<2 x i8> %x) {\n"
153       "  %v1 = shufflevector <2 x i8> %x, <2 x i8> undef, <2 x i32> <i32 1, i32 1>\n"
154       "  %A = ashr <2 x i8> <i8 42, i8 42>, %v1\n"
155       "  ret <2 x i8> %A\n"
156       "}\n");
157   EXPECT_TRUE(isSplatValue(A));
158 }
159 
160 TEST_F(VectorUtilsTest, isSplatValue_Binop_Not_Op0) {
161   parseAssembly(
162       "define <2 x i8> @test(<2 x i8> %x) {\n"
163       "  %v0 = shufflevector <2 x i8> %x, <2 x i8> undef, <2 x i32> <i32 1, i32 0>\n"
164       "  %v1 = shufflevector <2 x i8> %x, <2 x i8> undef, <2 x i32> <i32 1, i32 1>\n"
165       "  %A = add <2 x i8> %v0, %v1\n"
166       "  ret <2 x i8> %A\n"
167       "}\n");
168   EXPECT_FALSE(isSplatValue(A));
169 }
170 
171 TEST_F(VectorUtilsTest, isSplatValue_Binop_Not_Op1) {
172   parseAssembly(
173       "define <2 x i8> @test(<2 x i8> %x) {\n"
174       "  %v0 = shufflevector <2 x i8> %x, <2 x i8> undef, <2 x i32> <i32 1, i32 1>\n"
175       "  %v1 = shufflevector <2 x i8> %x, <2 x i8> undef, <2 x i32> <i32 0, i32 1>\n"
176       "  %A = shl <2 x i8> %v0, %v1\n"
177       "  ret <2 x i8> %A\n"
178       "}\n");
179   EXPECT_FALSE(isSplatValue(A));
180 }
181 
182 TEST_F(VectorUtilsTest, isSplatValue_Select) {
183   parseAssembly(
184       "define <2 x i8> @test(<2 x i1> %x, <2 x i8> %y, <2 x i8> %z) {\n"
185       "  %v0 = shufflevector <2 x i1> %x, <2 x i1> undef, <2 x i32> <i32 1, i32 1>\n"
186       "  %v1 = shufflevector <2 x i8> %y, <2 x i8> undef, <2 x i32> <i32 0, i32 0>\n"
187       "  %v2 = shufflevector <2 x i8> %z, <2 x i8> undef, <2 x i32> <i32 1, i32 1>\n"
188       "  %A = select <2 x i1> %v0, <2 x i8> %v1, <2 x i8> %v2\n"
189       "  ret <2 x i8> %A\n"
190       "}\n");
191   EXPECT_TRUE(isSplatValue(A));
192 }
193 
194 TEST_F(VectorUtilsTest, isSplatValue_Select_ConstantOp) {
195   parseAssembly(
196       "define <2 x i8> @test(<2 x i1> %x, <2 x i8> %y, <2 x i8> %z) {\n"
197       "  %v0 = shufflevector <2 x i1> %x, <2 x i1> undef, <2 x i32> <i32 1, i32 1>\n"
198       "  %v2 = shufflevector <2 x i8> %z, <2 x i8> undef, <2 x i32> <i32 1, i32 1>\n"
199       "  %A = select <2 x i1> %v0, <2 x i8> <i8 42, i8 42>, <2 x i8> %v2\n"
200       "  ret <2 x i8> %A\n"
201       "}\n");
202   EXPECT_TRUE(isSplatValue(A));
203 }
204 
205 TEST_F(VectorUtilsTest, isSplatValue_Select_NotCond) {
206   parseAssembly(
207       "define <2 x i8> @test(<2 x i1> %x, <2 x i8> %y, <2 x i8> %z) {\n"
208       "  %v1 = shufflevector <2 x i8> %y, <2 x i8> undef, <2 x i32> <i32 0, i32 0>\n"
209       "  %v2 = shufflevector <2 x i8> %z, <2 x i8> undef, <2 x i32> <i32 1, i32 1>\n"
210       "  %A = select <2 x i1> %x, <2 x i8> %v1, <2 x i8> %v2\n"
211       "  ret <2 x i8> %A\n"
212       "}\n");
213   EXPECT_FALSE(isSplatValue(A));
214 }
215 
216 TEST_F(VectorUtilsTest, isSplatValue_Select_NotOp1) {
217   parseAssembly(
218       "define <2 x i8> @test(<2 x i1> %x, <2 x i8> %y, <2 x i8> %z) {\n"
219       "  %v0 = shufflevector <2 x i1> %x, <2 x i1> undef, <2 x i32> <i32 1, i32 1>\n"
220       "  %v2 = shufflevector <2 x i8> %z, <2 x i8> undef, <2 x i32> <i32 1, i32 1>\n"
221       "  %A = select <2 x i1> %v0, <2 x i8> %y, <2 x i8> %v2\n"
222       "  ret <2 x i8> %A\n"
223       "}\n");
224   EXPECT_FALSE(isSplatValue(A));
225 }
226 
227 TEST_F(VectorUtilsTest, isSplatValue_Select_NotOp2) {
228   parseAssembly(
229       "define <2 x i8> @test(<2 x i1> %x, <2 x i8> %y, <2 x i8> %z) {\n"
230       "  %v0 = shufflevector <2 x i1> %x, <2 x i1> undef, <2 x i32> <i32 1, i32 1>\n"
231       "  %v1 = shufflevector <2 x i8> %y, <2 x i8> undef, <2 x i32> <i32 0, i32 0>\n"
232       "  %A = select <2 x i1> %v0, <2 x i8> %v1, <2 x i8> %z\n"
233       "  ret <2 x i8> %A\n"
234       "}\n");
235   EXPECT_FALSE(isSplatValue(A));
236 }
237 
238 TEST_F(VectorUtilsTest, isSplatValue_SelectBinop) {
239   parseAssembly(
240       "define <2 x i8> @test(<2 x i1> %x, <2 x i8> %y, <2 x i8> %z) {\n"
241       "  %v0 = shufflevector <2 x i1> %x, <2 x i1> undef, <2 x i32> <i32 1, i32 1>\n"
242       "  %v1 = shufflevector <2 x i8> %y, <2 x i8> undef, <2 x i32> <i32 0, i32 0>\n"
243       "  %v2 = shufflevector <2 x i8> %z, <2 x i8> undef, <2 x i32> <i32 1, i32 1>\n"
244       "  %bo = xor <2 x i8> %v1, %v2\n"
245       "  %A = select <2 x i1> %v0, <2 x i8> %bo, <2 x i8> %v2\n"
246       "  ret <2 x i8> %A\n"
247       "}\n");
248   EXPECT_TRUE(isSplatValue(A));
249 }
250 
251 TEST_F(VectorUtilsTest, getSplatValueElt0) {
252   parseAssembly(
253       "define <2 x i8> @test(i8 %x) {\n"
254       "  %ins = insertelement <2 x i8> undef, i8 %x, i32 0\n"
255       "  %A = shufflevector <2 x i8> %ins, <2 x i8> undef, <2 x i32> zeroinitializer\n"
256       "  ret <2 x i8> %A\n"
257       "}\n");
258   EXPECT_EQ(getSplatValue(A)->getName(), "x");
259 }
260 
261 TEST_F(VectorUtilsTest, getSplatValueEltMismatch) {
262   parseAssembly(
263       "define <2 x i8> @test(i8 %x) {\n"
264       "  %ins = insertelement <2 x i8> undef, i8 %x, i32 1\n"
265       "  %A = shufflevector <2 x i8> %ins, <2 x i8> undef, <2 x i32> zeroinitializer\n"
266       "  ret <2 x i8> %A\n"
267       "}\n");
268   EXPECT_EQ(getSplatValue(A), nullptr);
269 }
270 
271 // TODO: This is a splat, but we don't recognize it.
272 
273 TEST_F(VectorUtilsTest, getSplatValueElt1) {
274   parseAssembly(
275       "define <2 x i8> @test(i8 %x) {\n"
276       "  %ins = insertelement <2 x i8> undef, i8 %x, i32 1\n"
277       "  %A = shufflevector <2 x i8> %ins, <2 x i8> undef, <2 x i32> <i32 1, i32 1>\n"
278       "  ret <2 x i8> %A\n"
279       "}\n");
280   EXPECT_EQ(getSplatValue(A), nullptr);
281 }
282 
283 ////////////////////////////////////////////////////////////////////////////////
284 // VFShape API tests.
285 ////////////////////////////////////////////////////////////////////////////////
286 
287 class VFShapeAPITest : public testing::Test {
288 protected:
289   void SetUp() override {
290     M = parseAssemblyString(IR, Err, Ctx);
291     // Get the only call instruction in the block, which is the first
292     // instruction.
293     CI = dyn_cast<CallInst>(&*(instructions(M->getFunction("f")).begin()));
294   }
295 
296   const char *IR = "define i32 @f(i32 %a, i64 %b, double %c) {\n"
297                    " %1 = call i32 @g(i32 %a, i64 %b, double %c)\n"
298                    "  ret i32 %1\n"
299                    "}\n"
300                    "declare i32 @g(i32, i64, double)\n";
301   LLVMContext Ctx;
302   SMDiagnostic Err;
303   std::unique_ptr<Module> M;
304   CallInst *CI;
305   // Dummy shape with no parameters, overwritten by buildShape when invoked.
306   VFShape Shape = {/*VF*/ 2, /*IsScalable*/ false, /*Parameters*/ {}};
307   VFShape Expected;
308   SmallVector<VFParameter, 8> &ExpectedParams = Expected.Parameters;
309 
310   void buildShape(unsigned VF, bool IsScalable, bool HasGlobalPred) {
311     Shape = VFShape::get(*CI, {VF, IsScalable}, HasGlobalPred);
312   }
313 
314   bool validParams(ArrayRef<VFParameter> Parameters) {
315     Shape.Parameters =
316         SmallVector<VFParameter, 8>(Parameters.begin(), Parameters.end());
317     return Shape.hasValidParameterList();
318   }
319 };
320 
321 TEST_F(VFShapeAPITest, API_buildVFShape) {
322   buildShape(/*VF*/ 2, /*IsScalable*/ false, /*HasGlobalPred*/ false);
323   Expected = {/*VF*/ 2, /*IsScalable*/ false, /*Parameters*/ {
324                   {0, VFParamKind::Vector},
325                   {1, VFParamKind::Vector},
326                   {2, VFParamKind::Vector},
327               }};
328   EXPECT_EQ(Shape, Expected);
329 
330   buildShape(/*VF*/ 4, /*IsScalable*/ false, /*HasGlobalPred*/ true);
331   Expected = {/*VF*/ 4, /*IsScalable*/ false, /*Parameters*/ {
332                   {0, VFParamKind::Vector},
333                   {1, VFParamKind::Vector},
334                   {2, VFParamKind::Vector},
335                   {3, VFParamKind::GlobalPredicate},
336               }};
337   EXPECT_EQ(Shape, Expected);
338 
339   buildShape(/*VF*/ 16, /*IsScalable*/ true, /*HasGlobalPred*/ false);
340   Expected = {/*VF*/ 16, /*IsScalable*/ true, /*Parameters*/ {
341                   {0, VFParamKind::Vector},
342                   {1, VFParamKind::Vector},
343                   {2, VFParamKind::Vector},
344               }};
345   EXPECT_EQ(Shape, Expected);
346 }
347 
348 TEST_F(VFShapeAPITest, API_updateVFShape) {
349 
350   buildShape(/*VF*/ 2, /*IsScalable*/ false, /*HasGlobalPred*/ false);
351   Shape.updateParam({0 /*Pos*/, VFParamKind::OMP_Linear, 1, Align(4)});
352   Expected = {/*VF*/ 2, /*IsScalable*/ false, /*Parameters*/ {
353                   {0, VFParamKind::OMP_Linear, 1, Align(4)},
354                   {1, VFParamKind::Vector},
355                   {2, VFParamKind::Vector},
356               }};
357   EXPECT_EQ(Shape, Expected);
358 
359   // From this point on, we update only the parameters of the VFShape,
360   // so we update only the reference of the expected Parameters.
361   Shape.updateParam({1 /*Pos*/, VFParamKind::OMP_Uniform});
362   ExpectedParams = {
363       {0, VFParamKind::OMP_Linear, 1, Align(4)},
364       {1, VFParamKind::OMP_Uniform},
365       {2, VFParamKind::Vector},
366   };
367   EXPECT_EQ(Shape, Expected);
368 
369   Shape.updateParam({2 /*Pos*/, VFParamKind::OMP_LinearRefPos, 1});
370   ExpectedParams = {
371       {0, VFParamKind::OMP_Linear, 1, Align(4)},
372       {1, VFParamKind::OMP_Uniform},
373       {2, VFParamKind::OMP_LinearRefPos, 1},
374   };
375   EXPECT_EQ(Shape, Expected);
376 }
377 
378 TEST_F(VFShapeAPITest, API_updateVFShape_GlobalPredicate) {
379 
380   buildShape(/*VF*/ 2, /*IsScalable*/ true, /*HasGlobalPred*/ true);
381   Shape.updateParam({1 /*Pos*/, VFParamKind::OMP_Uniform});
382   Expected = {/*VF*/ 2, /*IsScalable*/ true,
383               /*Parameters*/ {{0, VFParamKind::Vector},
384                               {1, VFParamKind::OMP_Uniform},
385                               {2, VFParamKind::Vector},
386                               {3, VFParamKind::GlobalPredicate}}};
387   EXPECT_EQ(Shape, Expected);
388 }
389 
390 TEST_F(VFShapeAPITest, Parameters_Valid) {
391   // ParamPos in order.
392   EXPECT_TRUE(validParams({{0, VFParamKind::Vector}}));
393   EXPECT_TRUE(
394       validParams({{0, VFParamKind::Vector}, {1, VFParamKind::Vector}}));
395   EXPECT_TRUE(validParams({{0, VFParamKind::Vector},
396                            {1, VFParamKind::Vector},
397                            {2, VFParamKind::Vector}}));
398 
399   // GlocalPredicate is unique.
400   EXPECT_TRUE(validParams({{0, VFParamKind::Vector},
401                            {1, VFParamKind::Vector},
402                            {2, VFParamKind::Vector},
403                            {3, VFParamKind::GlobalPredicate}}));
404 
405   EXPECT_TRUE(validParams({{0, VFParamKind::Vector},
406                            {1, VFParamKind::GlobalPredicate},
407                            {2, VFParamKind::Vector}}));
408 }
409 
410 TEST_F(VFShapeAPITest, Parameters_ValidOpenMPLinear) {
411 // Valid linear constant step (>0).
412 #define __BUILD_PARAMETERS(Kind, Val)                                          \
413   {                                                                            \
414     { 0, Kind, Val }                                                           \
415   }
416   EXPECT_TRUE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_Linear, 1)));
417   EXPECT_TRUE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_LinearRef, 2)));
418   EXPECT_TRUE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_LinearVal, 4)));
419   EXPECT_TRUE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_LinearUVal, 33)));
420 #undef __BUILD_PARAMETERS
421 
422 // Valid linear runtime step (the step parameter is marked uniform).
423 #define __BUILD_PARAMETERS(Kind)                                               \
424   {                                                                            \
425     {0, VFParamKind::OMP_Uniform}, {1, VFParamKind::Vector}, { 2, Kind, 0 }    \
426   }
427   EXPECT_TRUE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_LinearPos)));
428   EXPECT_TRUE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_LinearRefPos)));
429   EXPECT_TRUE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_LinearValPos)));
430   EXPECT_TRUE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_LinearUValPos)));
431 #undef __BUILD_PARAMETERS
432 }
433 
434 TEST_F(VFShapeAPITest, Parameters_Invalid) {
435 #ifndef NDEBUG
436   // Wrong order is checked by an assertion: make sure that the
437   // assertion is not removed.
438   EXPECT_DEATH(validParams({{1, VFParamKind::Vector}}),
439                "Broken parameter list.");
440   EXPECT_DEATH(
441       validParams({{1, VFParamKind::Vector}, {0, VFParamKind::Vector}}),
442       "Broken parameter list.");
443 #endif
444 
445   // GlobalPredicate is not unique
446   EXPECT_FALSE(validParams({{0, VFParamKind::Vector},
447                             {1, VFParamKind::GlobalPredicate},
448                             {2, VFParamKind::GlobalPredicate}}));
449   EXPECT_FALSE(validParams({{0, VFParamKind::GlobalPredicate},
450                             {1, VFParamKind::Vector},
451                             {2, VFParamKind::GlobalPredicate}}));
452 }
453 
454 TEST_F(VFShapeAPITest, Parameters_InvalidOpenMPLinear) {
455 // Compile time linear steps must be non-zero (compile time invariant).
456 #define __BUILD_PARAMETERS(Kind)                                               \
457   {                                                                            \
458     { 0, Kind, 0 }                                                             \
459   }
460   EXPECT_FALSE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_Linear)));
461   EXPECT_FALSE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_LinearRef)));
462   EXPECT_FALSE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_LinearVal)));
463   EXPECT_FALSE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_LinearUVal)));
464 #undef __BUILD_PARAMETERS
465 
466 // The step of a runtime linear parameter must be marked
467 // as uniform (runtime invariant).
468 #define __BUILD_PARAMETERS(Kind)                                               \
469   {                                                                            \
470     {0, VFParamKind::OMP_Uniform}, {1, VFParamKind::Vector}, { 2, Kind, 1 }    \
471   }
472   EXPECT_FALSE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_LinearPos)));
473   EXPECT_FALSE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_LinearRefPos)));
474   EXPECT_FALSE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_LinearValPos)));
475   EXPECT_FALSE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_LinearUValPos)));
476 #undef __BUILD_PARAMETERS
477 
478 // The linear step parameter can't point at itself.
479 #define __BUILD_PARAMETERS(Kind)                                               \
480   {                                                                            \
481     {0, VFParamKind::Vector}, {1, VFParamKind::Vector}, { 2, Kind, 2 }         \
482   }
483   EXPECT_FALSE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_LinearPos)));
484   EXPECT_FALSE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_LinearRefPos)));
485   EXPECT_FALSE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_LinearValPos)));
486   EXPECT_FALSE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_LinearUValPos)));
487 #undef __BUILD_PARAMETERS
488 
489 // Linear parameter (runtime) is out of range.
490 #define __BUILD_PARAMETERS(Kind)                                               \
491   {                                                                            \
492     {0, VFParamKind::Vector}, {1, VFParamKind::Vector}, { 2, Kind, 3 }         \
493   }
494   EXPECT_FALSE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_LinearPos)));
495   EXPECT_FALSE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_LinearRefPos)));
496   EXPECT_FALSE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_LinearValPos)));
497   EXPECT_FALSE(validParams(__BUILD_PARAMETERS(VFParamKind::OMP_LinearUValPos)));
498 #undef __BUILD_PARAMETERS
499 }
500