[Clang][MIPS] Send correct architecture for MinGW toolchains (#121042)
[llvm-project.git] / llvm / unittests / Target / AArch64 / DecomposeStackOffsetTest.cpp
blobbe6985e0a285375f4353501442601de94d61fb53
1 //===- TestStackOffset.cpp - StackOffset unit 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 //===----------------------------------------------------------------------===//
9 #include "llvm/Support/TypeSize.h"
10 #include "AArch64InstrInfo.h"
11 #include "gtest/gtest.h"
13 using namespace llvm;
15 TEST(StackOffset, decomposeStackOffsetForFrameOffsets) {
16 StackOffset A = StackOffset::getFixed(8);
17 StackOffset B = StackOffset::getFixed(4);
18 StackOffset C = StackOffset::getScalable(16);
20 // If all offsets can be materialized with only ADDVL,
21 // make sure PLSized is 0.
22 int64_t ByteSized, VLSized, PLSized;
23 AArch64InstrInfo::decomposeStackOffsetForFrameOffsets(A + B + C, ByteSized, PLSized,
24 VLSized);
25 EXPECT_EQ(12, ByteSized);
26 EXPECT_EQ(1, VLSized);
27 EXPECT_EQ(0, PLSized);
29 // If we need an ADDPL to materialize the offset, and the number of scalable
30 // bytes fits the ADDPL immediate, fold the scalable bytes to fit in PLSized.
31 StackOffset D = StackOffset::getScalable(2);
32 AArch64InstrInfo::decomposeStackOffsetForFrameOffsets(C + D, ByteSized, PLSized, VLSized);
33 EXPECT_EQ(0, ByteSized);
34 EXPECT_EQ(0, VLSized);
35 EXPECT_EQ(9, PLSized);
37 StackOffset E = StackOffset::getScalable(64);
38 StackOffset F = StackOffset::getScalable(2);
39 AArch64InstrInfo::decomposeStackOffsetForFrameOffsets(E + F, ByteSized, PLSized, VLSized);
40 EXPECT_EQ(0, ByteSized);
41 EXPECT_EQ(0, VLSized);
42 EXPECT_EQ(33, PLSized);
44 // If the offset requires an ADDPL instruction to materialize, and would
45 // require more than two instructions, decompose it into both
46 // ADDVL (n x 16 bytes) and ADDPL (n x 2 bytes) instructions.
47 StackOffset G = StackOffset::getScalable(128);
48 StackOffset H = StackOffset::getScalable(2);
49 AArch64InstrInfo::decomposeStackOffsetForFrameOffsets(G + H, ByteSized, PLSized, VLSized);
50 EXPECT_EQ(0, ByteSized);
51 EXPECT_EQ(8, VLSized);
52 EXPECT_EQ(1, PLSized);