2016-11-11 08:27:37 +00:00
|
|
|
//===- ARMInstructionSelector.cpp ----------------------------*- C++ -*-==//
|
|
|
|
//
|
2019-01-19 08:50:56 +00:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2016-11-11 08:27:37 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \file
|
|
|
|
/// This file implements the targeting of the InstructionSelector class for ARM.
|
|
|
|
/// \todo This should be generated by TableGen.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "ARMRegisterBankInfo.h"
|
|
|
|
#include "ARMSubtarget.h"
|
|
|
|
#include "ARMTargetMachine.h"
|
2017-04-28 09:10:38 +00:00
|
|
|
#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
|
2017-10-26 23:39:54 +00:00
|
|
|
#include "llvm/CodeGen/GlobalISel/InstructionSelectorImpl.h"
|
2017-08-03 09:14:59 +00:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
2016-12-16 12:54:46 +00:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2016-11-11 08:27:37 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "arm-isel"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2017-04-28 09:10:38 +00:00
|
|
|
namespace {
|
2017-05-02 09:40:49 +00:00
|
|
|
|
|
|
|
#define GET_GLOBALISEL_PREDICATE_BITSET
|
|
|
|
#include "ARMGenGlobalISel.inc"
|
|
|
|
#undef GET_GLOBALISEL_PREDICATE_BITSET
|
|
|
|
|
2017-04-28 09:10:38 +00:00
|
|
|
class ARMInstructionSelector : public InstructionSelector {
|
|
|
|
public:
|
2017-05-02 09:40:49 +00:00
|
|
|
ARMInstructionSelector(const ARMBaseTargetMachine &TM, const ARMSubtarget &STI,
|
2017-04-28 09:10:38 +00:00
|
|
|
const ARMRegisterBankInfo &RBI);
|
|
|
|
|
[globalisel][tablegen] Generate rule coverage and use it to identify untested rules
Summary:
This patch adds a LLVM_ENABLE_GISEL_COV which, like LLVM_ENABLE_DAGISEL_COV,
causes TableGen to instrument the generated table to collect rule coverage
information. However, LLVM_ENABLE_GISEL_COV goes a bit further than
LLVM_ENABLE_DAGISEL_COV. The information is written to files
(${CMAKE_BINARY_DIR}/gisel-coverage-* by default). These files can then be
concatenated into ${LLVM_GISEL_COV_PREFIX}-all after which TableGen will
read this information and use it to emit warnings about untested rules.
This technique could also be used by SelectionDAG and can be further
extended to detect hot rules and give them priority over colder rules.
Usage:
* Enable LLVM_ENABLE_GISEL_COV in CMake
* Build the compiler and run some tests
* cat gisel-coverage-[0-9]* > gisel-coverage-all
* Delete lib/Target/*/*GenGlobalISel.inc*
* Build the compiler
Known issues:
* ${LLVM_GISEL_COV_PREFIX}-all must be generated as a manual
step due to a lack of a portable 'cat' command. It should be the
concatenation of all ${LLVM_GISEL_COV_PREFIX}-[0-9]* files.
* There's no mechanism to discard coverage information when the ruleset
changes
Depends on D39742
Reviewers: ab, qcolombet, t.p.northover, aditya_nandakumar, rovka
Reviewed By: rovka
Subscribers: vsk, arsenm, nhaehnle, mgorny, kristof.beyls, javed.absar, igorb, llvm-commits
Differential Revision: https://reviews.llvm.org/D39747
llvm-svn: 318356
2017-11-16 00:46:35 +00:00
|
|
|
bool select(MachineInstr &I, CodeGenCoverage &CoverageInfo) const override;
|
2017-10-26 23:39:54 +00:00
|
|
|
static const char *getName() { return DEBUG_TYPE; }
|
2017-04-28 09:10:38 +00:00
|
|
|
|
|
|
|
private:
|
[globalisel][tablegen] Generate rule coverage and use it to identify untested rules
Summary:
This patch adds a LLVM_ENABLE_GISEL_COV which, like LLVM_ENABLE_DAGISEL_COV,
causes TableGen to instrument the generated table to collect rule coverage
information. However, LLVM_ENABLE_GISEL_COV goes a bit further than
LLVM_ENABLE_DAGISEL_COV. The information is written to files
(${CMAKE_BINARY_DIR}/gisel-coverage-* by default). These files can then be
concatenated into ${LLVM_GISEL_COV_PREFIX}-all after which TableGen will
read this information and use it to emit warnings about untested rules.
This technique could also be used by SelectionDAG and can be further
extended to detect hot rules and give them priority over colder rules.
Usage:
* Enable LLVM_ENABLE_GISEL_COV in CMake
* Build the compiler and run some tests
* cat gisel-coverage-[0-9]* > gisel-coverage-all
* Delete lib/Target/*/*GenGlobalISel.inc*
* Build the compiler
Known issues:
* ${LLVM_GISEL_COV_PREFIX}-all must be generated as a manual
step due to a lack of a portable 'cat' command. It should be the
concatenation of all ${LLVM_GISEL_COV_PREFIX}-[0-9]* files.
* There's no mechanism to discard coverage information when the ruleset
changes
Depends on D39742
Reviewers: ab, qcolombet, t.p.northover, aditya_nandakumar, rovka
Reviewed By: rovka
Subscribers: vsk, arsenm, nhaehnle, mgorny, kristof.beyls, javed.absar, igorb, llvm-commits
Differential Revision: https://reviews.llvm.org/D39747
llvm-svn: 318356
2017-11-16 00:46:35 +00:00
|
|
|
bool selectImpl(MachineInstr &I, CodeGenCoverage &CoverageInfo) const;
|
2017-05-02 09:40:49 +00:00
|
|
|
|
2017-07-12 10:31:16 +00:00
|
|
|
struct CmpConstants;
|
|
|
|
struct InsertInfo;
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
|
2017-07-12 10:31:16 +00:00
|
|
|
bool selectCmp(CmpConstants Helper, MachineInstrBuilder &MIB,
|
|
|
|
MachineRegisterInfo &MRI) const;
|
2017-06-19 09:40:51 +00:00
|
|
|
|
2017-07-12 10:31:16 +00:00
|
|
|
// Helper for inserting a comparison sequence that sets \p ResReg to either 1
|
|
|
|
// if \p LHSReg and \p RHSReg are in the relationship defined by \p Cond, or
|
|
|
|
// \p PrevRes otherwise. In essence, it computes PrevRes OR (LHS Cond RHS).
|
|
|
|
bool insertComparison(CmpConstants Helper, InsertInfo I, unsigned ResReg,
|
|
|
|
ARMCC::CondCodes Cond, unsigned LHSReg, unsigned RHSReg,
|
|
|
|
unsigned PrevRes) const;
|
|
|
|
|
|
|
|
// Set \p DestReg to \p Constant.
|
|
|
|
void putConstant(InsertInfo I, unsigned DestReg, unsigned Constant) const;
|
|
|
|
|
2017-08-03 09:14:59 +00:00
|
|
|
bool selectGlobal(MachineInstrBuilder &MIB, MachineRegisterInfo &MRI) const;
|
2017-07-12 10:31:16 +00:00
|
|
|
bool selectSelect(MachineInstrBuilder &MIB, MachineRegisterInfo &MRI) const;
|
2017-10-06 15:39:16 +00:00
|
|
|
bool selectShift(unsigned ShiftOpc, MachineInstrBuilder &MIB) const;
|
2017-07-12 10:31:16 +00:00
|
|
|
|
|
|
|
// Check if the types match and both operands have the expected size and
|
|
|
|
// register bank.
|
|
|
|
bool validOpRegPair(MachineRegisterInfo &MRI, unsigned LHS, unsigned RHS,
|
|
|
|
unsigned ExpectedSize, unsigned ExpectedRegBankID) const;
|
|
|
|
|
|
|
|
// Check if the register has the expected size and register bank.
|
|
|
|
bool validReg(MachineRegisterInfo &MRI, unsigned Reg, unsigned ExpectedSize,
|
|
|
|
unsigned ExpectedRegBankID) const;
|
2017-06-27 09:19:51 +00:00
|
|
|
|
2017-04-28 09:10:38 +00:00
|
|
|
const ARMBaseInstrInfo &TII;
|
|
|
|
const ARMBaseRegisterInfo &TRI;
|
2017-05-02 09:40:49 +00:00
|
|
|
const ARMBaseTargetMachine &TM;
|
2017-04-28 09:10:38 +00:00
|
|
|
const ARMRegisterBankInfo &RBI;
|
2017-05-02 09:40:49 +00:00
|
|
|
const ARMSubtarget &STI;
|
|
|
|
|
2019-02-28 11:13:05 +00:00
|
|
|
// FIXME: This is necessary because DAGISel uses "Subtarget->" and GlobalISel
|
|
|
|
// uses "STI." in the code generated by TableGen. If we want to reuse some of
|
|
|
|
// the custom C++ predicates written for DAGISel, we need to have both around.
|
|
|
|
const ARMSubtarget *Subtarget = &STI;
|
|
|
|
|
2018-12-14 12:37:24 +00:00
|
|
|
// Store the opcodes that we might need, so we don't have to check what kind
|
|
|
|
// of subtarget (ARM vs Thumb) we have all the time.
|
|
|
|
struct OpcodeCache {
|
|
|
|
unsigned ZEXT16;
|
|
|
|
unsigned SEXT16;
|
|
|
|
|
|
|
|
unsigned ZEXT8;
|
|
|
|
unsigned SEXT8;
|
|
|
|
|
|
|
|
// Used for implementing ZEXT/SEXT from i1
|
|
|
|
unsigned AND;
|
|
|
|
unsigned RSB;
|
|
|
|
|
|
|
|
unsigned STORE32;
|
|
|
|
unsigned LOAD32;
|
|
|
|
|
|
|
|
unsigned STORE16;
|
|
|
|
unsigned LOAD16;
|
|
|
|
|
|
|
|
unsigned STORE8;
|
|
|
|
unsigned LOAD8;
|
|
|
|
|
2019-02-15 10:50:02 +00:00
|
|
|
unsigned ADDrr;
|
2019-02-21 13:00:02 +00:00
|
|
|
unsigned ADDri;
|
2019-02-15 10:50:02 +00:00
|
|
|
|
2019-02-13 11:25:32 +00:00
|
|
|
// Used for G_ICMP
|
2019-02-07 11:05:33 +00:00
|
|
|
unsigned CMPrr;
|
|
|
|
unsigned MOVi;
|
|
|
|
unsigned MOVCCi;
|
|
|
|
|
2019-02-13 11:25:32 +00:00
|
|
|
// Used for G_SELECT
|
|
|
|
unsigned MOVCCr;
|
|
|
|
|
2019-02-15 10:24:03 +00:00
|
|
|
unsigned TSTri;
|
|
|
|
unsigned Bcc;
|
|
|
|
|
2019-02-28 10:42:47 +00:00
|
|
|
// Used for G_GLOBAL_VALUE
|
|
|
|
unsigned MOVi32imm;
|
|
|
|
unsigned ConstPoolLoad;
|
|
|
|
unsigned MOV_ga_pcrel;
|
|
|
|
unsigned LDRLIT_ga_pcrel;
|
|
|
|
unsigned LDRLIT_ga_abs;
|
|
|
|
|
2018-12-14 12:37:24 +00:00
|
|
|
OpcodeCache(const ARMSubtarget &STI);
|
|
|
|
} const Opcodes;
|
|
|
|
|
|
|
|
// Select the opcode for simple extensions (that translate to a single SXT/UXT
|
|
|
|
// instruction). Extension operations more complicated than that should not
|
|
|
|
// invoke this. Returns the original opcode if it doesn't know how to select a
|
|
|
|
// better one.
|
|
|
|
unsigned selectSimpleExtOpc(unsigned Opc, unsigned Size) const;
|
|
|
|
|
|
|
|
// Select the opcode for simple loads and stores. Returns the original opcode
|
|
|
|
// if it doesn't know how to select a better one.
|
|
|
|
unsigned selectLoadStoreOpCode(unsigned Opc, unsigned RegBank,
|
|
|
|
unsigned Size) const;
|
|
|
|
|
2019-04-10 09:14:32 +00:00
|
|
|
void renderVFPF32Imm(MachineInstrBuilder &New, const MachineInstr &Old) const;
|
|
|
|
void renderVFPF64Imm(MachineInstrBuilder &New, const MachineInstr &Old) const;
|
|
|
|
|
2017-05-02 09:40:49 +00:00
|
|
|
#define GET_GLOBALISEL_PREDICATES_DECL
|
|
|
|
#include "ARMGenGlobalISel.inc"
|
|
|
|
#undef GET_GLOBALISEL_PREDICATES_DECL
|
|
|
|
|
|
|
|
// We declare the temporaries used by selectImpl() in the class to minimize the
|
|
|
|
// cost of constructing placeholder values.
|
|
|
|
#define GET_GLOBALISEL_TEMPORARIES_DECL
|
|
|
|
#include "ARMGenGlobalISel.inc"
|
|
|
|
#undef GET_GLOBALISEL_TEMPORARIES_DECL
|
2017-04-28 09:10:38 +00:00
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
InstructionSelector *
|
2017-05-02 09:40:49 +00:00
|
|
|
createARMInstructionSelector(const ARMBaseTargetMachine &TM,
|
|
|
|
const ARMSubtarget &STI,
|
2017-04-28 09:10:38 +00:00
|
|
|
const ARMRegisterBankInfo &RBI) {
|
2017-05-02 09:40:49 +00:00
|
|
|
return new ARMInstructionSelector(TM, STI, RBI);
|
2017-04-28 09:10:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-27 11:03:45 +00:00
|
|
|
const unsigned zero_reg = 0;
|
2017-05-02 09:40:49 +00:00
|
|
|
|
|
|
|
#define GET_GLOBALISEL_IMPL
|
|
|
|
#include "ARMGenGlobalISel.inc"
|
|
|
|
#undef GET_GLOBALISEL_IMPL
|
|
|
|
|
|
|
|
ARMInstructionSelector::ARMInstructionSelector(const ARMBaseTargetMachine &TM,
|
|
|
|
const ARMSubtarget &STI,
|
2016-11-11 08:27:37 +00:00
|
|
|
const ARMRegisterBankInfo &RBI)
|
2016-11-15 16:42:10 +00:00
|
|
|
: InstructionSelector(), TII(*STI.getInstrInfo()),
|
2018-12-14 12:37:24 +00:00
|
|
|
TRI(*STI.getRegisterInfo()), TM(TM), RBI(RBI), STI(STI), Opcodes(STI),
|
2017-05-02 09:40:49 +00:00
|
|
|
#define GET_GLOBALISEL_PREDICATES_INIT
|
|
|
|
#include "ARMGenGlobalISel.inc"
|
|
|
|
#undef GET_GLOBALISEL_PREDICATES_INIT
|
|
|
|
#define GET_GLOBALISEL_TEMPORARIES_INIT
|
|
|
|
#include "ARMGenGlobalISel.inc"
|
|
|
|
#undef GET_GLOBALISEL_TEMPORARIES_INIT
|
|
|
|
{
|
|
|
|
}
|
2016-11-11 08:27:37 +00:00
|
|
|
|
2018-01-04 13:09:25 +00:00
|
|
|
static const TargetRegisterClass *guessRegClass(unsigned Reg,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
const TargetRegisterInfo &TRI,
|
|
|
|
const RegisterBankInfo &RBI) {
|
|
|
|
const RegisterBank *RegBank = RBI.getRegBank(Reg, MRI, TRI);
|
2016-12-16 12:54:46 +00:00
|
|
|
assert(RegBank && "Can't get reg bank for virtual register");
|
|
|
|
|
2018-01-04 13:09:25 +00:00
|
|
|
const unsigned Size = MRI.getType(Reg).getSizeInBits();
|
2017-02-08 13:23:04 +00:00
|
|
|
assert((RegBank->getID() == ARM::GPRRegBankID ||
|
|
|
|
RegBank->getID() == ARM::FPRRegBankID) &&
|
|
|
|
"Unsupported reg bank");
|
|
|
|
|
|
|
|
if (RegBank->getID() == ARM::FPRRegBankID) {
|
2018-01-04 13:09:25 +00:00
|
|
|
if (Size == 32)
|
|
|
|
return &ARM::SPRRegClass;
|
|
|
|
else if (Size == 64)
|
|
|
|
return &ARM::DPRRegClass;
|
2018-05-23 02:59:31 +00:00
|
|
|
else if (Size == 128)
|
|
|
|
return &ARM::QPRRegClass;
|
2017-02-16 12:19:52 +00:00
|
|
|
else
|
|
|
|
llvm_unreachable("Unsupported destination size");
|
2017-02-08 13:23:04 +00:00
|
|
|
}
|
|
|
|
|
2018-01-04 13:09:25 +00:00
|
|
|
return &ARM::GPRRegClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool selectCopy(MachineInstr &I, const TargetInstrInfo &TII,
|
|
|
|
MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI,
|
|
|
|
const RegisterBankInfo &RBI) {
|
|
|
|
unsigned DstReg = I.getOperand(0).getReg();
|
|
|
|
if (TargetRegisterInfo::isPhysicalRegister(DstReg))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
const TargetRegisterClass *RC = guessRegClass(DstReg, MRI, TRI, RBI);
|
|
|
|
|
2016-12-16 12:54:46 +00:00
|
|
|
// No need to constrain SrcReg. It will get constrained when
|
|
|
|
// we hit another of its uses or its defs.
|
|
|
|
// Copies do not have constraints.
|
|
|
|
if (!RBI.constrainGenericRegister(DstReg, *RC, MRI)) {
|
2018-05-14 12:53:11 +00:00
|
|
|
LLVM_DEBUG(dbgs() << "Failed to constrain " << TII.getName(I.getOpcode())
|
|
|
|
<< " operand\n");
|
2016-12-16 12:54:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-07 12:35:05 +00:00
|
|
|
static bool selectMergeValues(MachineInstrBuilder &MIB,
|
|
|
|
const ARMBaseInstrInfo &TII,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
const TargetRegisterInfo &TRI,
|
|
|
|
const RegisterBankInfo &RBI) {
|
[ARM] Replace fp-only-sp and d16 with fp64 and d32.
Those two subtarget features were awkward because their semantics are
reversed: each one indicates the _lack_ of support for something in
the architecture, rather than the presence. As a consequence, you
don't get the behavior you want if you combine two sets of feature
bits.
Each SubtargetFeature for an FP architecture version now comes in four
versions, one for each combination of those options. So you can still
say (for example) '+vfp2' in a feature string and it will mean what
it's always meant, but there's a new string '+vfp2d16sp' meaning the
version without those extra options.
A lot of this change is just mechanically replacing positive checks
for the old features with negative checks for the new ones. But one
more interesting change is that I've rearranged getFPUFeatures() so
that the main FPU feature is appended to the output list *before*
rather than after the features derived from the Restriction field, so
that -fp64 and -d32 can override defaults added by the main feature.
Reviewers: dmgreen, samparker, SjoerdMeijer
Subscribers: srhines, javed.absar, eraman, kristof.beyls, hiraditya, zzheng, Petar.Avramovic, cfe-commits, llvm-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D60691
llvm-svn: 361845
2019-05-28 16:13:20 +00:00
|
|
|
assert(TII.getSubtarget().hasVFP2Base() && "Can't select merge without VFP");
|
2017-06-07 12:35:05 +00:00
|
|
|
|
|
|
|
// We only support G_MERGE_VALUES as a way to stick together two scalar GPRs
|
2017-02-16 12:19:57 +00:00
|
|
|
// into one DPR.
|
|
|
|
unsigned VReg0 = MIB->getOperand(0).getReg();
|
|
|
|
(void)VReg0;
|
|
|
|
assert(MRI.getType(VReg0).getSizeInBits() == 64 &&
|
|
|
|
RBI.getRegBank(VReg0, MRI, TRI)->getID() == ARM::FPRRegBankID &&
|
2017-06-07 12:35:05 +00:00
|
|
|
"Unsupported operand for G_MERGE_VALUES");
|
2017-02-16 12:19:57 +00:00
|
|
|
unsigned VReg1 = MIB->getOperand(1).getReg();
|
|
|
|
(void)VReg1;
|
|
|
|
assert(MRI.getType(VReg1).getSizeInBits() == 32 &&
|
|
|
|
RBI.getRegBank(VReg1, MRI, TRI)->getID() == ARM::GPRRegBankID &&
|
2017-06-07 12:35:05 +00:00
|
|
|
"Unsupported operand for G_MERGE_VALUES");
|
|
|
|
unsigned VReg2 = MIB->getOperand(2).getReg();
|
2017-02-16 12:19:57 +00:00
|
|
|
(void)VReg2;
|
|
|
|
assert(MRI.getType(VReg2).getSizeInBits() == 32 &&
|
|
|
|
RBI.getRegBank(VReg2, MRI, TRI)->getID() == ARM::GPRRegBankID &&
|
2017-06-07 12:35:05 +00:00
|
|
|
"Unsupported operand for G_MERGE_VALUES");
|
2017-02-16 12:19:57 +00:00
|
|
|
|
|
|
|
MIB->setDesc(TII.get(ARM::VMOVDRR));
|
|
|
|
MIB.add(predOps(ARMCC::AL));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-07 12:35:05 +00:00
|
|
|
static bool selectUnmergeValues(MachineInstrBuilder &MIB,
|
|
|
|
const ARMBaseInstrInfo &TII,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
const TargetRegisterInfo &TRI,
|
|
|
|
const RegisterBankInfo &RBI) {
|
[ARM] Replace fp-only-sp and d16 with fp64 and d32.
Those two subtarget features were awkward because their semantics are
reversed: each one indicates the _lack_ of support for something in
the architecture, rather than the presence. As a consequence, you
don't get the behavior you want if you combine two sets of feature
bits.
Each SubtargetFeature for an FP architecture version now comes in four
versions, one for each combination of those options. So you can still
say (for example) '+vfp2' in a feature string and it will mean what
it's always meant, but there's a new string '+vfp2d16sp' meaning the
version without those extra options.
A lot of this change is just mechanically replacing positive checks
for the old features with negative checks for the new ones. But one
more interesting change is that I've rearranged getFPUFeatures() so
that the main FPU feature is appended to the output list *before*
rather than after the features derived from the Restriction field, so
that -fp64 and -d32 can override defaults added by the main feature.
Reviewers: dmgreen, samparker, SjoerdMeijer
Subscribers: srhines, javed.absar, eraman, kristof.beyls, hiraditya, zzheng, Petar.Avramovic, cfe-commits, llvm-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D60691
llvm-svn: 361845
2019-05-28 16:13:20 +00:00
|
|
|
assert(TII.getSubtarget().hasVFP2Base() &&
|
|
|
|
"Can't select unmerge without VFP");
|
2017-02-16 12:19:57 +00:00
|
|
|
|
2017-06-07 12:35:05 +00:00
|
|
|
// We only support G_UNMERGE_VALUES as a way to break up one DPR into two
|
|
|
|
// GPRs.
|
2017-02-16 12:19:57 +00:00
|
|
|
unsigned VReg0 = MIB->getOperand(0).getReg();
|
|
|
|
(void)VReg0;
|
|
|
|
assert(MRI.getType(VReg0).getSizeInBits() == 32 &&
|
|
|
|
RBI.getRegBank(VReg0, MRI, TRI)->getID() == ARM::GPRRegBankID &&
|
2017-06-07 12:35:05 +00:00
|
|
|
"Unsupported operand for G_UNMERGE_VALUES");
|
2017-02-16 12:19:57 +00:00
|
|
|
unsigned VReg1 = MIB->getOperand(1).getReg();
|
|
|
|
(void)VReg1;
|
2017-06-07 12:35:05 +00:00
|
|
|
assert(MRI.getType(VReg1).getSizeInBits() == 32 &&
|
|
|
|
RBI.getRegBank(VReg1, MRI, TRI)->getID() == ARM::GPRRegBankID &&
|
|
|
|
"Unsupported operand for G_UNMERGE_VALUES");
|
|
|
|
unsigned VReg2 = MIB->getOperand(2).getReg();
|
|
|
|
(void)VReg2;
|
|
|
|
assert(MRI.getType(VReg2).getSizeInBits() == 64 &&
|
|
|
|
RBI.getRegBank(VReg2, MRI, TRI)->getID() == ARM::FPRRegBankID &&
|
|
|
|
"Unsupported operand for G_UNMERGE_VALUES");
|
2017-02-16 12:19:57 +00:00
|
|
|
|
2017-06-07 12:35:05 +00:00
|
|
|
MIB->setDesc(TII.get(ARM::VMOVRRD));
|
2017-02-16 12:19:57 +00:00
|
|
|
MIB.add(predOps(ARMCC::AL));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-12-14 12:37:24 +00:00
|
|
|
ARMInstructionSelector::OpcodeCache::OpcodeCache(const ARMSubtarget &STI) {
|
|
|
|
bool isThumb = STI.isThumb();
|
|
|
|
|
|
|
|
using namespace TargetOpcode;
|
|
|
|
|
|
|
|
#define STORE_OPCODE(VAR, OPC) VAR = isThumb ? ARM::t2##OPC : ARM::OPC
|
|
|
|
STORE_OPCODE(SEXT16, SXTH);
|
|
|
|
STORE_OPCODE(ZEXT16, UXTH);
|
|
|
|
|
|
|
|
STORE_OPCODE(SEXT8, SXTB);
|
|
|
|
STORE_OPCODE(ZEXT8, UXTB);
|
|
|
|
|
|
|
|
STORE_OPCODE(AND, ANDri);
|
|
|
|
STORE_OPCODE(RSB, RSBri);
|
|
|
|
|
|
|
|
STORE_OPCODE(STORE32, STRi12);
|
|
|
|
STORE_OPCODE(LOAD32, LDRi12);
|
|
|
|
|
|
|
|
// LDRH/STRH are special...
|
|
|
|
STORE16 = isThumb ? ARM::t2STRHi12 : ARM::STRH;
|
|
|
|
LOAD16 = isThumb ? ARM::t2LDRHi12 : ARM::LDRH;
|
|
|
|
|
|
|
|
STORE_OPCODE(STORE8, STRBi12);
|
|
|
|
STORE_OPCODE(LOAD8, LDRBi12);
|
2019-02-07 11:05:33 +00:00
|
|
|
|
2019-02-15 10:50:02 +00:00
|
|
|
STORE_OPCODE(ADDrr, ADDrr);
|
2019-02-21 13:00:02 +00:00
|
|
|
STORE_OPCODE(ADDri, ADDri);
|
2019-02-15 10:50:02 +00:00
|
|
|
|
2019-02-07 11:05:33 +00:00
|
|
|
STORE_OPCODE(CMPrr, CMPrr);
|
|
|
|
STORE_OPCODE(MOVi, MOVi);
|
|
|
|
STORE_OPCODE(MOVCCi, MOVCCi);
|
2019-02-13 11:25:32 +00:00
|
|
|
|
|
|
|
STORE_OPCODE(MOVCCr, MOVCCr);
|
2019-02-15 10:24:03 +00:00
|
|
|
|
|
|
|
STORE_OPCODE(TSTri, TSTri);
|
|
|
|
STORE_OPCODE(Bcc, Bcc);
|
2019-02-28 10:42:47 +00:00
|
|
|
|
|
|
|
STORE_OPCODE(MOVi32imm, MOVi32imm);
|
|
|
|
ConstPoolLoad = isThumb ? ARM::t2LDRpci : ARM::LDRi12;
|
|
|
|
STORE_OPCODE(MOV_ga_pcrel, MOV_ga_pcrel);
|
|
|
|
LDRLIT_ga_pcrel = isThumb ? ARM::tLDRLIT_ga_pcrel : ARM::LDRLIT_ga_pcrel;
|
|
|
|
LDRLIT_ga_abs = isThumb ? ARM::tLDRLIT_ga_abs : ARM::LDRLIT_ga_abs;
|
2018-12-14 12:37:24 +00:00
|
|
|
#undef MAP_OPCODE
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned ARMInstructionSelector::selectSimpleExtOpc(unsigned Opc,
|
|
|
|
unsigned Size) const {
|
2017-01-25 08:10:40 +00:00
|
|
|
using namespace TargetOpcode;
|
|
|
|
|
2017-02-17 13:44:19 +00:00
|
|
|
if (Size != 8 && Size != 16)
|
|
|
|
return Opc;
|
2017-01-25 08:10:40 +00:00
|
|
|
|
|
|
|
if (Opc == G_SEXT)
|
2018-12-14 12:37:24 +00:00
|
|
|
return Size == 8 ? Opcodes.SEXT8 : Opcodes.SEXT16;
|
2017-01-25 08:10:40 +00:00
|
|
|
|
|
|
|
if (Opc == G_ZEXT)
|
2018-12-14 12:37:24 +00:00
|
|
|
return Size == 8 ? Opcodes.ZEXT8 : Opcodes.ZEXT16;
|
2017-01-25 08:10:40 +00:00
|
|
|
|
2017-02-17 13:44:19 +00:00
|
|
|
return Opc;
|
2017-01-25 08:10:40 +00:00
|
|
|
}
|
|
|
|
|
2018-12-14 12:37:24 +00:00
|
|
|
unsigned ARMInstructionSelector::selectLoadStoreOpCode(unsigned Opc,
|
|
|
|
unsigned RegBank,
|
|
|
|
unsigned Size) const {
|
2017-02-24 14:01:27 +00:00
|
|
|
bool isStore = Opc == TargetOpcode::G_STORE;
|
|
|
|
|
2017-02-16 14:10:50 +00:00
|
|
|
if (RegBank == ARM::GPRRegBankID) {
|
|
|
|
switch (Size) {
|
|
|
|
case 1:
|
|
|
|
case 8:
|
2018-12-14 12:37:24 +00:00
|
|
|
return isStore ? Opcodes.STORE8 : Opcodes.LOAD8;
|
2017-02-16 14:10:50 +00:00
|
|
|
case 16:
|
2018-12-14 12:37:24 +00:00
|
|
|
return isStore ? Opcodes.STORE16 : Opcodes.LOAD16;
|
2017-02-16 14:10:50 +00:00
|
|
|
case 32:
|
2018-12-14 12:37:24 +00:00
|
|
|
return isStore ? Opcodes.STORE32 : Opcodes.LOAD32;
|
2017-02-17 13:44:19 +00:00
|
|
|
default:
|
2017-02-24 14:01:27 +00:00
|
|
|
return Opc;
|
2017-02-16 14:10:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-17 13:44:19 +00:00
|
|
|
if (RegBank == ARM::FPRRegBankID) {
|
|
|
|
switch (Size) {
|
|
|
|
case 32:
|
2017-02-24 14:01:27 +00:00
|
|
|
return isStore ? ARM::VSTRS : ARM::VLDRS;
|
2017-02-17 13:44:19 +00:00
|
|
|
case 64:
|
2017-02-24 14:01:27 +00:00
|
|
|
return isStore ? ARM::VSTRD : ARM::VLDRD;
|
2017-02-17 13:44:19 +00:00
|
|
|
default:
|
2017-02-24 14:01:27 +00:00
|
|
|
return Opc;
|
2017-02-17 13:44:19 +00:00
|
|
|
}
|
2017-01-26 09:20:47 +00:00
|
|
|
}
|
|
|
|
|
2017-02-24 14:01:27 +00:00
|
|
|
return Opc;
|
2017-01-26 09:20:47 +00:00
|
|
|
}
|
|
|
|
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
// When lowering comparisons, we sometimes need to perform two compares instead
|
|
|
|
// of just one. Get the condition codes for both comparisons. If only one is
|
|
|
|
// needed, the second member of the pair is ARMCC::AL.
|
|
|
|
static std::pair<ARMCC::CondCodes, ARMCC::CondCodes>
|
|
|
|
getComparePreds(CmpInst::Predicate Pred) {
|
|
|
|
std::pair<ARMCC::CondCodes, ARMCC::CondCodes> Preds = {ARMCC::AL, ARMCC::AL};
|
2017-06-19 09:40:51 +00:00
|
|
|
switch (Pred) {
|
|
|
|
case CmpInst::FCMP_ONE:
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
Preds = {ARMCC::GT, ARMCC::MI};
|
|
|
|
break;
|
2017-06-19 09:40:51 +00:00
|
|
|
case CmpInst::FCMP_UEQ:
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
Preds = {ARMCC::EQ, ARMCC::VS};
|
|
|
|
break;
|
2017-06-19 09:40:51 +00:00
|
|
|
case CmpInst::ICMP_EQ:
|
|
|
|
case CmpInst::FCMP_OEQ:
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
Preds.first = ARMCC::EQ;
|
|
|
|
break;
|
2017-06-19 09:40:51 +00:00
|
|
|
case CmpInst::ICMP_SGT:
|
|
|
|
case CmpInst::FCMP_OGT:
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
Preds.first = ARMCC::GT;
|
|
|
|
break;
|
2017-06-19 09:40:51 +00:00
|
|
|
case CmpInst::ICMP_SGE:
|
|
|
|
case CmpInst::FCMP_OGE:
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
Preds.first = ARMCC::GE;
|
|
|
|
break;
|
2017-06-19 09:40:51 +00:00
|
|
|
case CmpInst::ICMP_UGT:
|
|
|
|
case CmpInst::FCMP_UGT:
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
Preds.first = ARMCC::HI;
|
|
|
|
break;
|
2017-06-19 09:40:51 +00:00
|
|
|
case CmpInst::FCMP_OLT:
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
Preds.first = ARMCC::MI;
|
|
|
|
break;
|
2017-06-19 09:40:51 +00:00
|
|
|
case CmpInst::ICMP_ULE:
|
|
|
|
case CmpInst::FCMP_OLE:
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
Preds.first = ARMCC::LS;
|
|
|
|
break;
|
2017-06-19 09:40:51 +00:00
|
|
|
case CmpInst::FCMP_ORD:
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
Preds.first = ARMCC::VC;
|
|
|
|
break;
|
2017-06-19 09:40:51 +00:00
|
|
|
case CmpInst::FCMP_UNO:
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
Preds.first = ARMCC::VS;
|
|
|
|
break;
|
2017-06-19 09:40:51 +00:00
|
|
|
case CmpInst::FCMP_UGE:
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
Preds.first = ARMCC::PL;
|
|
|
|
break;
|
2017-06-19 09:40:51 +00:00
|
|
|
case CmpInst::ICMP_SLT:
|
|
|
|
case CmpInst::FCMP_ULT:
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
Preds.first = ARMCC::LT;
|
|
|
|
break;
|
2017-06-19 09:40:51 +00:00
|
|
|
case CmpInst::ICMP_SLE:
|
|
|
|
case CmpInst::FCMP_ULE:
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
Preds.first = ARMCC::LE;
|
|
|
|
break;
|
2017-06-19 09:40:51 +00:00
|
|
|
case CmpInst::FCMP_UNE:
|
|
|
|
case CmpInst::ICMP_NE:
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
Preds.first = ARMCC::NE;
|
|
|
|
break;
|
2017-06-19 09:40:51 +00:00
|
|
|
case CmpInst::ICMP_UGE:
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
Preds.first = ARMCC::HS;
|
|
|
|
break;
|
2017-06-19 09:40:51 +00:00
|
|
|
case CmpInst::ICMP_ULT:
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
Preds.first = ARMCC::LO;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2017-06-19 09:40:51 +00:00
|
|
|
}
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
assert(Preds.first != ARMCC::AL && "No comparisons needed?");
|
|
|
|
return Preds;
|
2017-06-19 09:40:51 +00:00
|
|
|
}
|
|
|
|
|
2017-07-12 10:31:16 +00:00
|
|
|
struct ARMInstructionSelector::CmpConstants {
|
2019-02-07 11:05:33 +00:00
|
|
|
CmpConstants(unsigned CmpOpcode, unsigned FlagsOpcode, unsigned SelectOpcode,
|
|
|
|
unsigned OpRegBank, unsigned OpSize)
|
2017-07-12 10:31:16 +00:00
|
|
|
: ComparisonOpcode(CmpOpcode), ReadFlagsOpcode(FlagsOpcode),
|
2019-02-07 11:05:33 +00:00
|
|
|
SelectResultOpcode(SelectOpcode), OperandRegBankID(OpRegBank),
|
|
|
|
OperandSize(OpSize) {}
|
2017-06-19 09:40:51 +00:00
|
|
|
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
// The opcode used for performing the comparison.
|
2017-07-12 10:31:16 +00:00
|
|
|
const unsigned ComparisonOpcode;
|
2017-06-19 09:40:51 +00:00
|
|
|
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
// The opcode used for reading the flags set by the comparison. May be
|
|
|
|
// ARM::INSTRUCTION_LIST_END if we don't need to read the flags.
|
2017-07-12 10:31:16 +00:00
|
|
|
const unsigned ReadFlagsOpcode;
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
|
2019-02-07 11:05:33 +00:00
|
|
|
// The opcode used for materializing the result of the comparison.
|
|
|
|
const unsigned SelectResultOpcode;
|
|
|
|
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
// The assumed register bank ID for the operands.
|
2017-07-12 10:31:16 +00:00
|
|
|
const unsigned OperandRegBankID;
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
|
2017-07-12 09:01:54 +00:00
|
|
|
// The assumed size in bits for the operands.
|
2017-07-12 10:31:16 +00:00
|
|
|
const unsigned OperandSize;
|
|
|
|
};
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
|
2017-07-12 10:31:16 +00:00
|
|
|
struct ARMInstructionSelector::InsertInfo {
|
|
|
|
InsertInfo(MachineInstrBuilder &MIB)
|
|
|
|
: MBB(*MIB->getParent()), InsertBefore(std::next(MIB->getIterator())),
|
|
|
|
DbgLoc(MIB->getDebugLoc()) {}
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
|
2017-07-12 10:31:16 +00:00
|
|
|
MachineBasicBlock &MBB;
|
|
|
|
const MachineBasicBlock::instr_iterator InsertBefore;
|
|
|
|
const DebugLoc &DbgLoc;
|
|
|
|
};
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
|
2017-07-12 10:31:16 +00:00
|
|
|
void ARMInstructionSelector::putConstant(InsertInfo I, unsigned DestReg,
|
|
|
|
unsigned Constant) const {
|
2019-02-07 11:05:33 +00:00
|
|
|
(void)BuildMI(I.MBB, I.InsertBefore, I.DbgLoc, TII.get(Opcodes.MOVi))
|
2017-07-12 10:31:16 +00:00
|
|
|
.addDef(DestReg)
|
|
|
|
.addImm(Constant)
|
|
|
|
.add(predOps(ARMCC::AL))
|
|
|
|
.add(condCodeOp());
|
|
|
|
}
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
|
2017-07-12 10:31:16 +00:00
|
|
|
bool ARMInstructionSelector::validOpRegPair(MachineRegisterInfo &MRI,
|
|
|
|
unsigned LHSReg, unsigned RHSReg,
|
|
|
|
unsigned ExpectedSize,
|
|
|
|
unsigned ExpectedRegBankID) const {
|
|
|
|
return MRI.getType(LHSReg) == MRI.getType(RHSReg) &&
|
|
|
|
validReg(MRI, LHSReg, ExpectedSize, ExpectedRegBankID) &&
|
|
|
|
validReg(MRI, RHSReg, ExpectedSize, ExpectedRegBankID);
|
|
|
|
}
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
|
2017-07-12 10:31:16 +00:00
|
|
|
bool ARMInstructionSelector::validReg(MachineRegisterInfo &MRI, unsigned Reg,
|
|
|
|
unsigned ExpectedSize,
|
|
|
|
unsigned ExpectedRegBankID) const {
|
|
|
|
if (MRI.getType(Reg).getSizeInBits() != ExpectedSize) {
|
2018-05-14 12:53:11 +00:00
|
|
|
LLVM_DEBUG(dbgs() << "Unexpected size for register");
|
2017-07-12 10:31:16 +00:00
|
|
|
return false;
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
}
|
|
|
|
|
2017-07-12 10:31:16 +00:00
|
|
|
if (RBI.getRegBank(Reg, MRI, TRI)->getID() != ExpectedRegBankID) {
|
2018-05-14 12:53:11 +00:00
|
|
|
LLVM_DEBUG(dbgs() << "Unexpected register bank for register");
|
2017-07-12 10:31:16 +00:00
|
|
|
return false;
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
}
|
|
|
|
|
2017-07-12 10:31:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
|
2017-07-12 10:31:16 +00:00
|
|
|
bool ARMInstructionSelector::selectCmp(CmpConstants Helper,
|
|
|
|
MachineInstrBuilder &MIB,
|
|
|
|
MachineRegisterInfo &MRI) const {
|
|
|
|
const InsertInfo I(MIB);
|
2017-06-19 09:40:51 +00:00
|
|
|
|
|
|
|
auto ResReg = MIB->getOperand(0).getReg();
|
2017-07-12 10:31:16 +00:00
|
|
|
if (!validReg(MRI, ResReg, 1, ARM::GPRRegBankID))
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
return false;
|
|
|
|
|
2017-06-19 09:40:51 +00:00
|
|
|
auto Cond =
|
|
|
|
static_cast<CmpInst::Predicate>(MIB->getOperand(1).getPredicate());
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
if (Cond == CmpInst::FCMP_TRUE || Cond == CmpInst::FCMP_FALSE) {
|
2017-07-12 10:31:16 +00:00
|
|
|
putConstant(I, ResReg, Cond == CmpInst::FCMP_TRUE ? 1 : 0);
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
MIB->eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
2017-06-19 09:40:51 +00:00
|
|
|
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
auto LHSReg = MIB->getOperand(2).getReg();
|
|
|
|
auto RHSReg = MIB->getOperand(3).getReg();
|
2017-07-12 10:31:16 +00:00
|
|
|
if (!validOpRegPair(MRI, LHSReg, RHSReg, Helper.OperandSize,
|
|
|
|
Helper.OperandRegBankID))
|
2017-06-19 09:40:51 +00:00
|
|
|
return false;
|
|
|
|
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
auto ARMConds = getComparePreds(Cond);
|
2017-07-12 10:31:16 +00:00
|
|
|
auto ZeroReg = MRI.createVirtualRegister(&ARM::GPRRegClass);
|
|
|
|
putConstant(I, ZeroReg, 0);
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
|
|
|
|
if (ARMConds.second == ARMCC::AL) {
|
|
|
|
// Simple case, we only need one comparison and we're done.
|
2017-07-12 10:31:16 +00:00
|
|
|
if (!insertComparison(Helper, I, ResReg, ARMConds.first, LHSReg, RHSReg,
|
|
|
|
ZeroReg))
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
// Not so simple, we need two successive comparisons.
|
|
|
|
auto IntermediateRes = MRI.createVirtualRegister(&ARM::GPRRegClass);
|
2017-07-12 10:31:16 +00:00
|
|
|
if (!insertComparison(Helper, I, IntermediateRes, ARMConds.first, LHSReg,
|
|
|
|
RHSReg, ZeroReg))
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
return false;
|
2017-07-12 10:31:16 +00:00
|
|
|
if (!insertComparison(Helper, I, ResReg, ARMConds.second, LHSReg, RHSReg,
|
|
|
|
IntermediateRes))
|
[ARM] GlobalISel: Select hard G_FCMP for s32
We lower to a sequence consisting of:
- MOVi 0 into a register
- VCMPS to do the actual comparison and set the VFP flags
- FMSTAT to move the flags out of the VFP unit
- MOVCCi to either use the "zero register" that we have previously set
with the MOVi, or move 1 into the result register, based on the values
of the flags
As was the case with soft-float, for some predicates (one, ueq) we
actually need two comparisons instead of just one. When that happens, we
generate two VCMPS-FMSTAT-MOVCCi sequences and chain them by means of
using the result of the first MOVCCi as the "zero register" for the
second one. This is a bit overkill, since one comparison followed by
two non-flag-setting conditional moves should be enough. In any case,
the backend manages to CSE one of the comparisons away so it doesn't
matter much.
Note that unlike SelectionDAG and FastISel, we always use VCMPS, and not
VCMPES. This makes the code a lot simpler, and it also seems correct
since the LLVM Lang Ref defines simple true/false returns if the
operands are QNaN's. For SNaN's, even VCMPS throws an Invalid Operand
exception, so they won't be slipping through unnoticed.
Implementation-wise, this introduces a template so we can share the same
code that we use for handling integer comparisons, since the only
differences are in the details (exact opcodes to be used etc). Hopefully
this will be easy to extend to s64 G_FCMP.
llvm-svn: 307365
2017-07-07 08:39:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-06-19 09:40:51 +00:00
|
|
|
MIB->eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-12 10:31:16 +00:00
|
|
|
bool ARMInstructionSelector::insertComparison(CmpConstants Helper, InsertInfo I,
|
|
|
|
unsigned ResReg,
|
|
|
|
ARMCC::CondCodes Cond,
|
|
|
|
unsigned LHSReg, unsigned RHSReg,
|
|
|
|
unsigned PrevRes) const {
|
|
|
|
// Perform the comparison.
|
|
|
|
auto CmpI =
|
|
|
|
BuildMI(I.MBB, I.InsertBefore, I.DbgLoc, TII.get(Helper.ComparisonOpcode))
|
|
|
|
.addUse(LHSReg)
|
|
|
|
.addUse(RHSReg)
|
|
|
|
.add(predOps(ARMCC::AL));
|
|
|
|
if (!constrainSelectedInstRegOperands(*CmpI, TII, TRI, RBI))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Read the comparison flags (if necessary).
|
|
|
|
if (Helper.ReadFlagsOpcode != ARM::INSTRUCTION_LIST_END) {
|
|
|
|
auto ReadI = BuildMI(I.MBB, I.InsertBefore, I.DbgLoc,
|
|
|
|
TII.get(Helper.ReadFlagsOpcode))
|
|
|
|
.add(predOps(ARMCC::AL));
|
|
|
|
if (!constrainSelectedInstRegOperands(*ReadI, TII, TRI, RBI))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select either 1 or the previous result based on the value of the flags.
|
2019-02-07 11:05:33 +00:00
|
|
|
auto Mov1I = BuildMI(I.MBB, I.InsertBefore, I.DbgLoc,
|
|
|
|
TII.get(Helper.SelectResultOpcode))
|
2017-07-12 10:31:16 +00:00
|
|
|
.addDef(ResReg)
|
|
|
|
.addUse(PrevRes)
|
|
|
|
.addImm(1)
|
|
|
|
.add(predOps(Cond, ARM::CPSR));
|
|
|
|
if (!constrainSelectedInstRegOperands(*Mov1I, TII, TRI, RBI))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-03 09:14:59 +00:00
|
|
|
bool ARMInstructionSelector::selectGlobal(MachineInstrBuilder &MIB,
|
|
|
|
MachineRegisterInfo &MRI) const {
|
2017-09-05 07:57:41 +00:00
|
|
|
if ((STI.isROPI() || STI.isRWPI()) && !STI.isTargetELF()) {
|
2018-05-14 12:53:11 +00:00
|
|
|
LLVM_DEBUG(dbgs() << "ROPI and RWPI only supported for ELF\n");
|
2017-08-03 09:14:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto GV = MIB->getOperand(1).getGlobal();
|
|
|
|
if (GV->isThreadLocal()) {
|
2018-05-14 12:53:11 +00:00
|
|
|
LLVM_DEBUG(dbgs() << "TLS variables not supported yet\n");
|
2017-08-03 09:14:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &MBB = *MIB->getParent();
|
|
|
|
auto &MF = *MBB.getParent();
|
|
|
|
|
2019-02-08 07:57:42 +00:00
|
|
|
bool UseMovt = STI.useMovt();
|
2017-08-03 09:14:59 +00:00
|
|
|
|
2018-03-14 00:36:23 +00:00
|
|
|
unsigned Size = TM.getPointerSize(0);
|
2017-08-29 09:47:55 +00:00
|
|
|
unsigned Alignment = 4;
|
2017-09-05 07:57:41 +00:00
|
|
|
|
|
|
|
auto addOpsForConstantPoolLoad = [&MF, Alignment,
|
|
|
|
Size](MachineInstrBuilder &MIB,
|
|
|
|
const GlobalValue *GV, bool IsSBREL) {
|
2019-02-28 10:42:47 +00:00
|
|
|
assert((MIB->getOpcode() == ARM::LDRi12 ||
|
|
|
|
MIB->getOpcode() == ARM::t2LDRpci) &&
|
|
|
|
"Unsupported instruction");
|
2017-09-05 07:57:41 +00:00
|
|
|
auto ConstPool = MF.getConstantPool();
|
|
|
|
auto CPIndex =
|
|
|
|
// For SB relative entries we need a target-specific constant pool.
|
|
|
|
// Otherwise, just use a regular constant pool entry.
|
|
|
|
IsSBREL
|
|
|
|
? ConstPool->getConstantPoolIndex(
|
|
|
|
ARMConstantPoolConstant::Create(GV, ARMCP::SBREL), Alignment)
|
|
|
|
: ConstPool->getConstantPoolIndex(GV, Alignment);
|
|
|
|
MIB.addConstantPoolIndex(CPIndex, /*Offset*/ 0, /*TargetFlags*/ 0)
|
2019-02-28 10:42:47 +00:00
|
|
|
.addMemOperand(MF.getMachineMemOperand(
|
|
|
|
MachinePointerInfo::getConstantPool(MF), MachineMemOperand::MOLoad,
|
|
|
|
Size, Alignment));
|
|
|
|
if (MIB->getOpcode() == ARM::LDRi12)
|
|
|
|
MIB.addImm(0);
|
|
|
|
MIB.add(predOps(ARMCC::AL));
|
|
|
|
};
|
|
|
|
|
|
|
|
auto addGOTMemOperand = [this, &MF, Alignment](MachineInstrBuilder &MIB) {
|
|
|
|
MIB.addMemOperand(MF.getMachineMemOperand(
|
|
|
|
MachinePointerInfo::getGOT(MF), MachineMemOperand::MOLoad,
|
|
|
|
TM.getProgramPointerSize(), Alignment));
|
2017-09-05 07:57:41 +00:00
|
|
|
};
|
|
|
|
|
2017-08-29 09:47:55 +00:00
|
|
|
if (TM.isPositionIndependent()) {
|
2017-09-05 08:22:47 +00:00
|
|
|
bool Indirect = STI.isGVIndirectSymbol(GV);
|
2019-02-28 10:42:47 +00:00
|
|
|
|
|
|
|
// For ARM mode, we have different pseudoinstructions for direct accesses
|
|
|
|
// and indirect accesses, and the ones for indirect accesses include the
|
|
|
|
// load from GOT. For Thumb mode, we use the same pseudoinstruction for both
|
|
|
|
// direct and indirect accesses, and we need to manually generate the load
|
|
|
|
// from GOT.
|
|
|
|
bool UseOpcodeThatLoads = Indirect && !STI.isThumb();
|
|
|
|
|
2017-08-29 09:47:55 +00:00
|
|
|
// FIXME: Taking advantage of MOVT for ELF is pretty involved, so we don't
|
|
|
|
// support it yet. See PR28229.
|
2019-03-04 08:51:32 +00:00
|
|
|
unsigned Opc =
|
|
|
|
UseMovt && !STI.isTargetELF()
|
|
|
|
? (UseOpcodeThatLoads ? (unsigned)ARM::MOV_ga_pcrel_ldr
|
|
|
|
: Opcodes.MOV_ga_pcrel)
|
|
|
|
: (UseOpcodeThatLoads ? (unsigned)ARM::LDRLIT_ga_pcrel_ldr
|
|
|
|
: Opcodes.LDRLIT_ga_pcrel);
|
2017-08-29 09:47:55 +00:00
|
|
|
MIB->setDesc(TII.get(Opc));
|
|
|
|
|
2017-11-13 20:45:38 +00:00
|
|
|
int TargetFlags = ARMII::MO_NO_FLAG;
|
2017-09-05 08:22:47 +00:00
|
|
|
if (STI.isTargetDarwin())
|
2017-11-13 20:45:38 +00:00
|
|
|
TargetFlags |= ARMII::MO_NONLAZY;
|
|
|
|
if (STI.isGVInGOT(GV))
|
|
|
|
TargetFlags |= ARMII::MO_GOT;
|
|
|
|
MIB->getOperand(1).setTargetFlags(TargetFlags);
|
2017-08-29 09:47:55 +00:00
|
|
|
|
2019-02-28 10:42:47 +00:00
|
|
|
if (Indirect) {
|
|
|
|
if (!UseOpcodeThatLoads) {
|
|
|
|
auto ResultReg = MIB->getOperand(0).getReg();
|
|
|
|
auto AddressReg = MRI.createVirtualRegister(&ARM::GPRRegClass);
|
|
|
|
|
|
|
|
MIB->getOperand(0).setReg(AddressReg);
|
|
|
|
|
|
|
|
auto InsertBefore = std::next(MIB->getIterator());
|
|
|
|
auto MIBLoad = BuildMI(MBB, InsertBefore, MIB->getDebugLoc(),
|
|
|
|
TII.get(Opcodes.LOAD32))
|
|
|
|
.addDef(ResultReg)
|
|
|
|
.addReg(AddressReg)
|
|
|
|
.addImm(0)
|
|
|
|
.add(predOps(ARMCC::AL));
|
|
|
|
addGOTMemOperand(MIBLoad);
|
|
|
|
|
|
|
|
if (!constrainSelectedInstRegOperands(*MIBLoad, TII, TRI, RBI))
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
addGOTMemOperand(MIB);
|
|
|
|
}
|
|
|
|
}
|
2017-08-29 09:47:55 +00:00
|
|
|
|
2017-09-05 08:22:47 +00:00
|
|
|
return constrainSelectedInstRegOperands(*MIB, TII, TRI, RBI);
|
2017-08-29 09:47:55 +00:00
|
|
|
}
|
|
|
|
|
2017-09-01 11:13:39 +00:00
|
|
|
bool isReadOnly = STI.getTargetLowering()->isReadOnly(GV);
|
|
|
|
if (STI.isROPI() && isReadOnly) {
|
2019-02-28 10:42:47 +00:00
|
|
|
unsigned Opc = UseMovt ? Opcodes.MOV_ga_pcrel : Opcodes.LDRLIT_ga_pcrel;
|
2017-09-01 11:13:39 +00:00
|
|
|
MIB->setDesc(TII.get(Opc));
|
|
|
|
return constrainSelectedInstRegOperands(*MIB, TII, TRI, RBI);
|
|
|
|
}
|
2017-09-05 07:57:41 +00:00
|
|
|
if (STI.isRWPI() && !isReadOnly) {
|
|
|
|
auto Offset = MRI.createVirtualRegister(&ARM::GPRRegClass);
|
|
|
|
MachineInstrBuilder OffsetMIB;
|
|
|
|
if (UseMovt) {
|
|
|
|
OffsetMIB = BuildMI(MBB, *MIB, MIB->getDebugLoc(),
|
2019-02-28 10:42:47 +00:00
|
|
|
TII.get(Opcodes.MOVi32imm), Offset);
|
2017-09-05 07:57:41 +00:00
|
|
|
OffsetMIB.addGlobalAddress(GV, /*Offset*/ 0, ARMII::MO_SBREL);
|
|
|
|
} else {
|
|
|
|
// Load the offset from the constant pool.
|
2019-02-28 10:42:47 +00:00
|
|
|
OffsetMIB = BuildMI(MBB, *MIB, MIB->getDebugLoc(),
|
|
|
|
TII.get(Opcodes.ConstPoolLoad), Offset);
|
2017-09-05 07:57:41 +00:00
|
|
|
addOpsForConstantPoolLoad(OffsetMIB, GV, /*IsSBREL*/ true);
|
|
|
|
}
|
|
|
|
if (!constrainSelectedInstRegOperands(*OffsetMIB, TII, TRI, RBI))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Add the offset to the SB register.
|
2019-02-28 10:42:47 +00:00
|
|
|
MIB->setDesc(TII.get(Opcodes.ADDrr));
|
2017-09-05 07:57:41 +00:00
|
|
|
MIB->RemoveOperand(1);
|
|
|
|
MIB.addReg(ARM::R9) // FIXME: don't hardcode R9
|
|
|
|
.addReg(Offset)
|
|
|
|
.add(predOps(ARMCC::AL))
|
|
|
|
.add(condCodeOp());
|
|
|
|
|
|
|
|
return constrainSelectedInstRegOperands(*MIB, TII, TRI, RBI);
|
|
|
|
}
|
2017-09-01 11:13:39 +00:00
|
|
|
|
2017-09-05 08:22:47 +00:00
|
|
|
if (STI.isTargetELF()) {
|
2017-08-03 09:14:59 +00:00
|
|
|
if (UseMovt) {
|
2019-02-28 10:42:47 +00:00
|
|
|
MIB->setDesc(TII.get(Opcodes.MOVi32imm));
|
2017-08-03 09:14:59 +00:00
|
|
|
} else {
|
|
|
|
// Load the global's address from the constant pool.
|
2019-02-28 10:42:47 +00:00
|
|
|
MIB->setDesc(TII.get(Opcodes.ConstPoolLoad));
|
2017-08-03 09:14:59 +00:00
|
|
|
MIB->RemoveOperand(1);
|
2017-09-05 07:57:41 +00:00
|
|
|
addOpsForConstantPoolLoad(MIB, GV, /*IsSBREL*/ false);
|
2017-08-03 09:14:59 +00:00
|
|
|
}
|
2017-09-05 08:22:47 +00:00
|
|
|
} else if (STI.isTargetMachO()) {
|
2017-08-03 09:14:59 +00:00
|
|
|
if (UseMovt)
|
2019-02-28 10:42:47 +00:00
|
|
|
MIB->setDesc(TII.get(Opcodes.MOVi32imm));
|
2017-08-03 09:14:59 +00:00
|
|
|
else
|
2019-02-28 10:42:47 +00:00
|
|
|
MIB->setDesc(TII.get(Opcodes.LDRLIT_ga_abs));
|
2017-08-03 09:14:59 +00:00
|
|
|
} else {
|
2018-05-14 12:53:11 +00:00
|
|
|
LLVM_DEBUG(dbgs() << "Object format not supported yet\n");
|
2017-08-03 09:14:59 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return constrainSelectedInstRegOperands(*MIB, TII, TRI, RBI);
|
|
|
|
}
|
|
|
|
|
2017-06-27 09:19:51 +00:00
|
|
|
bool ARMInstructionSelector::selectSelect(MachineInstrBuilder &MIB,
|
2017-07-12 10:31:16 +00:00
|
|
|
MachineRegisterInfo &MRI) const {
|
2017-06-27 09:19:51 +00:00
|
|
|
auto &MBB = *MIB->getParent();
|
|
|
|
auto InsertBefore = std::next(MIB->getIterator());
|
2017-07-07 08:53:27 +00:00
|
|
|
auto &DbgLoc = MIB->getDebugLoc();
|
2017-06-27 09:19:51 +00:00
|
|
|
|
2019-03-28 09:09:27 +00:00
|
|
|
// Compare the condition to 1.
|
2017-06-27 09:19:51 +00:00
|
|
|
auto CondReg = MIB->getOperand(1).getReg();
|
2017-07-12 10:31:16 +00:00
|
|
|
assert(validReg(MRI, CondReg, 1, ARM::GPRRegBankID) &&
|
2017-06-27 09:19:51 +00:00
|
|
|
"Unsupported types for select operation");
|
2019-03-28 09:09:27 +00:00
|
|
|
auto CmpI = BuildMI(MBB, InsertBefore, DbgLoc, TII.get(Opcodes.TSTri))
|
2017-06-27 09:19:51 +00:00
|
|
|
.addUse(CondReg)
|
2019-03-28 09:09:27 +00:00
|
|
|
.addImm(1)
|
2017-06-27 09:19:51 +00:00
|
|
|
.add(predOps(ARMCC::AL));
|
|
|
|
if (!constrainSelectedInstRegOperands(*CmpI, TII, TRI, RBI))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Move a value into the result register based on the result of the
|
|
|
|
// comparison.
|
|
|
|
auto ResReg = MIB->getOperand(0).getReg();
|
|
|
|
auto TrueReg = MIB->getOperand(2).getReg();
|
|
|
|
auto FalseReg = MIB->getOperand(3).getReg();
|
2017-07-12 10:31:16 +00:00
|
|
|
assert(validOpRegPair(MRI, ResReg, TrueReg, 32, ARM::GPRRegBankID) &&
|
|
|
|
validOpRegPair(MRI, TrueReg, FalseReg, 32, ARM::GPRRegBankID) &&
|
2017-06-27 09:19:51 +00:00
|
|
|
"Unsupported types for select operation");
|
2019-02-13 11:25:32 +00:00
|
|
|
auto Mov1I = BuildMI(MBB, InsertBefore, DbgLoc, TII.get(Opcodes.MOVCCr))
|
2017-06-27 09:19:51 +00:00
|
|
|
.addDef(ResReg)
|
|
|
|
.addUse(TrueReg)
|
|
|
|
.addUse(FalseReg)
|
|
|
|
.add(predOps(ARMCC::EQ, ARM::CPSR));
|
|
|
|
if (!constrainSelectedInstRegOperands(*Mov1I, TII, TRI, RBI))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
MIB->eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-10-06 15:39:16 +00:00
|
|
|
bool ARMInstructionSelector::selectShift(unsigned ShiftOpc,
|
|
|
|
MachineInstrBuilder &MIB) const {
|
2019-04-10 09:14:37 +00:00
|
|
|
assert(!STI.isThumb() && "Unsupported subtarget");
|
2017-10-06 15:39:16 +00:00
|
|
|
MIB->setDesc(TII.get(ARM::MOVsr));
|
|
|
|
MIB.addImm(ShiftOpc);
|
|
|
|
MIB.add(predOps(ARMCC::AL)).add(condCodeOp());
|
|
|
|
return constrainSelectedInstRegOperands(*MIB, TII, TRI, RBI);
|
|
|
|
}
|
|
|
|
|
2019-04-10 09:14:32 +00:00
|
|
|
void ARMInstructionSelector::renderVFPF32Imm(
|
|
|
|
MachineInstrBuilder &NewInstBuilder, const MachineInstr &OldInst) const {
|
|
|
|
assert(OldInst.getOpcode() == TargetOpcode::G_FCONSTANT &&
|
|
|
|
"Expected G_FCONSTANT");
|
|
|
|
|
|
|
|
APFloat FPImmValue = OldInst.getOperand(1).getFPImm()->getValueAPF();
|
2019-04-10 09:31:28 +00:00
|
|
|
int FPImmEncoding = ARM_AM::getFP32Imm(FPImmValue);
|
2019-04-10 09:14:32 +00:00
|
|
|
assert(FPImmEncoding != -1 && "Invalid immediate value");
|
|
|
|
|
|
|
|
NewInstBuilder.addImm(FPImmEncoding);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ARMInstructionSelector::renderVFPF64Imm(
|
|
|
|
MachineInstrBuilder &NewInstBuilder, const MachineInstr &OldInst) const {
|
|
|
|
assert(OldInst.getOpcode() == TargetOpcode::G_FCONSTANT &&
|
|
|
|
"Expected G_FCONSTANT");
|
|
|
|
|
|
|
|
APFloat FPImmValue = OldInst.getOperand(1).getFPImm()->getValueAPF();
|
2019-04-10 09:31:28 +00:00
|
|
|
int FPImmEncoding = ARM_AM::getFP64Imm(FPImmValue);
|
2019-04-10 09:14:32 +00:00
|
|
|
assert(FPImmEncoding != -1 && "Invalid immediate value");
|
|
|
|
|
|
|
|
NewInstBuilder.addImm(FPImmEncoding);
|
|
|
|
}
|
|
|
|
|
[globalisel][tablegen] Generate rule coverage and use it to identify untested rules
Summary:
This patch adds a LLVM_ENABLE_GISEL_COV which, like LLVM_ENABLE_DAGISEL_COV,
causes TableGen to instrument the generated table to collect rule coverage
information. However, LLVM_ENABLE_GISEL_COV goes a bit further than
LLVM_ENABLE_DAGISEL_COV. The information is written to files
(${CMAKE_BINARY_DIR}/gisel-coverage-* by default). These files can then be
concatenated into ${LLVM_GISEL_COV_PREFIX}-all after which TableGen will
read this information and use it to emit warnings about untested rules.
This technique could also be used by SelectionDAG and can be further
extended to detect hot rules and give them priority over colder rules.
Usage:
* Enable LLVM_ENABLE_GISEL_COV in CMake
* Build the compiler and run some tests
* cat gisel-coverage-[0-9]* > gisel-coverage-all
* Delete lib/Target/*/*GenGlobalISel.inc*
* Build the compiler
Known issues:
* ${LLVM_GISEL_COV_PREFIX}-all must be generated as a manual
step due to a lack of a portable 'cat' command. It should be the
concatenation of all ${LLVM_GISEL_COV_PREFIX}-[0-9]* files.
* There's no mechanism to discard coverage information when the ruleset
changes
Depends on D39742
Reviewers: ab, qcolombet, t.p.northover, aditya_nandakumar, rovka
Reviewed By: rovka
Subscribers: vsk, arsenm, nhaehnle, mgorny, kristof.beyls, javed.absar, igorb, llvm-commits
Differential Revision: https://reviews.llvm.org/D39747
llvm-svn: 318356
2017-11-16 00:46:35 +00:00
|
|
|
bool ARMInstructionSelector::select(MachineInstr &I,
|
|
|
|
CodeGenCoverage &CoverageInfo) const {
|
2016-12-16 12:54:46 +00:00
|
|
|
assert(I.getParent() && "Instruction should be in a basic block!");
|
|
|
|
assert(I.getParent()->getParent() && "Instruction should be in a function!");
|
|
|
|
|
|
|
|
auto &MBB = *I.getParent();
|
|
|
|
auto &MF = *MBB.getParent();
|
|
|
|
auto &MRI = MF.getRegInfo();
|
|
|
|
|
|
|
|
if (!isPreISelGenericOpcode(I.getOpcode())) {
|
|
|
|
if (I.isCopy())
|
|
|
|
return selectCopy(I, TII, MRI, TRI, RBI);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-22 11:09:18 +00:00
|
|
|
using namespace TargetOpcode;
|
|
|
|
|
[globalisel][tablegen] Generate rule coverage and use it to identify untested rules
Summary:
This patch adds a LLVM_ENABLE_GISEL_COV which, like LLVM_ENABLE_DAGISEL_COV,
causes TableGen to instrument the generated table to collect rule coverage
information. However, LLVM_ENABLE_GISEL_COV goes a bit further than
LLVM_ENABLE_DAGISEL_COV. The information is written to files
(${CMAKE_BINARY_DIR}/gisel-coverage-* by default). These files can then be
concatenated into ${LLVM_GISEL_COV_PREFIX}-all after which TableGen will
read this information and use it to emit warnings about untested rules.
This technique could also be used by SelectionDAG and can be further
extended to detect hot rules and give them priority over colder rules.
Usage:
* Enable LLVM_ENABLE_GISEL_COV in CMake
* Build the compiler and run some tests
* cat gisel-coverage-[0-9]* > gisel-coverage-all
* Delete lib/Target/*/*GenGlobalISel.inc*
* Build the compiler
Known issues:
* ${LLVM_GISEL_COV_PREFIX}-all must be generated as a manual
step due to a lack of a portable 'cat' command. It should be the
concatenation of all ${LLVM_GISEL_COV_PREFIX}-[0-9]* files.
* There's no mechanism to discard coverage information when the ruleset
changes
Depends on D39742
Reviewers: ab, qcolombet, t.p.northover, aditya_nandakumar, rovka
Reviewed By: rovka
Subscribers: vsk, arsenm, nhaehnle, mgorny, kristof.beyls, javed.absar, igorb, llvm-commits
Differential Revision: https://reviews.llvm.org/D39747
llvm-svn: 318356
2017-11-16 00:46:35 +00:00
|
|
|
if (selectImpl(I, CoverageInfo))
|
2017-05-02 09:40:49 +00:00
|
|
|
return true;
|
|
|
|
|
2016-12-19 11:26:31 +00:00
|
|
|
MachineInstrBuilder MIB{MF, I};
|
2017-01-25 08:47:40 +00:00
|
|
|
bool isSExt = false;
|
2016-12-19 11:26:31 +00:00
|
|
|
|
|
|
|
switch (I.getOpcode()) {
|
2017-01-25 08:10:40 +00:00
|
|
|
case G_SEXT:
|
2017-01-25 08:47:40 +00:00
|
|
|
isSExt = true;
|
|
|
|
LLVM_FALLTHROUGH;
|
2017-01-25 08:10:40 +00:00
|
|
|
case G_ZEXT: {
|
2019-05-02 10:08:29 +00:00
|
|
|
assert(MRI.getType(I.getOperand(0).getReg()).getSizeInBits() <= 32 &&
|
2019-05-02 09:28:00 +00:00
|
|
|
"Unsupported destination size for extension");
|
2017-01-25 08:10:40 +00:00
|
|
|
|
|
|
|
LLT SrcTy = MRI.getType(I.getOperand(1).getReg());
|
|
|
|
unsigned SrcSize = SrcTy.getSizeInBits();
|
|
|
|
switch (SrcSize) {
|
2017-01-25 08:47:40 +00:00
|
|
|
case 1: {
|
|
|
|
// ZExt boils down to & 0x1; for SExt we also subtract that from 0
|
2018-12-14 12:37:24 +00:00
|
|
|
I.setDesc(TII.get(Opcodes.AND));
|
2017-01-25 08:47:40 +00:00
|
|
|
MIB.addImm(1).add(predOps(ARMCC::AL)).add(condCodeOp());
|
|
|
|
|
|
|
|
if (isSExt) {
|
|
|
|
unsigned SExtResult = I.getOperand(0).getReg();
|
|
|
|
|
|
|
|
// Use a new virtual register for the result of the AND
|
|
|
|
unsigned AndResult = MRI.createVirtualRegister(&ARM::GPRRegClass);
|
|
|
|
I.getOperand(0).setReg(AndResult);
|
|
|
|
|
|
|
|
auto InsertBefore = std::next(I.getIterator());
|
2018-12-14 12:37:24 +00:00
|
|
|
auto SubI =
|
|
|
|
BuildMI(MBB, InsertBefore, I.getDebugLoc(), TII.get(Opcodes.RSB))
|
|
|
|
.addDef(SExtResult)
|
|
|
|
.addUse(AndResult)
|
|
|
|
.addImm(0)
|
|
|
|
.add(predOps(ARMCC::AL))
|
|
|
|
.add(condCodeOp());
|
2017-01-25 08:47:40 +00:00
|
|
|
if (!constrainSelectedInstRegOperands(*SubI, TII, TRI, RBI))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-01-25 08:10:40 +00:00
|
|
|
case 8:
|
|
|
|
case 16: {
|
2018-12-14 12:37:24 +00:00
|
|
|
unsigned NewOpc = selectSimpleExtOpc(I.getOpcode(), SrcSize);
|
2017-02-17 13:44:19 +00:00
|
|
|
if (NewOpc == I.getOpcode())
|
|
|
|
return false;
|
2017-01-25 08:10:40 +00:00
|
|
|
I.setDesc(TII.get(NewOpc));
|
|
|
|
MIB.addImm(0).add(predOps(ARMCC::AL));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2018-05-14 12:53:11 +00:00
|
|
|
LLVM_DEBUG(dbgs() << "Unsupported source size for extension");
|
2017-01-25 08:10:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-05-11 08:28:31 +00:00
|
|
|
case G_ANYEXT:
|
2017-04-21 13:16:50 +00:00
|
|
|
case G_TRUNC: {
|
|
|
|
// The high bits are undefined, so there's nothing special to do, just
|
|
|
|
// treat it as a copy.
|
|
|
|
auto SrcReg = I.getOperand(1).getReg();
|
|
|
|
auto DstReg = I.getOperand(0).getReg();
|
|
|
|
|
|
|
|
const auto &SrcRegBank = *RBI.getRegBank(SrcReg, MRI, TRI);
|
|
|
|
const auto &DstRegBank = *RBI.getRegBank(DstReg, MRI, TRI);
|
|
|
|
|
2017-12-20 11:27:10 +00:00
|
|
|
if (SrcRegBank.getID() == ARM::FPRRegBankID) {
|
|
|
|
// This should only happen in the obscure case where we have put a 64-bit
|
|
|
|
// integer into a D register. Get it out of there and keep only the
|
|
|
|
// interesting part.
|
|
|
|
assert(I.getOpcode() == G_TRUNC && "Unsupported operand for G_ANYEXT");
|
|
|
|
assert(DstRegBank.getID() == ARM::GPRRegBankID &&
|
|
|
|
"Unsupported combination of register banks");
|
|
|
|
assert(MRI.getType(SrcReg).getSizeInBits() == 64 && "Unsupported size");
|
|
|
|
assert(MRI.getType(DstReg).getSizeInBits() <= 32 && "Unsupported size");
|
|
|
|
|
|
|
|
unsigned IgnoredBits = MRI.createVirtualRegister(&ARM::GPRRegClass);
|
|
|
|
auto InsertBefore = std::next(I.getIterator());
|
|
|
|
auto MovI =
|
|
|
|
BuildMI(MBB, InsertBefore, I.getDebugLoc(), TII.get(ARM::VMOVRRD))
|
|
|
|
.addDef(DstReg)
|
|
|
|
.addDef(IgnoredBits)
|
|
|
|
.addUse(SrcReg)
|
|
|
|
.add(predOps(ARMCC::AL));
|
|
|
|
if (!constrainSelectedInstRegOperands(*MovI, TII, TRI, RBI))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
MIB->eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-04-21 13:16:50 +00:00
|
|
|
if (SrcRegBank.getID() != DstRegBank.getID()) {
|
2018-05-14 12:53:11 +00:00
|
|
|
LLVM_DEBUG(
|
|
|
|
dbgs() << "G_TRUNC/G_ANYEXT operands on different register banks\n");
|
2017-04-21 13:16:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SrcRegBank.getID() != ARM::GPRRegBankID) {
|
2018-05-14 12:53:11 +00:00
|
|
|
LLVM_DEBUG(dbgs() << "G_TRUNC/G_ANYEXT on non-GPR not supported yet\n");
|
2017-04-21 13:16:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
I.setDesc(TII.get(COPY));
|
|
|
|
return selectCopy(I, TII, MRI, TRI, RBI);
|
|
|
|
}
|
2018-01-04 10:54:57 +00:00
|
|
|
case G_CONSTANT: {
|
|
|
|
if (!MRI.getType(I.getOperand(0).getReg()).isPointer()) {
|
|
|
|
// Non-pointer constants should be handled by TableGen.
|
2018-05-14 12:53:11 +00:00
|
|
|
LLVM_DEBUG(dbgs() << "Unsupported constant type\n");
|
2018-01-04 10:54:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &Val = I.getOperand(1);
|
|
|
|
if (Val.isCImm()) {
|
|
|
|
if (!Val.getCImm()->isZero()) {
|
2018-05-14 12:53:11 +00:00
|
|
|
LLVM_DEBUG(dbgs() << "Unsupported pointer constant value\n");
|
2018-01-04 10:54:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Val.ChangeToImmediate(0);
|
|
|
|
} else {
|
|
|
|
assert(Val.isImm() && "Unexpected operand for G_CONSTANT");
|
|
|
|
if (Val.getImm() != 0) {
|
2018-05-14 12:53:11 +00:00
|
|
|
LLVM_DEBUG(dbgs() << "Unsupported pointer constant value\n");
|
2018-01-04 10:54:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-10 09:14:37 +00:00
|
|
|
assert(!STI.isThumb() && "Unsupported subtarget");
|
2018-01-04 10:54:57 +00:00
|
|
|
I.setDesc(TII.get(ARM::MOVi));
|
|
|
|
MIB.add(predOps(ARMCC::AL)).add(condCodeOp());
|
|
|
|
break;
|
|
|
|
}
|
2019-04-10 09:14:24 +00:00
|
|
|
case G_FCONSTANT: {
|
|
|
|
// Load from constant pool
|
|
|
|
unsigned Size = MRI.getType(I.getOperand(0).getReg()).getSizeInBits() / 8;
|
|
|
|
unsigned Alignment = Size;
|
|
|
|
|
|
|
|
assert((Size == 4 || Size == 8) && "Unsupported FP constant type");
|
|
|
|
auto LoadOpcode = Size == 4 ? ARM::VLDRS : ARM::VLDRD;
|
|
|
|
|
|
|
|
auto ConstPool = MF.getConstantPool();
|
|
|
|
auto CPIndex =
|
|
|
|
ConstPool->getConstantPoolIndex(I.getOperand(1).getFPImm(), Alignment);
|
|
|
|
MIB->setDesc(TII.get(LoadOpcode));
|
|
|
|
MIB->RemoveOperand(1);
|
|
|
|
MIB.addConstantPoolIndex(CPIndex, /*Offset*/ 0, /*TargetFlags*/ 0)
|
|
|
|
.addMemOperand(
|
|
|
|
MF.getMachineMemOperand(MachinePointerInfo::getConstantPool(MF),
|
|
|
|
MachineMemOperand::MOLoad, Size, Alignment))
|
|
|
|
.addImm(0)
|
|
|
|
.add(predOps(ARMCC::AL));
|
|
|
|
break;
|
|
|
|
}
|
2017-12-22 13:05:51 +00:00
|
|
|
case G_INTTOPTR:
|
|
|
|
case G_PTRTOINT: {
|
|
|
|
auto SrcReg = I.getOperand(1).getReg();
|
|
|
|
auto DstReg = I.getOperand(0).getReg();
|
|
|
|
|
|
|
|
const auto &SrcRegBank = *RBI.getRegBank(SrcReg, MRI, TRI);
|
|
|
|
const auto &DstRegBank = *RBI.getRegBank(DstReg, MRI, TRI);
|
|
|
|
|
|
|
|
if (SrcRegBank.getID() != DstRegBank.getID()) {
|
2018-05-14 12:53:11 +00:00
|
|
|
LLVM_DEBUG(
|
|
|
|
dbgs()
|
|
|
|
<< "G_INTTOPTR/G_PTRTOINT operands on different register banks\n");
|
2017-12-22 13:05:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SrcRegBank.getID() != ARM::GPRRegBankID) {
|
2018-05-14 12:53:11 +00:00
|
|
|
LLVM_DEBUG(
|
|
|
|
dbgs() << "G_INTTOPTR/G_PTRTOINT on non-GPR not supported yet\n");
|
2017-12-22 13:05:51 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
I.setDesc(TII.get(COPY));
|
|
|
|
return selectCopy(I, TII, MRI, TRI, RBI);
|
|
|
|
}
|
2017-06-27 09:19:51 +00:00
|
|
|
case G_SELECT:
|
2017-07-12 10:31:16 +00:00
|
|
|
return selectSelect(MIB, MRI);
|
|
|
|
case G_ICMP: {
|
2019-02-07 11:05:33 +00:00
|
|
|
CmpConstants Helper(Opcodes.CMPrr, ARM::INSTRUCTION_LIST_END,
|
|
|
|
Opcodes.MOVCCi, ARM::GPRRegBankID, 32);
|
2017-07-12 10:31:16 +00:00
|
|
|
return selectCmp(Helper, MIB, MRI);
|
|
|
|
}
|
2017-07-12 09:01:54 +00:00
|
|
|
case G_FCMP: {
|
[ARM] Replace fp-only-sp and d16 with fp64 and d32.
Those two subtarget features were awkward because their semantics are
reversed: each one indicates the _lack_ of support for something in
the architecture, rather than the presence. As a consequence, you
don't get the behavior you want if you combine two sets of feature
bits.
Each SubtargetFeature for an FP architecture version now comes in four
versions, one for each combination of those options. So you can still
say (for example) '+vfp2' in a feature string and it will mean what
it's always meant, but there's a new string '+vfp2d16sp' meaning the
version without those extra options.
A lot of this change is just mechanically replacing positive checks
for the old features with negative checks for the new ones. But one
more interesting change is that I've rearranged getFPUFeatures() so
that the main FPU feature is appended to the output list *before*
rather than after the features derived from the Restriction field, so
that -fp64 and -d32 can override defaults added by the main feature.
Reviewers: dmgreen, samparker, SjoerdMeijer
Subscribers: srhines, javed.absar, eraman, kristof.beyls, hiraditya, zzheng, Petar.Avramovic, cfe-commits, llvm-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D60691
llvm-svn: 361845
2019-05-28 16:13:20 +00:00
|
|
|
assert(STI.hasVFP2Base() && "Can't select fcmp without VFP");
|
2017-07-12 09:01:54 +00:00
|
|
|
|
|
|
|
unsigned OpReg = I.getOperand(2).getReg();
|
|
|
|
unsigned Size = MRI.getType(OpReg).getSizeInBits();
|
2017-07-12 10:31:16 +00:00
|
|
|
|
[ARM] Replace fp-only-sp and d16 with fp64 and d32.
Those two subtarget features were awkward because their semantics are
reversed: each one indicates the _lack_ of support for something in
the architecture, rather than the presence. As a consequence, you
don't get the behavior you want if you combine two sets of feature
bits.
Each SubtargetFeature for an FP architecture version now comes in four
versions, one for each combination of those options. So you can still
say (for example) '+vfp2' in a feature string and it will mean what
it's always meant, but there's a new string '+vfp2d16sp' meaning the
version without those extra options.
A lot of this change is just mechanically replacing positive checks
for the old features with negative checks for the new ones. But one
more interesting change is that I've rearranged getFPUFeatures() so
that the main FPU feature is appended to the output list *before*
rather than after the features derived from the Restriction field, so
that -fp64 and -d32 can override defaults added by the main feature.
Reviewers: dmgreen, samparker, SjoerdMeijer
Subscribers: srhines, javed.absar, eraman, kristof.beyls, hiraditya, zzheng, Petar.Avramovic, cfe-commits, llvm-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D60691
llvm-svn: 361845
2019-05-28 16:13:20 +00:00
|
|
|
if (Size == 64 && !STI.hasFP64()) {
|
2018-05-14 12:53:11 +00:00
|
|
|
LLVM_DEBUG(dbgs() << "Subtarget only supports single precision");
|
2017-07-12 10:31:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (Size != 32 && Size != 64) {
|
2018-05-14 12:53:11 +00:00
|
|
|
LLVM_DEBUG(dbgs() << "Unsupported size for G_FCMP operand");
|
2017-07-12 10:31:16 +00:00
|
|
|
return false;
|
2017-07-12 09:01:54 +00:00
|
|
|
}
|
|
|
|
|
2017-07-12 10:31:16 +00:00
|
|
|
CmpConstants Helper(Size == 32 ? ARM::VCMPS : ARM::VCMPD, ARM::FMSTAT,
|
2019-02-07 11:05:33 +00:00
|
|
|
Opcodes.MOVCCi, ARM::FPRRegBankID, Size);
|
2017-07-12 10:31:16 +00:00
|
|
|
return selectCmp(Helper, MIB, MRI);
|
2017-07-12 09:01:54 +00:00
|
|
|
}
|
2017-10-06 15:39:16 +00:00
|
|
|
case G_LSHR:
|
|
|
|
return selectShift(ARM_AM::ShiftOpc::lsr, MIB);
|
|
|
|
case G_ASHR:
|
|
|
|
return selectShift(ARM_AM::ShiftOpc::asr, MIB);
|
|
|
|
case G_SHL: {
|
|
|
|
return selectShift(ARM_AM::ShiftOpc::lsl, MIB);
|
|
|
|
}
|
2017-02-28 10:14:38 +00:00
|
|
|
case G_GEP:
|
2019-02-15 10:50:02 +00:00
|
|
|
I.setDesc(TII.get(Opcodes.ADDrr));
|
2017-01-13 10:18:01 +00:00
|
|
|
MIB.add(predOps(ARMCC::AL)).add(condCodeOp());
|
2016-12-19 11:26:31 +00:00
|
|
|
break;
|
|
|
|
case G_FRAME_INDEX:
|
|
|
|
// Add 0 to the given frame index and hope it will eventually be folded into
|
|
|
|
// the user(s).
|
2019-02-21 13:00:02 +00:00
|
|
|
I.setDesc(TII.get(Opcodes.ADDri));
|
2017-01-13 10:18:01 +00:00
|
|
|
MIB.addImm(0).add(predOps(ARMCC::AL)).add(condCodeOp());
|
2016-12-19 11:26:31 +00:00
|
|
|
break;
|
2017-08-03 09:14:59 +00:00
|
|
|
case G_GLOBAL_VALUE:
|
|
|
|
return selectGlobal(MIB, MRI);
|
2017-02-24 14:01:27 +00:00
|
|
|
case G_STORE:
|
2017-01-26 09:20:47 +00:00
|
|
|
case G_LOAD: {
|
2017-12-05 05:52:07 +00:00
|
|
|
const auto &MemOp = **I.memoperands_begin();
|
|
|
|
if (MemOp.getOrdering() != AtomicOrdering::NotAtomic) {
|
2018-05-14 12:53:11 +00:00
|
|
|
LLVM_DEBUG(dbgs() << "Atomic load/store not supported yet\n");
|
2017-12-05 05:52:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-16 14:10:50 +00:00
|
|
|
unsigned Reg = I.getOperand(0).getReg();
|
|
|
|
unsigned RegBank = RBI.getRegBank(Reg, MRI, TRI)->getID();
|
|
|
|
|
|
|
|
LLT ValTy = MRI.getType(Reg);
|
2017-01-26 09:20:47 +00:00
|
|
|
const auto ValSize = ValTy.getSizeInBits();
|
|
|
|
|
[ARM] Replace fp-only-sp and d16 with fp64 and d32.
Those two subtarget features were awkward because their semantics are
reversed: each one indicates the _lack_ of support for something in
the architecture, rather than the presence. As a consequence, you
don't get the behavior you want if you combine two sets of feature
bits.
Each SubtargetFeature for an FP architecture version now comes in four
versions, one for each combination of those options. So you can still
say (for example) '+vfp2' in a feature string and it will mean what
it's always meant, but there's a new string '+vfp2d16sp' meaning the
version without those extra options.
A lot of this change is just mechanically replacing positive checks
for the old features with negative checks for the new ones. But one
more interesting change is that I've rearranged getFPUFeatures() so
that the main FPU feature is appended to the output list *before*
rather than after the features derived from the Restriction field, so
that -fp64 and -d32 can override defaults added by the main feature.
Reviewers: dmgreen, samparker, SjoerdMeijer
Subscribers: srhines, javed.absar, eraman, kristof.beyls, hiraditya, zzheng, Petar.Avramovic, cfe-commits, llvm-commits
Tags: #clang, #llvm
Differential Revision: https://reviews.llvm.org/D60691
llvm-svn: 361845
2019-05-28 16:13:20 +00:00
|
|
|
assert((ValSize != 64 || STI.hasVFP2Base()) &&
|
2017-02-24 14:01:27 +00:00
|
|
|
"Don't know how to load/store 64-bit value without VFP");
|
2017-02-16 14:10:50 +00:00
|
|
|
|
2018-12-14 12:37:24 +00:00
|
|
|
const auto NewOpc = selectLoadStoreOpCode(I.getOpcode(), RegBank, ValSize);
|
2017-02-24 14:01:27 +00:00
|
|
|
if (NewOpc == G_LOAD || NewOpc == G_STORE)
|
2017-02-17 13:44:19 +00:00
|
|
|
return false;
|
|
|
|
|
2019-03-28 09:09:36 +00:00
|
|
|
if (ValSize == 1 && NewOpc == Opcodes.STORE8) {
|
|
|
|
// Before storing a 1-bit value, make sure to clear out any unneeded bits.
|
|
|
|
unsigned OriginalValue = I.getOperand(0).getReg();
|
|
|
|
|
|
|
|
unsigned ValueToStore = MRI.createVirtualRegister(&ARM::GPRRegClass);
|
|
|
|
I.getOperand(0).setReg(ValueToStore);
|
|
|
|
|
|
|
|
auto InsertBefore = I.getIterator();
|
|
|
|
auto AndI = BuildMI(MBB, InsertBefore, I.getDebugLoc(), TII.get(Opcodes.AND))
|
|
|
|
.addDef(ValueToStore)
|
|
|
|
.addUse(OriginalValue)
|
|
|
|
.addImm(1)
|
|
|
|
.add(predOps(ARMCC::AL))
|
|
|
|
.add(condCodeOp());
|
|
|
|
if (!constrainSelectedInstRegOperands(*AndI, TII, TRI, RBI))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-26 09:20:47 +00:00
|
|
|
I.setDesc(TII.get(NewOpc));
|
|
|
|
|
2017-02-24 14:01:27 +00:00
|
|
|
if (NewOpc == ARM::LDRH || NewOpc == ARM::STRH)
|
2017-01-26 09:20:47 +00:00
|
|
|
// LDRH has a funny addressing mode (there's already a FIXME for it).
|
|
|
|
MIB.addReg(0);
|
2017-01-13 09:37:56 +00:00
|
|
|
MIB.addImm(0).add(predOps(ARMCC::AL));
|
2016-12-19 11:26:31 +00:00
|
|
|
break;
|
2017-01-26 09:20:47 +00:00
|
|
|
}
|
2017-06-07 12:35:05 +00:00
|
|
|
case G_MERGE_VALUES: {
|
|
|
|
if (!selectMergeValues(MIB, TII, MRI, TRI, RBI))
|
2017-02-16 12:19:57 +00:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
2017-06-07 12:35:05 +00:00
|
|
|
case G_UNMERGE_VALUES: {
|
|
|
|
if (!selectUnmergeValues(MIB, TII, MRI, TRI, RBI))
|
2017-02-16 12:19:57 +00:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
2017-07-14 09:46:06 +00:00
|
|
|
case G_BRCOND: {
|
|
|
|
if (!validReg(MRI, I.getOperand(0).getReg(), 1, ARM::GPRRegBankID)) {
|
2018-05-14 12:53:11 +00:00
|
|
|
LLVM_DEBUG(dbgs() << "Unsupported condition register for G_BRCOND");
|
2017-07-14 09:46:06 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the flags.
|
2019-02-15 10:24:03 +00:00
|
|
|
auto Test =
|
|
|
|
BuildMI(*I.getParent(), I, I.getDebugLoc(), TII.get(Opcodes.TSTri))
|
|
|
|
.addReg(I.getOperand(0).getReg())
|
|
|
|
.addImm(1)
|
|
|
|
.add(predOps(ARMCC::AL));
|
2017-07-14 09:46:06 +00:00
|
|
|
if (!constrainSelectedInstRegOperands(*Test, TII, TRI, RBI))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Branch conditionally.
|
2019-02-15 10:24:03 +00:00
|
|
|
auto Branch =
|
|
|
|
BuildMI(*I.getParent(), I, I.getDebugLoc(), TII.get(Opcodes.Bcc))
|
|
|
|
.add(I.getOperand(1))
|
|
|
|
.add(predOps(ARMCC::NE, ARM::CPSR));
|
2017-07-14 09:46:06 +00:00
|
|
|
if (!constrainSelectedInstRegOperands(*Branch, TII, TRI, RBI))
|
|
|
|
return false;
|
|
|
|
I.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
2018-01-04 13:09:25 +00:00
|
|
|
case G_PHI: {
|
|
|
|
I.setDesc(TII.get(PHI));
|
|
|
|
|
|
|
|
unsigned DstReg = I.getOperand(0).getReg();
|
|
|
|
const TargetRegisterClass *RC = guessRegClass(DstReg, MRI, TRI, RBI);
|
|
|
|
if (!RBI.constrainGenericRegister(DstReg, *RC, MRI)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-12-19 11:26:31 +00:00
|
|
|
default:
|
|
|
|
return false;
|
2016-12-16 12:54:46 +00:00
|
|
|
}
|
|
|
|
|
2016-12-19 11:26:31 +00:00
|
|
|
return constrainSelectedInstRegOperands(I, TII, TRI, RBI);
|
2016-11-11 08:27:37 +00:00
|
|
|
}
|