summaryrefslogtreecommitdiff
path: root/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp')
-rw-r--r--llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp57
1 files changed, 24 insertions, 33 deletions
diff --git a/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp b/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
index e090d87d59a2..3d9a626d3ac3 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp
@@ -1920,35 +1920,6 @@ bool AArch64InstructionSelector::preISelLower(MachineInstr &I) {
MachineRegisterInfo &MRI = MF.getRegInfo();
switch (I.getOpcode()) {
- case TargetOpcode::G_SHL:
- case TargetOpcode::G_ASHR:
- case TargetOpcode::G_LSHR: {
- // These shifts are legalized to have 64 bit shift amounts because we want
- // to take advantage of the existing imported selection patterns that assume
- // the immediates are s64s. However, if the shifted type is 32 bits and for
- // some reason we receive input GMIR that has an s64 shift amount that's not
- // a G_CONSTANT, insert a truncate so that we can still select the s32
- // register-register variant.
- Register SrcReg = I.getOperand(1).getReg();
- Register ShiftReg = I.getOperand(2).getReg();
- const LLT ShiftTy = MRI.getType(ShiftReg);
- const LLT SrcTy = MRI.getType(SrcReg);
- if (SrcTy.isVector())
- return false;
- assert(!ShiftTy.isVector() && "unexpected vector shift ty");
- if (SrcTy.getSizeInBits() != 32 || ShiftTy.getSizeInBits() != 64)
- return false;
- auto *AmtMI = MRI.getVRegDef(ShiftReg);
- assert(AmtMI && "could not find a vreg definition for shift amount");
- if (AmtMI->getOpcode() != TargetOpcode::G_CONSTANT) {
- // Insert a subregister copy to implement a 64->32 trunc
- auto Trunc = MIB.buildInstr(TargetOpcode::COPY, {SrcTy}, {})
- .addReg(ShiftReg, 0, AArch64::sub_32);
- MRI.setRegBank(Trunc.getReg(0), RBI.getRegBank(AArch64::GPRRegBankID));
- I.getOperand(2).setReg(Trunc.getReg(0));
- }
- return true;
- }
case TargetOpcode::G_STORE: {
bool Changed = contractCrossBankCopyIntoStore(I, MRI);
MachineOperand &SrcOp = I.getOperand(0);
@@ -2950,6 +2921,28 @@ bool AArch64InstructionSelector::select(MachineInstr &I) {
if (Opcode == TargetOpcode::G_SHL &&
MRI.getType(I.getOperand(0).getReg()).isVector())
return selectVectorSHL(I, MRI);
+
+ // These shifts were legalized to have 64 bit shift amounts because we
+ // want to take advantage of the selection patterns that assume the
+ // immediates are s64s, however, selectBinaryOp will assume both operands
+ // will have the same bit size.
+ {
+ Register SrcReg = I.getOperand(1).getReg();
+ Register ShiftReg = I.getOperand(2).getReg();
+ const LLT ShiftTy = MRI.getType(ShiftReg);
+ const LLT SrcTy = MRI.getType(SrcReg);
+ if (!SrcTy.isVector() && SrcTy.getSizeInBits() == 32 &&
+ ShiftTy.getSizeInBits() == 64) {
+ assert(!ShiftTy.isVector() && "unexpected vector shift ty");
+ assert(MRI.getVRegDef(ShiftReg) &&
+ "could not find a vreg definition for shift amount");
+ // Insert a subregister copy to implement a 64->32 trunc
+ auto Trunc = MIB.buildInstr(TargetOpcode::COPY, {SrcTy}, {})
+ .addReg(ShiftReg, 0, AArch64::sub_32);
+ MRI.setRegBank(Trunc.getReg(0), RBI.getRegBank(AArch64::GPRRegBankID));
+ I.getOperand(2).setReg(Trunc.getReg(0));
+ }
+ }
LLVM_FALLTHROUGH;
case TargetOpcode::G_FADD:
case TargetOpcode::G_FSUB:
@@ -6452,8 +6445,7 @@ static void fixupPHIOpBanks(MachineInstr &MI, MachineRegisterInfo &MRI,
MachineIRBuilder MIB(MI);
// Go through each operand and ensure it has the same regbank.
- for (unsigned OpIdx = 1; OpIdx < MI.getNumOperands(); ++OpIdx) {
- MachineOperand &MO = MI.getOperand(OpIdx);
+ for (MachineOperand &MO : llvm::drop_begin(MI.operands())) {
if (!MO.isReg())
continue;
Register OpReg = MO.getReg();
@@ -6511,8 +6503,7 @@ void AArch64InstructionSelector::processPHIs(MachineFunction &MF) {
// %endbb:
// %dst:gpr(s16) = G_PHI %in1:gpr(s16), %bb1, %in2_copy:gpr(s16), %bb2
bool HasGPROp = false, HasFPROp = false;
- for (unsigned OpIdx = 1; OpIdx < MI->getNumOperands(); ++OpIdx) {
- const auto &MO = MI->getOperand(OpIdx);
+ for (const MachineOperand &MO : llvm::drop_begin(MI->operands())) {
if (!MO.isReg())
continue;
const LLT &Ty = MRI.getType(MO.getReg());