2018-01-25 08:41:58 +08:00
|
|
|
//== ---lib/CodeGen/GlobalISel/GICombinerHelper.cpp --------------------- == //
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/CodeGen/GlobalISel/CombinerHelper.h"
|
|
|
|
#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
|
|
|
|
#include "llvm/CodeGen/GlobalISel/Utils.h"
|
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "gi-combine"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
CombinerHelper::CombinerHelper(MachineIRBuilder &B) :
|
|
|
|
Builder(B), MRI(Builder.getMF().getRegInfo()) {}
|
|
|
|
|
|
|
|
bool CombinerHelper::tryCombineCopy(MachineInstr &MI) {
|
|
|
|
if (MI.getOpcode() != TargetOpcode::COPY)
|
|
|
|
return false;
|
|
|
|
unsigned DstReg = MI.getOperand(0).getReg();
|
|
|
|
unsigned SrcReg = MI.getOperand(1).getReg();
|
|
|
|
LLT DstTy = MRI.getType(DstReg);
|
|
|
|
LLT SrcTy = MRI.getType(SrcReg);
|
|
|
|
// Simple Copy Propagation.
|
|
|
|
// a(sx) = COPY b(sx) -> Replace all uses of a with b.
|
|
|
|
if (DstTy.isValid() && SrcTy.isValid() && DstTy == SrcTy) {
|
|
|
|
MI.eraseFromParent();
|
|
|
|
MRI.replaceRegWith(DstReg, SrcReg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
[globalisel] Add a combiner helpers for extending loads and use them in a pre-legalize combiner for AArch64
Summary: Depends on D45541
Reviewers: ab, aditya_nandakumar, bogner, rtereshin, volkan, rovka, javed.absar, aemerson
Reviewed By: aemerson
Subscribers: aemerson, rengolin, mgorny, javed.absar, kristof.beyls, llvm-commits
Differential Revision: https://reviews.llvm.org/D45543
llvm-svn: 331816
2018-05-09 06:26:39 +08:00
|
|
|
bool CombinerHelper::tryCombineExtendingLoads(MachineInstr &MI) {
|
|
|
|
if (MI.getOpcode() != TargetOpcode::G_ANYEXT &&
|
|
|
|
MI.getOpcode() != TargetOpcode::G_SEXT &&
|
|
|
|
MI.getOpcode() != TargetOpcode::G_ZEXT)
|
|
|
|
return false;
|
|
|
|
|
2018-05-09 06:58:35 +08:00
|
|
|
unsigned DstReg = MI.getOperand(0).getReg();
|
|
|
|
unsigned SrcReg = MI.getOperand(1).getReg();
|
|
|
|
|
[globalisel] Add a combiner helpers for extending loads and use them in a pre-legalize combiner for AArch64
Summary: Depends on D45541
Reviewers: ab, aditya_nandakumar, bogner, rtereshin, volkan, rovka, javed.absar, aemerson
Reviewed By: aemerson
Subscribers: aemerson, rengolin, mgorny, javed.absar, kristof.beyls, llvm-commits
Differential Revision: https://reviews.llvm.org/D45543
llvm-svn: 331816
2018-05-09 06:26:39 +08:00
|
|
|
LLT DstTy = MRI.getType(DstReg);
|
|
|
|
if (!DstTy.isScalar())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (MachineInstr *DefMI = getOpcodeDef(TargetOpcode::G_LOAD, SrcReg, MRI)) {
|
|
|
|
unsigned PtrReg = DefMI->getOperand(1).getReg();
|
|
|
|
MachineMemOperand &MMO = **DefMI->memoperands_begin();
|
|
|
|
DEBUG(dbgs() << ".. Combine MI: " << MI;);
|
|
|
|
Builder.setInstr(MI);
|
|
|
|
Builder.buildLoadInstr(MI.getOpcode() == TargetOpcode::G_SEXT
|
|
|
|
? TargetOpcode::G_SEXTLOAD
|
|
|
|
: MI.getOpcode() == TargetOpcode::G_ZEXT
|
|
|
|
? TargetOpcode::G_ZEXTLOAD
|
|
|
|
: TargetOpcode::G_LOAD,
|
|
|
|
DstReg, PtrReg, MMO);
|
|
|
|
MI.eraseFromParent();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-01-25 08:41:58 +08:00
|
|
|
bool CombinerHelper::tryCombine(MachineInstr &MI) {
|
[globalisel] Add a combiner helpers for extending loads and use them in a pre-legalize combiner for AArch64
Summary: Depends on D45541
Reviewers: ab, aditya_nandakumar, bogner, rtereshin, volkan, rovka, javed.absar, aemerson
Reviewed By: aemerson
Subscribers: aemerson, rengolin, mgorny, javed.absar, kristof.beyls, llvm-commits
Differential Revision: https://reviews.llvm.org/D45543
llvm-svn: 331816
2018-05-09 06:26:39 +08:00
|
|
|
if (tryCombineCopy(MI))
|
|
|
|
return true;
|
2018-05-09 06:58:35 +08:00
|
|
|
return tryCombineExtendingLoads(MI);
|
2018-01-25 08:41:58 +08:00
|
|
|
}
|