[InstCombine] Signed saturation patterns
[llvm-complete.git] / unittests / IR / DataLayoutTest.cpp
blobde8ac253c45cf7d06b59d7b51c53e939611883e2
1 //===- ConstantRangeTest.cpp - ConstantRange 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/IR/DataLayout.h"
10 #include "llvm/IR/LLVMContext.h"
11 #include "llvm/IR/Type.h"
12 #include "gtest/gtest.h"
14 using namespace llvm;
16 namespace {
18 TEST(DataLayoutTest, FunctionPtrAlign) {
19 EXPECT_EQ(MaybeAlign(0), DataLayout("").getFunctionPtrAlign());
20 EXPECT_EQ(MaybeAlign(1), DataLayout("Fi8").getFunctionPtrAlign());
21 EXPECT_EQ(MaybeAlign(2), DataLayout("Fi16").getFunctionPtrAlign());
22 EXPECT_EQ(MaybeAlign(4), DataLayout("Fi32").getFunctionPtrAlign());
23 EXPECT_EQ(MaybeAlign(8), DataLayout("Fi64").getFunctionPtrAlign());
24 EXPECT_EQ(MaybeAlign(1), DataLayout("Fn8").getFunctionPtrAlign());
25 EXPECT_EQ(MaybeAlign(2), DataLayout("Fn16").getFunctionPtrAlign());
26 EXPECT_EQ(MaybeAlign(4), DataLayout("Fn32").getFunctionPtrAlign());
27 EXPECT_EQ(MaybeAlign(8), DataLayout("Fn64").getFunctionPtrAlign());
28 EXPECT_EQ(DataLayout::FunctionPtrAlignType::Independent, \
29 DataLayout("").getFunctionPtrAlignType());
30 EXPECT_EQ(DataLayout::FunctionPtrAlignType::Independent, \
31 DataLayout("Fi8").getFunctionPtrAlignType());
32 EXPECT_EQ(DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign, \
33 DataLayout("Fn8").getFunctionPtrAlignType());
34 EXPECT_EQ(DataLayout("Fi8"), DataLayout("Fi8"));
35 EXPECT_NE(DataLayout("Fi8"), DataLayout("Fi16"));
36 EXPECT_NE(DataLayout("Fi8"), DataLayout("Fn8"));
38 DataLayout a(""), b("Fi8"), c("Fn8");
39 EXPECT_NE(a, b);
40 EXPECT_NE(a, c);
41 EXPECT_NE(b, c);
43 a = b;
44 EXPECT_EQ(a, b);
45 a = c;
46 EXPECT_EQ(a, c);
49 TEST(DataLayoutTest, ValueOrABITypeAlignment) {
50 const DataLayout DL("Fi8");
51 LLVMContext Context;
52 Type *const FourByteAlignType = Type::getInt32Ty(Context);
53 EXPECT_EQ(Align(16),
54 DL.getValueOrABITypeAlignment(MaybeAlign(16), FourByteAlignType));
55 EXPECT_EQ(Align(4),
56 DL.getValueOrABITypeAlignment(MaybeAlign(), FourByteAlignType));
59 } // anonymous namespace