From e6d677ada82fa4a76a6127ce248685b70c88c473 Mon Sep 17 00:00:00 2001 From: Matt Arsenault Date: Thu, 16 May 2019 12:23:04 +0000 Subject: [PATCH] GlobalISel: Add buildXor/buildNot git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@360880 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../CodeGen/GlobalISel/MachineIRBuilder.h | 14 ++++++++++ .../GlobalISel/MachineIRBuilderTest.cpp | 28 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h b/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h index f7247b31e2c..f14d9d6e47f 100644 --- a/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h +++ b/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h @@ -1242,6 +1242,20 @@ public: return buildInstr(TargetOpcode::G_OR, {Dst}, {Src0, Src1}); } + /// Build and insert \p Res = G_XOR \p Op0, \p Op1 + MachineInstrBuilder buildXor(const DstOp &Dst, const SrcOp &Src0, + const SrcOp &Src1) { + return buildInstr(TargetOpcode::G_XOR, {Dst}, {Src0, Src1}); + } + + /// Build and insert a bitwise not, + /// \p NegOne = G_CONSTANT -1 + /// \p Res = G_OR \p Op0, NegOne + MachineInstrBuilder buildNot(const DstOp &Dst, const SrcOp &Src0) { + auto NegOne = buildConstant(Dst.getLLTTy(*getMRI()), -1); + return buildInstr(TargetOpcode::G_XOR, {Dst}, {Src0, NegOne}); + } + /// Build and insert \p Res = G_FADD \p Op0, \p Op1 MachineInstrBuilder buildFAdd(const DstOp &Dst, const SrcOp &Src0, const SrcOp &Src1) { diff --git a/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp b/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp index 6d2ddcb35d5..c64aebcd309 100644 --- a/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp +++ b/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp @@ -171,3 +171,31 @@ TEST_F(GISelMITest, BuildIntrinsic) { EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF; } + +TEST_F(GISelMITest, BuildXor) { + if (!TM) + return; + + LLT S64 = LLT::scalar(64); + LLT S128 = LLT::scalar(128); + SmallVector Copies; + collectCopies(Copies, MF); + B.buildXor(S64, Copies[0], Copies[1]); + B.buildNot(S64, Copies[0]); + + // Make sure this works with > 64-bit types + auto Merge = B.buildMerge(S128, {Copies[0], Copies[1]}); + B.buildNot(S128, Merge); + auto CheckStr = R"( + ; CHECK: [[COPY0:%[0-9]+]]:_(s64) = COPY $x0 + ; CHECK: [[COPY1:%[0-9]+]]:_(s64) = COPY $x1 + ; CHECK: [[XOR0:%[0-9]+]]:_(s64) = G_XOR [[COPY0]]:_, [[COPY1]]:_ + ; CHECK: [[NEGONE64:%[0-9]+]]:_(s64) = G_CONSTANT i64 -1 + ; CHECK: [[XOR1:%[0-9]+]]:_(s64) = G_XOR [[COPY0]]:_, [[NEGONE64]]:_ + ; CHECK: [[MERGE:%[0-9]+]]:_(s128) = G_MERGE_VALUES [[COPY0]]:_(s64), [[COPY1]]:_(s64) + ; CHECK: [[NEGONE128:%[0-9]+]]:_(s128) = G_CONSTANT i128 -1 + ; CHECK: [[XOR2:%[0-9]+]]:_(s128) = G_XOR [[MERGE]]:_, [[NEGONE128]]:_ + )"; + + EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF; +} -- 2.40.0