2016-11-11 16:27:37 +08:00
|
|
|
//===- ARMInstructionSelector.cpp ----------------------------*- C++ -*-==//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \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 17:10:38 +08:00
|
|
|
#include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
|
2017-10-27 07:39:54 +08:00
|
|
|
#include "llvm/CodeGen/GlobalISel/InstructionSelectorImpl.h"
|
2017-08-03 17:14:59 +08:00
|
|
|
#include "llvm/CodeGen/MachineConstantPool.h"
|
2016-12-16 20:54:46 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2016-11-11 16:27:37 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "arm-isel"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2017-04-28 17:10:38 +08:00
|
|
|
namespace {
|
2017-05-02 17:40:49 +08:00
|
|
|
|
|
|
|
#define GET_GLOBALISEL_PREDICATE_BITSET
|
|
|
|
#include "ARMGenGlobalISel.inc"
|
|
|
|
#undef GET_GLOBALISEL_PREDICATE_BITSET
|
|
|
|
|
2017-04-28 17:10:38 +08:00
|
|
|
class ARMInstructionSelector : public InstructionSelector {
|
|
|
|
public:
|
2017-05-02 17:40:49 +08:00
|
|
|
ARMInstructionSelector(const ARMBaseTargetMachine &TM, const ARMSubtarget &STI,
|
2017-04-28 17:10:38 +08: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 08:46:35 +08:00
|
|
|
bool select(MachineInstr &I, CodeGenCoverage &CoverageInfo) const override;
|
2017-10-27 07:39:54 +08:00
|
|
|
static const char *getName() { return DEBUG_TYPE; }
|
2017-04-28 17:10:38 +08: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 08:46:35 +08:00
|
|
|
bool selectImpl(MachineInstr &I, CodeGenCoverage &CoverageInfo) const;
|
2017-05-02 17:40:49 +08:00
|
|
|
|
2017-07-12 18:31:16 +08: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 16:39:04 +08:00
|
|
|
|
2017-07-12 18:31:16 +08:00
|
|
|
bool selectCmp(CmpConstants Helper, MachineInstrBuilder &MIB,
|
|
|
|
MachineRegisterInfo &MRI) const;
|
2017-06-19 17:40:51 +08:00
|
|
|
|
2017-07-12 18:31:16 +08: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 17:14:59 +08:00
|
|
|
bool selectGlobal(MachineInstrBuilder &MIB, MachineRegisterInfo &MRI) const;
|
2017-07-12 18:31:16 +08:00
|
|
|
bool selectSelect(MachineInstrBuilder &MIB, MachineRegisterInfo &MRI) const;
|
2017-10-06 23:39:16 +08:00
|
|
|
bool selectShift(unsigned ShiftOpc, MachineInstrBuilder &MIB) const;
|
2017-07-12 18:31:16 +08: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 17:19:51 +08:00
|
|
|
|
2017-04-28 17:10:38 +08:00
|
|
|
const ARMBaseInstrInfo &TII;
|
|
|
|
const ARMBaseRegisterInfo &TRI;
|
2017-05-02 17:40:49 +08:00
|
|
|
const ARMBaseTargetMachine &TM;
|
2017-04-28 17:10:38 +08:00
|
|
|
const ARMRegisterBankInfo &RBI;
|
2017-05-02 17:40:49 +08:00
|
|
|
const ARMSubtarget &STI;
|
|
|
|
|
|
|
|
#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 17:10:38 +08:00
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
InstructionSelector *
|
2017-05-02 17:40:49 +08:00
|
|
|
createARMInstructionSelector(const ARMBaseTargetMachine &TM,
|
|
|
|
const ARMSubtarget &STI,
|
2017-04-28 17:10:38 +08:00
|
|
|
const ARMRegisterBankInfo &RBI) {
|
2017-05-02 17:40:49 +08:00
|
|
|
return new ARMInstructionSelector(TM, STI, RBI);
|
2017-04-28 17:10:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-27 19:03:45 +08:00
|
|
|
const unsigned zero_reg = 0;
|
2017-05-02 17:40:49 +08:00
|
|
|
|
|
|
|
#define GET_GLOBALISEL_IMPL
|
|
|
|
#include "ARMGenGlobalISel.inc"
|
|
|
|
#undef GET_GLOBALISEL_IMPL
|
|
|
|
|
|
|
|
ARMInstructionSelector::ARMInstructionSelector(const ARMBaseTargetMachine &TM,
|
|
|
|
const ARMSubtarget &STI,
|
2016-11-11 16:27:37 +08:00
|
|
|
const ARMRegisterBankInfo &RBI)
|
2016-11-16 00:42:10 +08:00
|
|
|
: InstructionSelector(), TII(*STI.getInstrInfo()),
|
2017-05-02 17:40:49 +08:00
|
|
|
TRI(*STI.getRegisterInfo()), TM(TM), RBI(RBI), STI(STI),
|
|
|
|
#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 16:27:37 +08:00
|
|
|
|
2018-01-04 21:09:25 +08: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 20:54:46 +08:00
|
|
|
assert(RegBank && "Can't get reg bank for virtual register");
|
|
|
|
|
2018-01-04 21:09:25 +08:00
|
|
|
const unsigned Size = MRI.getType(Reg).getSizeInBits();
|
2017-02-08 21:23:04 +08:00
|
|
|
assert((RegBank->getID() == ARM::GPRRegBankID ||
|
|
|
|
RegBank->getID() == ARM::FPRRegBankID) &&
|
|
|
|
"Unsupported reg bank");
|
|
|
|
|
|
|
|
if (RegBank->getID() == ARM::FPRRegBankID) {
|
2018-01-04 21:09:25 +08:00
|
|
|
if (Size == 32)
|
|
|
|
return &ARM::SPRRegClass;
|
|
|
|
else if (Size == 64)
|
|
|
|
return &ARM::DPRRegClass;
|
2017-02-16 20:19:52 +08:00
|
|
|
else
|
|
|
|
llvm_unreachable("Unsupported destination size");
|
2017-02-08 21:23:04 +08:00
|
|
|
}
|
|
|
|
|
2018-01-04 21:09:25 +08: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 20:54:46 +08: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)) {
|
|
|
|
DEBUG(dbgs() << "Failed to constrain " << TII.getName(I.getOpcode())
|
|
|
|
<< " operand\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-07 20:35:05 +08:00
|
|
|
static bool selectMergeValues(MachineInstrBuilder &MIB,
|
|
|
|
const ARMBaseInstrInfo &TII,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
const TargetRegisterInfo &TRI,
|
|
|
|
const RegisterBankInfo &RBI) {
|
|
|
|
assert(TII.getSubtarget().hasVFP2() && "Can't select merge without VFP");
|
|
|
|
|
|
|
|
// We only support G_MERGE_VALUES as a way to stick together two scalar GPRs
|
2017-02-16 20:19:57 +08: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 20:35:05 +08:00
|
|
|
"Unsupported operand for G_MERGE_VALUES");
|
2017-02-16 20:19:57 +08: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 20:35:05 +08:00
|
|
|
"Unsupported operand for G_MERGE_VALUES");
|
|
|
|
unsigned VReg2 = MIB->getOperand(2).getReg();
|
2017-02-16 20:19:57 +08:00
|
|
|
(void)VReg2;
|
|
|
|
assert(MRI.getType(VReg2).getSizeInBits() == 32 &&
|
|
|
|
RBI.getRegBank(VReg2, MRI, TRI)->getID() == ARM::GPRRegBankID &&
|
2017-06-07 20:35:05 +08:00
|
|
|
"Unsupported operand for G_MERGE_VALUES");
|
2017-02-16 20:19:57 +08:00
|
|
|
|
|
|
|
MIB->setDesc(TII.get(ARM::VMOVDRR));
|
|
|
|
MIB.add(predOps(ARMCC::AL));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-07 20:35:05 +08:00
|
|
|
static bool selectUnmergeValues(MachineInstrBuilder &MIB,
|
|
|
|
const ARMBaseInstrInfo &TII,
|
|
|
|
MachineRegisterInfo &MRI,
|
|
|
|
const TargetRegisterInfo &TRI,
|
|
|
|
const RegisterBankInfo &RBI) {
|
|
|
|
assert(TII.getSubtarget().hasVFP2() && "Can't select unmerge without VFP");
|
2017-02-16 20:19:57 +08:00
|
|
|
|
2017-06-07 20:35:05 +08:00
|
|
|
// We only support G_UNMERGE_VALUES as a way to break up one DPR into two
|
|
|
|
// GPRs.
|
2017-02-16 20:19:57 +08: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 20:35:05 +08:00
|
|
|
"Unsupported operand for G_UNMERGE_VALUES");
|
2017-02-16 20:19:57 +08:00
|
|
|
unsigned VReg1 = MIB->getOperand(1).getReg();
|
|
|
|
(void)VReg1;
|
2017-06-07 20:35:05 +08: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 20:19:57 +08:00
|
|
|
|
2017-06-07 20:35:05 +08:00
|
|
|
MIB->setDesc(TII.get(ARM::VMOVRRD));
|
2017-02-16 20:19:57 +08:00
|
|
|
MIB.add(predOps(ARMCC::AL));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-25 16:10:40 +08:00
|
|
|
/// Select the opcode for simple extensions (that translate to a single SXT/UXT
|
|
|
|
/// instruction). Extension operations more complicated than that should not
|
2017-02-17 21:44:19 +08:00
|
|
|
/// invoke this. Returns the original opcode if it doesn't know how to select a
|
|
|
|
/// better one.
|
2017-01-25 16:10:40 +08:00
|
|
|
static unsigned selectSimpleExtOpc(unsigned Opc, unsigned Size) {
|
|
|
|
using namespace TargetOpcode;
|
|
|
|
|
2017-02-17 21:44:19 +08:00
|
|
|
if (Size != 8 && Size != 16)
|
|
|
|
return Opc;
|
2017-01-25 16:10:40 +08:00
|
|
|
|
|
|
|
if (Opc == G_SEXT)
|
|
|
|
return Size == 8 ? ARM::SXTB : ARM::SXTH;
|
|
|
|
|
|
|
|
if (Opc == G_ZEXT)
|
|
|
|
return Size == 8 ? ARM::UXTB : ARM::UXTH;
|
|
|
|
|
2017-02-17 21:44:19 +08:00
|
|
|
return Opc;
|
2017-01-25 16:10:40 +08:00
|
|
|
}
|
|
|
|
|
2017-02-24 22:01:27 +08:00
|
|
|
/// Select the opcode for simple loads and stores. For types smaller than 32
|
|
|
|
/// bits, the value will be zero extended. Returns the original opcode if it
|
|
|
|
/// doesn't know how to select a better one.
|
|
|
|
static unsigned selectLoadStoreOpCode(unsigned Opc, unsigned RegBank,
|
|
|
|
unsigned Size) {
|
|
|
|
bool isStore = Opc == TargetOpcode::G_STORE;
|
|
|
|
|
2017-02-16 22:10:50 +08:00
|
|
|
if (RegBank == ARM::GPRRegBankID) {
|
|
|
|
switch (Size) {
|
|
|
|
case 1:
|
|
|
|
case 8:
|
2017-02-24 22:01:27 +08:00
|
|
|
return isStore ? ARM::STRBi12 : ARM::LDRBi12;
|
2017-02-16 22:10:50 +08:00
|
|
|
case 16:
|
2017-02-24 22:01:27 +08:00
|
|
|
return isStore ? ARM::STRH : ARM::LDRH;
|
2017-02-16 22:10:50 +08:00
|
|
|
case 32:
|
2017-02-24 22:01:27 +08:00
|
|
|
return isStore ? ARM::STRi12 : ARM::LDRi12;
|
2017-02-17 21:44:19 +08:00
|
|
|
default:
|
2017-02-24 22:01:27 +08:00
|
|
|
return Opc;
|
2017-02-16 22:10:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-17 21:44:19 +08:00
|
|
|
if (RegBank == ARM::FPRRegBankID) {
|
|
|
|
switch (Size) {
|
|
|
|
case 32:
|
2017-02-24 22:01:27 +08:00
|
|
|
return isStore ? ARM::VSTRS : ARM::VLDRS;
|
2017-02-17 21:44:19 +08:00
|
|
|
case 64:
|
2017-02-24 22:01:27 +08:00
|
|
|
return isStore ? ARM::VSTRD : ARM::VLDRD;
|
2017-02-17 21:44:19 +08:00
|
|
|
default:
|
2017-02-24 22:01:27 +08:00
|
|
|
return Opc;
|
2017-02-17 21:44:19 +08:00
|
|
|
}
|
2017-01-26 17:20:47 +08:00
|
|
|
}
|
|
|
|
|
2017-02-24 22:01:27 +08:00
|
|
|
return Opc;
|
2017-01-26 17:20:47 +08: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 16:39:04 +08: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 17:40:51 +08: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 16:39:04 +08:00
|
|
|
Preds = {ARMCC::GT, ARMCC::MI};
|
|
|
|
break;
|
2017-06-19 17:40:51 +08: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 16:39:04 +08:00
|
|
|
Preds = {ARMCC::EQ, ARMCC::VS};
|
|
|
|
break;
|
2017-06-19 17:40:51 +08: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 16:39:04 +08:00
|
|
|
Preds.first = ARMCC::EQ;
|
|
|
|
break;
|
2017-06-19 17:40:51 +08: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 16:39:04 +08:00
|
|
|
Preds.first = ARMCC::GT;
|
|
|
|
break;
|
2017-06-19 17:40:51 +08: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 16:39:04 +08:00
|
|
|
Preds.first = ARMCC::GE;
|
|
|
|
break;
|
2017-06-19 17:40:51 +08: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 16:39:04 +08:00
|
|
|
Preds.first = ARMCC::HI;
|
|
|
|
break;
|
2017-06-19 17:40:51 +08: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 16:39:04 +08:00
|
|
|
Preds.first = ARMCC::MI;
|
|
|
|
break;
|
2017-06-19 17:40:51 +08: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 16:39:04 +08:00
|
|
|
Preds.first = ARMCC::LS;
|
|
|
|
break;
|
2017-06-19 17:40:51 +08: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 16:39:04 +08:00
|
|
|
Preds.first = ARMCC::VC;
|
|
|
|
break;
|
2017-06-19 17:40:51 +08: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 16:39:04 +08:00
|
|
|
Preds.first = ARMCC::VS;
|
|
|
|
break;
|
2017-06-19 17:40:51 +08: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 16:39:04 +08:00
|
|
|
Preds.first = ARMCC::PL;
|
|
|
|
break;
|
2017-06-19 17:40:51 +08: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 16:39:04 +08:00
|
|
|
Preds.first = ARMCC::LT;
|
|
|
|
break;
|
2017-06-19 17:40:51 +08: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 16:39:04 +08:00
|
|
|
Preds.first = ARMCC::LE;
|
|
|
|
break;
|
2017-06-19 17:40:51 +08: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 16:39:04 +08:00
|
|
|
Preds.first = ARMCC::NE;
|
|
|
|
break;
|
2017-06-19 17:40:51 +08: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 16:39:04 +08:00
|
|
|
Preds.first = ARMCC::HS;
|
|
|
|
break;
|
2017-06-19 17:40:51 +08: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 16:39:04 +08:00
|
|
|
Preds.first = ARMCC::LO;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2017-06-19 17:40:51 +08: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 16:39:04 +08:00
|
|
|
assert(Preds.first != ARMCC::AL && "No comparisons needed?");
|
|
|
|
return Preds;
|
2017-06-19 17:40:51 +08:00
|
|
|
}
|
|
|
|
|
2017-07-12 18:31:16 +08:00
|
|
|
struct ARMInstructionSelector::CmpConstants {
|
|
|
|
CmpConstants(unsigned CmpOpcode, unsigned FlagsOpcode, unsigned OpRegBank,
|
|
|
|
unsigned OpSize)
|
|
|
|
: ComparisonOpcode(CmpOpcode), ReadFlagsOpcode(FlagsOpcode),
|
|
|
|
OperandRegBankID(OpRegBank), OperandSize(OpSize) {}
|
2017-06-19 17:40:51 +08: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 16:39:04 +08:00
|
|
|
// The opcode used for performing the comparison.
|
2017-07-12 18:31:16 +08:00
|
|
|
const unsigned ComparisonOpcode;
|
2017-06-19 17:40:51 +08: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 16:39:04 +08: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 18:31:16 +08: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 16:39:04 +08:00
|
|
|
|
|
|
|
// The assumed register bank ID for the operands.
|
2017-07-12 18:31:16 +08: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 16:39:04 +08:00
|
|
|
|
2017-07-12 17:01:54 +08:00
|
|
|
// The assumed size in bits for the operands.
|
2017-07-12 18:31:16 +08: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 16:39:04 +08:00
|
|
|
|
2017-07-12 18:31:16 +08: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 16:39:04 +08:00
|
|
|
|
2017-07-12 18:31:16 +08: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 16:39:04 +08:00
|
|
|
|
2017-07-12 18:31:16 +08:00
|
|
|
void ARMInstructionSelector::putConstant(InsertInfo I, unsigned DestReg,
|
|
|
|
unsigned Constant) const {
|
|
|
|
(void)BuildMI(I.MBB, I.InsertBefore, I.DbgLoc, TII.get(ARM::MOVi))
|
|
|
|
.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 16:39:04 +08:00
|
|
|
|
2017-07-12 18:31:16 +08: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 16:39:04 +08:00
|
|
|
|
2017-07-12 18:31:16 +08:00
|
|
|
bool ARMInstructionSelector::validReg(MachineRegisterInfo &MRI, unsigned Reg,
|
|
|
|
unsigned ExpectedSize,
|
|
|
|
unsigned ExpectedRegBankID) const {
|
|
|
|
if (MRI.getType(Reg).getSizeInBits() != ExpectedSize) {
|
|
|
|
DEBUG(dbgs() << "Unexpected size for register");
|
|
|
|
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 16:39:04 +08:00
|
|
|
}
|
|
|
|
|
2017-07-12 18:31:16 +08:00
|
|
|
if (RBI.getRegBank(Reg, MRI, TRI)->getID() != ExpectedRegBankID) {
|
|
|
|
DEBUG(dbgs() << "Unexpected register bank for register");
|
|
|
|
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 16:39:04 +08:00
|
|
|
}
|
|
|
|
|
2017-07-12 18:31:16 +08: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 16:39:04 +08:00
|
|
|
|
2017-07-12 18:31:16 +08:00
|
|
|
bool ARMInstructionSelector::selectCmp(CmpConstants Helper,
|
|
|
|
MachineInstrBuilder &MIB,
|
|
|
|
MachineRegisterInfo &MRI) const {
|
|
|
|
const InsertInfo I(MIB);
|
2017-06-19 17:40:51 +08:00
|
|
|
|
|
|
|
auto ResReg = MIB->getOperand(0).getReg();
|
2017-07-12 18:31:16 +08: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 16:39:04 +08:00
|
|
|
return false;
|
|
|
|
|
2017-06-19 17:40:51 +08: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 16:39:04 +08:00
|
|
|
if (Cond == CmpInst::FCMP_TRUE || Cond == CmpInst::FCMP_FALSE) {
|
2017-07-12 18:31:16 +08: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 16:39:04 +08:00
|
|
|
MIB->eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
2017-06-19 17:40:51 +08: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 16:39:04 +08:00
|
|
|
auto LHSReg = MIB->getOperand(2).getReg();
|
|
|
|
auto RHSReg = MIB->getOperand(3).getReg();
|
2017-07-12 18:31:16 +08:00
|
|
|
if (!validOpRegPair(MRI, LHSReg, RHSReg, Helper.OperandSize,
|
|
|
|
Helper.OperandRegBankID))
|
2017-06-19 17:40:51 +08: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 16:39:04 +08:00
|
|
|
auto ARMConds = getComparePreds(Cond);
|
2017-07-12 18:31:16 +08: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 16:39:04 +08:00
|
|
|
|
|
|
|
if (ARMConds.second == ARMCC::AL) {
|
|
|
|
// Simple case, we only need one comparison and we're done.
|
2017-07-12 18:31:16 +08: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 16:39:04 +08:00
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
// Not so simple, we need two successive comparisons.
|
|
|
|
auto IntermediateRes = MRI.createVirtualRegister(&ARM::GPRRegClass);
|
2017-07-12 18:31:16 +08: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 16:39:04 +08:00
|
|
|
return false;
|
2017-07-12 18:31:16 +08: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 16:39:04 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-06-19 17:40:51 +08:00
|
|
|
MIB->eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-07-12 18:31:16 +08: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.
|
|
|
|
auto Mov1I = BuildMI(I.MBB, I.InsertBefore, I.DbgLoc, TII.get(ARM::MOVCCi))
|
|
|
|
.addDef(ResReg)
|
|
|
|
.addUse(PrevRes)
|
|
|
|
.addImm(1)
|
|
|
|
.add(predOps(Cond, ARM::CPSR));
|
|
|
|
if (!constrainSelectedInstRegOperands(*Mov1I, TII, TRI, RBI))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-03 17:14:59 +08:00
|
|
|
bool ARMInstructionSelector::selectGlobal(MachineInstrBuilder &MIB,
|
|
|
|
MachineRegisterInfo &MRI) const {
|
2017-09-05 15:57:41 +08:00
|
|
|
if ((STI.isROPI() || STI.isRWPI()) && !STI.isTargetELF()) {
|
|
|
|
DEBUG(dbgs() << "ROPI and RWPI only supported for ELF\n");
|
2017-08-03 17:14:59 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto GV = MIB->getOperand(1).getGlobal();
|
|
|
|
if (GV->isThreadLocal()) {
|
|
|
|
DEBUG(dbgs() << "TLS variables not supported yet\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &MBB = *MIB->getParent();
|
|
|
|
auto &MF = *MBB.getParent();
|
|
|
|
|
2017-09-05 16:22:47 +08:00
|
|
|
bool UseMovt = STI.useMovt(MF);
|
2017-08-03 17:14:59 +08:00
|
|
|
|
2017-09-05 15:57:41 +08:00
|
|
|
unsigned Size = TM.getPointerSize();
|
2017-08-29 17:47:55 +08:00
|
|
|
unsigned Alignment = 4;
|
2017-09-05 15:57:41 +08:00
|
|
|
|
|
|
|
auto addOpsForConstantPoolLoad = [&MF, Alignment,
|
|
|
|
Size](MachineInstrBuilder &MIB,
|
|
|
|
const GlobalValue *GV, bool IsSBREL) {
|
|
|
|
assert(MIB->getOpcode() == ARM::LDRi12 && "Unsupported instruction");
|
|
|
|
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)
|
|
|
|
.addMemOperand(
|
|
|
|
MF.getMachineMemOperand(MachinePointerInfo::getConstantPool(MF),
|
|
|
|
MachineMemOperand::MOLoad, Size, Alignment))
|
|
|
|
.addImm(0)
|
|
|
|
.add(predOps(ARMCC::AL));
|
|
|
|
};
|
|
|
|
|
2017-08-29 17:47:55 +08:00
|
|
|
if (TM.isPositionIndependent()) {
|
2017-09-05 16:22:47 +08:00
|
|
|
bool Indirect = STI.isGVIndirectSymbol(GV);
|
2017-08-29 17:47:55 +08:00
|
|
|
// FIXME: Taking advantage of MOVT for ELF is pretty involved, so we don't
|
|
|
|
// support it yet. See PR28229.
|
|
|
|
unsigned Opc =
|
2017-09-05 16:22:47 +08:00
|
|
|
UseMovt && !STI.isTargetELF()
|
2017-08-29 17:47:55 +08:00
|
|
|
? (Indirect ? ARM::MOV_ga_pcrel_ldr : ARM::MOV_ga_pcrel)
|
|
|
|
: (Indirect ? ARM::LDRLIT_ga_pcrel_ldr : ARM::LDRLIT_ga_pcrel);
|
|
|
|
MIB->setDesc(TII.get(Opc));
|
|
|
|
|
2017-11-14 04:45:38 +08:00
|
|
|
int TargetFlags = ARMII::MO_NO_FLAG;
|
2017-09-05 16:22:47 +08:00
|
|
|
if (STI.isTargetDarwin())
|
2017-11-14 04:45:38 +08:00
|
|
|
TargetFlags |= ARMII::MO_NONLAZY;
|
|
|
|
if (STI.isGVInGOT(GV))
|
|
|
|
TargetFlags |= ARMII::MO_GOT;
|
|
|
|
MIB->getOperand(1).setTargetFlags(TargetFlags);
|
2017-08-29 17:47:55 +08:00
|
|
|
|
|
|
|
if (Indirect)
|
|
|
|
MIB.addMemOperand(MF.getMachineMemOperand(
|
|
|
|
MachinePointerInfo::getGOT(MF), MachineMemOperand::MOLoad,
|
|
|
|
TM.getPointerSize(), Alignment));
|
|
|
|
|
2017-09-05 16:22:47 +08:00
|
|
|
return constrainSelectedInstRegOperands(*MIB, TII, TRI, RBI);
|
2017-08-29 17:47:55 +08:00
|
|
|
}
|
|
|
|
|
2017-09-01 19:13:39 +08:00
|
|
|
bool isReadOnly = STI.getTargetLowering()->isReadOnly(GV);
|
|
|
|
if (STI.isROPI() && isReadOnly) {
|
|
|
|
unsigned Opc = UseMovt ? ARM::MOV_ga_pcrel : ARM::LDRLIT_ga_pcrel;
|
|
|
|
MIB->setDesc(TII.get(Opc));
|
|
|
|
return constrainSelectedInstRegOperands(*MIB, TII, TRI, RBI);
|
|
|
|
}
|
2017-09-05 15:57:41 +08:00
|
|
|
if (STI.isRWPI() && !isReadOnly) {
|
|
|
|
auto Offset = MRI.createVirtualRegister(&ARM::GPRRegClass);
|
|
|
|
MachineInstrBuilder OffsetMIB;
|
|
|
|
if (UseMovt) {
|
|
|
|
OffsetMIB = BuildMI(MBB, *MIB, MIB->getDebugLoc(),
|
|
|
|
TII.get(ARM::MOVi32imm), Offset);
|
|
|
|
OffsetMIB.addGlobalAddress(GV, /*Offset*/ 0, ARMII::MO_SBREL);
|
|
|
|
} else {
|
|
|
|
// Load the offset from the constant pool.
|
|
|
|
OffsetMIB =
|
|
|
|
BuildMI(MBB, *MIB, MIB->getDebugLoc(), TII.get(ARM::LDRi12), Offset);
|
|
|
|
addOpsForConstantPoolLoad(OffsetMIB, GV, /*IsSBREL*/ true);
|
|
|
|
}
|
|
|
|
if (!constrainSelectedInstRegOperands(*OffsetMIB, TII, TRI, RBI))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Add the offset to the SB register.
|
|
|
|
MIB->setDesc(TII.get(ARM::ADDrr));
|
|
|
|
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 19:13:39 +08:00
|
|
|
|
2017-09-05 16:22:47 +08:00
|
|
|
if (STI.isTargetELF()) {
|
2017-08-03 17:14:59 +08:00
|
|
|
if (UseMovt) {
|
|
|
|
MIB->setDesc(TII.get(ARM::MOVi32imm));
|
|
|
|
} else {
|
|
|
|
// Load the global's address from the constant pool.
|
|
|
|
MIB->setDesc(TII.get(ARM::LDRi12));
|
|
|
|
MIB->RemoveOperand(1);
|
2017-09-05 15:57:41 +08:00
|
|
|
addOpsForConstantPoolLoad(MIB, GV, /*IsSBREL*/ false);
|
2017-08-03 17:14:59 +08:00
|
|
|
}
|
2017-09-05 16:22:47 +08:00
|
|
|
} else if (STI.isTargetMachO()) {
|
2017-08-03 17:14:59 +08:00
|
|
|
if (UseMovt)
|
|
|
|
MIB->setDesc(TII.get(ARM::MOVi32imm));
|
|
|
|
else
|
|
|
|
MIB->setDesc(TII.get(ARM::LDRLIT_ga_abs));
|
|
|
|
} else {
|
|
|
|
DEBUG(dbgs() << "Object format not supported yet\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return constrainSelectedInstRegOperands(*MIB, TII, TRI, RBI);
|
|
|
|
}
|
|
|
|
|
2017-06-27 17:19:51 +08:00
|
|
|
bool ARMInstructionSelector::selectSelect(MachineInstrBuilder &MIB,
|
2017-07-12 18:31:16 +08:00
|
|
|
MachineRegisterInfo &MRI) const {
|
2017-06-27 17:19:51 +08:00
|
|
|
auto &MBB = *MIB->getParent();
|
|
|
|
auto InsertBefore = std::next(MIB->getIterator());
|
2017-07-07 16:53:27 +08:00
|
|
|
auto &DbgLoc = MIB->getDebugLoc();
|
2017-06-27 17:19:51 +08:00
|
|
|
|
|
|
|
// Compare the condition to 0.
|
|
|
|
auto CondReg = MIB->getOperand(1).getReg();
|
2017-07-12 18:31:16 +08:00
|
|
|
assert(validReg(MRI, CondReg, 1, ARM::GPRRegBankID) &&
|
2017-06-27 17:19:51 +08:00
|
|
|
"Unsupported types for select operation");
|
2017-07-07 16:53:27 +08:00
|
|
|
auto CmpI = BuildMI(MBB, InsertBefore, DbgLoc, TII.get(ARM::CMPri))
|
2017-06-27 17:19:51 +08:00
|
|
|
.addUse(CondReg)
|
|
|
|
.addImm(0)
|
|
|
|
.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 18:31:16 +08:00
|
|
|
assert(validOpRegPair(MRI, ResReg, TrueReg, 32, ARM::GPRRegBankID) &&
|
|
|
|
validOpRegPair(MRI, TrueReg, FalseReg, 32, ARM::GPRRegBankID) &&
|
2017-06-27 17:19:51 +08:00
|
|
|
"Unsupported types for select operation");
|
2017-07-07 16:53:27 +08:00
|
|
|
auto Mov1I = BuildMI(MBB, InsertBefore, DbgLoc, TII.get(ARM::MOVCCr))
|
2017-06-27 17:19:51 +08: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 23:39:16 +08:00
|
|
|
bool ARMInstructionSelector::selectShift(unsigned ShiftOpc,
|
|
|
|
MachineInstrBuilder &MIB) const {
|
|
|
|
MIB->setDesc(TII.get(ARM::MOVsr));
|
|
|
|
MIB.addImm(ShiftOpc);
|
|
|
|
MIB.add(predOps(ARMCC::AL)).add(condCodeOp());
|
|
|
|
return constrainSelectedInstRegOperands(*MIB, TII, TRI, 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 08:46:35 +08:00
|
|
|
bool ARMInstructionSelector::select(MachineInstr &I,
|
|
|
|
CodeGenCoverage &CoverageInfo) const {
|
2016-12-16 20:54:46 +08: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 19:09:18 +08: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 08:46:35 +08:00
|
|
|
if (selectImpl(I, CoverageInfo))
|
2017-05-02 17:40:49 +08:00
|
|
|
return true;
|
|
|
|
|
2016-12-19 19:26:31 +08:00
|
|
|
MachineInstrBuilder MIB{MF, I};
|
2017-01-25 16:47:40 +08:00
|
|
|
bool isSExt = false;
|
2016-12-19 19:26:31 +08:00
|
|
|
|
|
|
|
switch (I.getOpcode()) {
|
2017-01-25 16:10:40 +08:00
|
|
|
case G_SEXT:
|
2017-01-25 16:47:40 +08:00
|
|
|
isSExt = true;
|
|
|
|
LLVM_FALLTHROUGH;
|
2017-01-25 16:10:40 +08:00
|
|
|
case G_ZEXT: {
|
|
|
|
LLT DstTy = MRI.getType(I.getOperand(0).getReg());
|
|
|
|
// FIXME: Smaller destination sizes coming soon!
|
|
|
|
if (DstTy.getSizeInBits() != 32) {
|
|
|
|
DEBUG(dbgs() << "Unsupported destination size for extension");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
LLT SrcTy = MRI.getType(I.getOperand(1).getReg());
|
|
|
|
unsigned SrcSize = SrcTy.getSizeInBits();
|
|
|
|
switch (SrcSize) {
|
2017-01-25 16:47:40 +08:00
|
|
|
case 1: {
|
|
|
|
// ZExt boils down to & 0x1; for SExt we also subtract that from 0
|
|
|
|
I.setDesc(TII.get(ARM::ANDri));
|
|
|
|
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());
|
2017-01-25 22:28:19 +08:00
|
|
|
auto SubI =
|
2017-01-25 16:47:40 +08:00
|
|
|
BuildMI(MBB, InsertBefore, I.getDebugLoc(), TII.get(ARM::RSBri))
|
|
|
|
.addDef(SExtResult)
|
|
|
|
.addUse(AndResult)
|
|
|
|
.addImm(0)
|
|
|
|
.add(predOps(ARMCC::AL))
|
|
|
|
.add(condCodeOp());
|
|
|
|
if (!constrainSelectedInstRegOperands(*SubI, TII, TRI, RBI))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-01-25 16:10:40 +08:00
|
|
|
case 8:
|
|
|
|
case 16: {
|
|
|
|
unsigned NewOpc = selectSimpleExtOpc(I.getOpcode(), SrcSize);
|
2017-02-17 21:44:19 +08:00
|
|
|
if (NewOpc == I.getOpcode())
|
|
|
|
return false;
|
2017-01-25 16:10:40 +08:00
|
|
|
I.setDesc(TII.get(NewOpc));
|
|
|
|
MIB.addImm(0).add(predOps(ARMCC::AL));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
DEBUG(dbgs() << "Unsupported source size for extension");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-05-11 16:28:31 +08:00
|
|
|
case G_ANYEXT:
|
2017-04-21 21:16:50 +08: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 19:27:10 +08: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 21:16:50 +08:00
|
|
|
if (SrcRegBank.getID() != DstRegBank.getID()) {
|
2017-05-11 16:28:31 +08:00
|
|
|
DEBUG(dbgs() << "G_TRUNC/G_ANYEXT operands on different register banks\n");
|
2017-04-21 21:16:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SrcRegBank.getID() != ARM::GPRRegBankID) {
|
2017-05-11 16:28:31 +08:00
|
|
|
DEBUG(dbgs() << "G_TRUNC/G_ANYEXT on non-GPR not supported yet\n");
|
2017-04-21 21:16:50 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
I.setDesc(TII.get(COPY));
|
|
|
|
return selectCopy(I, TII, MRI, TRI, RBI);
|
|
|
|
}
|
2018-01-04 18:54:57 +08:00
|
|
|
case G_CONSTANT: {
|
|
|
|
if (!MRI.getType(I.getOperand(0).getReg()).isPointer()) {
|
|
|
|
// Non-pointer constants should be handled by TableGen.
|
|
|
|
DEBUG(dbgs() << "Unsupported constant type\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto &Val = I.getOperand(1);
|
|
|
|
if (Val.isCImm()) {
|
|
|
|
if (!Val.getCImm()->isZero()) {
|
|
|
|
DEBUG(dbgs() << "Unsupported pointer constant value\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Val.ChangeToImmediate(0);
|
|
|
|
} else {
|
|
|
|
assert(Val.isImm() && "Unexpected operand for G_CONSTANT");
|
|
|
|
if (Val.getImm() != 0) {
|
|
|
|
DEBUG(dbgs() << "Unsupported pointer constant value\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
I.setDesc(TII.get(ARM::MOVi));
|
|
|
|
MIB.add(predOps(ARMCC::AL)).add(condCodeOp());
|
|
|
|
break;
|
|
|
|
}
|
2017-12-22 21:05:51 +08: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()) {
|
|
|
|
DEBUG(dbgs()
|
|
|
|
<< "G_INTTOPTR/G_PTRTOINT operands on different register banks\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SrcRegBank.getID() != ARM::GPRRegBankID) {
|
|
|
|
DEBUG(dbgs() << "G_INTTOPTR/G_PTRTOINT on non-GPR not supported yet\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
I.setDesc(TII.get(COPY));
|
|
|
|
return selectCopy(I, TII, MRI, TRI, RBI);
|
|
|
|
}
|
2017-06-27 17:19:51 +08:00
|
|
|
case G_SELECT:
|
2017-07-12 18:31:16 +08:00
|
|
|
return selectSelect(MIB, MRI);
|
|
|
|
case G_ICMP: {
|
|
|
|
CmpConstants Helper(ARM::CMPrr, ARM::INSTRUCTION_LIST_END,
|
|
|
|
ARM::GPRRegBankID, 32);
|
|
|
|
return selectCmp(Helper, MIB, MRI);
|
|
|
|
}
|
2017-07-12 17:01:54 +08:00
|
|
|
case G_FCMP: {
|
2017-09-05 16:22:47 +08:00
|
|
|
assert(STI.hasVFP2() && "Can't select fcmp without VFP");
|
2017-07-12 17:01:54 +08:00
|
|
|
|
|
|
|
unsigned OpReg = I.getOperand(2).getReg();
|
|
|
|
unsigned Size = MRI.getType(OpReg).getSizeInBits();
|
2017-07-12 18:31:16 +08:00
|
|
|
|
2017-09-05 16:22:47 +08:00
|
|
|
if (Size == 64 && STI.isFPOnlySP()) {
|
2017-07-12 18:31:16 +08:00
|
|
|
DEBUG(dbgs() << "Subtarget only supports single precision");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (Size != 32 && Size != 64) {
|
|
|
|
DEBUG(dbgs() << "Unsupported size for G_FCMP operand");
|
|
|
|
return false;
|
2017-07-12 17:01:54 +08:00
|
|
|
}
|
|
|
|
|
2017-07-12 18:31:16 +08:00
|
|
|
CmpConstants Helper(Size == 32 ? ARM::VCMPS : ARM::VCMPD, ARM::FMSTAT,
|
|
|
|
ARM::FPRRegBankID, Size);
|
|
|
|
return selectCmp(Helper, MIB, MRI);
|
2017-07-12 17:01:54 +08:00
|
|
|
}
|
2017-10-06 23:39:16 +08: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 18:14:38 +08:00
|
|
|
case G_GEP:
|
2016-12-16 20:54:46 +08:00
|
|
|
I.setDesc(TII.get(ARM::ADDrr));
|
2017-01-13 18:18:01 +08:00
|
|
|
MIB.add(predOps(ARMCC::AL)).add(condCodeOp());
|
2016-12-19 19:26:31 +08:00
|
|
|
break;
|
|
|
|
case G_FRAME_INDEX:
|
|
|
|
// Add 0 to the given frame index and hope it will eventually be folded into
|
|
|
|
// the user(s).
|
|
|
|
I.setDesc(TII.get(ARM::ADDri));
|
2017-01-13 18:18:01 +08:00
|
|
|
MIB.addImm(0).add(predOps(ARMCC::AL)).add(condCodeOp());
|
2016-12-19 19:26:31 +08:00
|
|
|
break;
|
2017-08-03 17:14:59 +08:00
|
|
|
case G_GLOBAL_VALUE:
|
|
|
|
return selectGlobal(MIB, MRI);
|
2017-02-24 22:01:27 +08:00
|
|
|
case G_STORE:
|
2017-01-26 17:20:47 +08:00
|
|
|
case G_LOAD: {
|
2017-12-05 13:52:07 +08:00
|
|
|
const auto &MemOp = **I.memoperands_begin();
|
|
|
|
if (MemOp.getOrdering() != AtomicOrdering::NotAtomic) {
|
|
|
|
DEBUG(dbgs() << "Atomic load/store not supported yet\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-02-16 22:10:50 +08:00
|
|
|
unsigned Reg = I.getOperand(0).getReg();
|
|
|
|
unsigned RegBank = RBI.getRegBank(Reg, MRI, TRI)->getID();
|
|
|
|
|
|
|
|
LLT ValTy = MRI.getType(Reg);
|
2017-01-26 17:20:47 +08:00
|
|
|
const auto ValSize = ValTy.getSizeInBits();
|
|
|
|
|
2017-09-05 16:22:47 +08:00
|
|
|
assert((ValSize != 64 || STI.hasVFP2()) &&
|
2017-02-24 22:01:27 +08:00
|
|
|
"Don't know how to load/store 64-bit value without VFP");
|
2017-02-16 22:10:50 +08:00
|
|
|
|
2017-02-24 22:01:27 +08:00
|
|
|
const auto NewOpc = selectLoadStoreOpCode(I.getOpcode(), RegBank, ValSize);
|
|
|
|
if (NewOpc == G_LOAD || NewOpc == G_STORE)
|
2017-02-17 21:44:19 +08:00
|
|
|
return false;
|
|
|
|
|
2017-01-26 17:20:47 +08:00
|
|
|
I.setDesc(TII.get(NewOpc));
|
|
|
|
|
2017-02-24 22:01:27 +08:00
|
|
|
if (NewOpc == ARM::LDRH || NewOpc == ARM::STRH)
|
2017-01-26 17:20:47 +08:00
|
|
|
// LDRH has a funny addressing mode (there's already a FIXME for it).
|
|
|
|
MIB.addReg(0);
|
2017-01-13 17:37:56 +08:00
|
|
|
MIB.addImm(0).add(predOps(ARMCC::AL));
|
2016-12-19 19:26:31 +08:00
|
|
|
break;
|
2017-01-26 17:20:47 +08:00
|
|
|
}
|
2017-06-07 20:35:05 +08:00
|
|
|
case G_MERGE_VALUES: {
|
|
|
|
if (!selectMergeValues(MIB, TII, MRI, TRI, RBI))
|
2017-02-16 20:19:57 +08:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
2017-06-07 20:35:05 +08:00
|
|
|
case G_UNMERGE_VALUES: {
|
|
|
|
if (!selectUnmergeValues(MIB, TII, MRI, TRI, RBI))
|
2017-02-16 20:19:57 +08:00
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
2017-07-14 17:46:06 +08:00
|
|
|
case G_BRCOND: {
|
|
|
|
if (!validReg(MRI, I.getOperand(0).getReg(), 1, ARM::GPRRegBankID)) {
|
|
|
|
DEBUG(dbgs() << "Unsupported condition register for G_BRCOND");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the flags.
|
|
|
|
auto Test = BuildMI(*I.getParent(), I, I.getDebugLoc(), TII.get(ARM::TSTri))
|
|
|
|
.addReg(I.getOperand(0).getReg())
|
|
|
|
.addImm(1)
|
|
|
|
.add(predOps(ARMCC::AL));
|
|
|
|
if (!constrainSelectedInstRegOperands(*Test, TII, TRI, RBI))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Branch conditionally.
|
|
|
|
auto Branch = BuildMI(*I.getParent(), I, I.getDebugLoc(), TII.get(ARM::Bcc))
|
|
|
|
.add(I.getOperand(1))
|
2017-11-29 22:20:06 +08:00
|
|
|
.add(predOps(ARMCC::NE, ARM::CPSR));
|
2017-07-14 17:46:06 +08:00
|
|
|
if (!constrainSelectedInstRegOperands(*Branch, TII, TRI, RBI))
|
|
|
|
return false;
|
|
|
|
I.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
2018-01-04 21:09:25 +08: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 19:26:31 +08:00
|
|
|
default:
|
|
|
|
return false;
|
2016-12-16 20:54:46 +08:00
|
|
|
}
|
|
|
|
|
2016-12-19 19:26:31 +08:00
|
|
|
return constrainSelectedInstRegOperands(I, TII, TRI, RBI);
|
2016-11-11 16:27:37 +08:00
|
|
|
}
|