#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
+#include "llvm/Support/raw_ostream.h"
using namespace llvm;
/// IsProfitableToHoist - Return true if it is potentially profitable to hoist
/// the given loop invariant.
bool MachineLICM::IsProfitableToHoist(MachineInstr &MI) {
+ if (MI.getOpcode() == TargetInstrInfo::IMPLICIT_DEF)
+ return false;
+
const TargetInstrDesc &TID = MI.getDesc();
// FIXME: For now, only hoist re-materilizable instructions. LICM will
}
static const MachineInstr *LookForDuplicate(const MachineInstr *MI,
- std::vector<const MachineInstr*> &PrevMIs) {
+ std::vector<const MachineInstr*> &PrevMIs,
+ MachineRegisterInfo *RegInfo) {
unsigned NumOps = MI->getNumOperands();
for (unsigned i = 0, e = PrevMIs.size(); i != e; ++i) {
const MachineInstr *PrevMI = PrevMIs[i];
bool IsSame = true;
for (unsigned j = 0; j != NumOps; ++j) {
const MachineOperand &MO = MI->getOperand(j);
- if (MO.isReg() && MO.isDef())
+ if (MO.isReg() && MO.isDef()) {
+ if (RegInfo->getRegClass(MO.getReg()) !=
+ RegInfo->getRegClass(PrevMI->getOperand(j).getReg())) {
+ IsSame = false;
+ break;
+ }
continue;
+ }
if (!MO.isIdenticalTo(PrevMI->getOperand(j))) {
IsSame = false;
break;
// Now move the instructions to the predecessor, inserting it before any
// terminator instructions.
DEBUG({
- DOUT << "Hoisting " << MI;
+ errs() << "Hoisting " << MI;
if (CurPreheader->getBasicBlock())
- DOUT << " to MachineBasicBlock "
- << CurPreheader->getBasicBlock()->getName();
+ errs() << " to MachineBasicBlock "
+ << CurPreheader->getBasicBlock()->getName();
if (MI.getParent()->getBasicBlock())
- DOUT << " from MachineBasicBlock "
- << MI.getParent()->getBasicBlock()->getName();
- DOUT << "\n";
+ errs() << " from MachineBasicBlock "
+ << MI.getParent()->getBasicBlock()->getName();
+ errs() << "\n";
});
// Look for opportunity to CSE the hoisted instruction.
std::vector<const MachineInstr*> >::iterator CI = CSEMap.find(BBOpcPair);
bool DoneCSE = false;
if (CI != CSEMap.end()) {
- const MachineInstr *Dup = LookForDuplicate(&MI, CI->second);
+ const MachineInstr *Dup = LookForDuplicate(&MI, CI->second, RegInfo);
if (Dup) {
DOUT << "CSEing " << MI;
DOUT << " with " << *Dup;