blob: 9a2533159bedaf542ba075c62013215360433eb1 [file] [log] [blame]
Matt Arsenault52133812019-01-22 21:31:02 +00001//===- MachineIRBuilderTest.cpp -------------------------------------------===//
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 "GISelMITest.h"
10#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
11
12TEST_F(GISelMITest, TestBuildConstantFConstant) {
13 if (!TM)
14 return;
15
Matt Arsenault52133812019-01-22 21:31:02 +000016 B.buildConstant(LLT::scalar(32), 42);
17 B.buildFConstant(LLT::scalar(32), 1.0);
18
19 B.buildConstant(LLT::vector(2, 32), 99);
20 B.buildFConstant(LLT::vector(2, 32), 2.0);
21
22 auto CheckStr = R"(
23 CHECK: [[CONST0:%[0-9]+]]:_(s32) = G_CONSTANT i32 42
24 CHECK: [[FCONST0:%[0-9]+]]:_(s32) = G_FCONSTANT float 1.000000e+00
25 CHECK: [[CONST1:%[0-9]+]]:_(s32) = G_CONSTANT i32 99
26 CHECK: [[VEC0:%[0-9]+]]:_(<2 x s32>) = G_BUILD_VECTOR [[CONST1]]:_(s32), [[CONST1]]:_(s32)
Matt Arsenault8121ec22019-02-04 19:15:50 +000027 CHECK: [[FCONST1:%[0-9]+]]:_(s32) = G_FCONSTANT float 2.000000e+00
Matt Arsenault52133812019-01-22 21:31:02 +000028 CHECK: [[VEC1:%[0-9]+]]:_(<2 x s32>) = G_BUILD_VECTOR [[FCONST1]]:_(s32), [[FCONST1]]:_(s32)
Matt Arsenault52133812019-01-22 21:31:02 +000029 )";
30
Matt Arsenaultb3e86702019-02-04 18:58:27 +000031 EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
Matt Arsenault52133812019-01-22 21:31:02 +000032}
Matt Arsenault8121ec22019-02-04 19:15:50 +000033
34
35#ifdef GTEST_HAS_DEATH_TEST
36#ifndef NDEBUG
37
38TEST_F(GISelMITest, TestBuildConstantFConstantDeath) {
39 if (!TM)
40 return;
41
42 LLVMContext &Ctx = MF->getFunction().getContext();
43 APInt APV32(32, 12345);
44
45 // Test APInt version breaks
46 EXPECT_DEATH(B.buildConstant(LLT::scalar(16), APV32),
47 "creating constant with the wrong size");
48 EXPECT_DEATH(B.buildConstant(LLT::vector(2, 16), APV32),
49 "creating constant with the wrong size");
50
51 // Test ConstantInt version breaks
52 ConstantInt *CI = ConstantInt::get(Ctx, APV32);
53 EXPECT_DEATH(B.buildConstant(LLT::scalar(16), *CI),
54 "creating constant with the wrong size");
55 EXPECT_DEATH(B.buildConstant(LLT::vector(2, 16), *CI),
56 "creating constant with the wrong size");
57
58 APFloat DoubleVal(APFloat::IEEEdouble());
59 ConstantFP *CF = ConstantFP::get(Ctx, DoubleVal);
60 EXPECT_DEATH(B.buildFConstant(LLT::scalar(16), *CF),
61 "creating fconstant with the wrong size");
62 EXPECT_DEATH(B.buildFConstant(LLT::vector(2, 16), *CF),
63 "creating fconstant with the wrong size");
64}
65
66#endif
67#endif