1 #include "AArch64Subtarget.h"
2 #include "AArch64TargetMachine.h"
3 #include "llvm/IR/DataLayout.h"
4 #include "llvm/MC/TargetRegistry.h"
5 #include "llvm/Support/TargetSelect.h"
7 #include "gtest/gtest.h"
8 #include <initializer_list>
20 const std::initializer_list
<TestCase
> Tests
= {
21 // ScalableImm, Result
22 // No change, easily 'supported'
25 // addvl increments by whole registers, range [-32,31]
26 // +(16 * vscale), one register's worth
28 // -(32 * 16 * vscale)
30 // -(33 * 16 * vscale)
32 // +(31 * 16 * vscale)
34 // +(32 * 16 * vscale)
37 // inc[h|w|d] increments by the number of 16/32/64bit elements in a
38 // register. mult_imm is in the range [1,16]
39 // +(mult_imm * num_elts * vscale)
40 // +(1 * 8 * vscale), 16 bit
42 // +(15 * 8 * vscale), 16 bit
44 // +(1 * 4 * vscale), 32 bit
46 // +(7 * 4 * vscale), 32 bit
48 // +(1 * 2 * vscale), 64 bit
50 // +(13 * 2 * vscale), 64 bit
52 // +(17 * 8 * vscale), 16 bit, out of range.
54 // +(19 * 2 * vscale), 64 bit, out of range.
56 // +(21 * 4 * vscale), 32 bit, out of range.
59 // dec[h|w|d] -- Same as above, but negative.
60 // -(mult_imm * num_elts * vscale)
61 // -(1 * 8 * vscale), 16 bit
63 // -(15 * 8 * vscale), 16 bit
65 // -(1 * 4 * vscale), 32 bit
67 // -(7 * 4 * vscale), 32 bit
69 // -(1 * 2 * vscale), 64 bit
71 // -(13 * 2 * vscale), 64 bit
73 // -(17 * 8 * vscale), 16 bit, out of range.
75 // -(19 * 2 * vscale), 64 bit, out of range.
77 // -(21 * 4 * vscale), 32 bit, out of range.
80 // Invalid; not divisible by the above powers of 2.
85 TEST(Immediates
, Immediates
) {
86 LLVMInitializeAArch64TargetInfo();
87 LLVMInitializeAArch64Target();
88 LLVMInitializeAArch64TargetMC();
91 auto TT
= Triple::normalize("aarch64");
92 const Target
*T
= TargetRegistry::lookupTarget(TT
, Error
);
94 std::unique_ptr
<TargetMachine
> TM(T
->createTargetMachine(
95 TT
, "generic", "+sve2", TargetOptions(), std::nullopt
, std::nullopt
,
96 CodeGenOptLevel::Default
));
97 AArch64Subtarget
ST(TM
->getTargetTriple(), TM
->getTargetCPU(),
98 TM
->getTargetCPU(), TM
->getTargetFeatureString(), *TM
,
101 auto *TLI
= ST
.getTargetLowering();
103 for (const auto &Test
: Tests
) {
104 ASSERT_EQ(TLI
->isLegalAddScalableImmediate(Test
.Imm
), Test
.Result
);