2017-10-05 08:33:50 +08:00
|
|
|
//===- X86OptimizeLEAs.cpp - optimize usage of LEA instructions -----------===//
|
2015-12-04 18:53:15 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the pass that performs some optimizations with LEA
|
2016-05-19 18:18:29 +08:00
|
|
|
// instructions in order to improve performance and code size.
|
2016-01-13 19:30:44 +08:00
|
|
|
// Currently, it does two things:
|
|
|
|
// 1) If there are two LEA instructions calculating addresses which only differ
|
|
|
|
// by displacement inside a basic block, one of them is removed.
|
|
|
|
// 2) Address calculations in load and store instructions are replaced by
|
2015-12-04 18:53:15 +08:00
|
|
|
// existing LEA def registers where possible.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-10-05 08:33:50 +08:00
|
|
|
#include "MCTargetDesc/X86BaseInfo.h"
|
2015-12-04 18:53:15 +08:00
|
|
|
#include "X86.h"
|
|
|
|
#include "X86InstrInfo.h"
|
|
|
|
#include "X86Subtarget.h"
|
2017-10-05 08:33:50 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/DenseMapInfo.h"
|
|
|
|
#include "llvm/ADT/Hashing.h"
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2015-12-04 18:53:15 +08:00
|
|
|
#include "llvm/ADT/Statistic.h"
|
2017-10-05 08:33:50 +08:00
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
|
|
|
#include "llvm/CodeGen/MachineFunction.h"
|
2015-12-04 18:53:15 +08:00
|
|
|
#include "llvm/CodeGen/MachineFunctionPass.h"
|
2017-10-05 08:33:50 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstr.h"
|
2015-12-04 18:53:15 +08:00
|
|
|
#include "llvm/CodeGen/MachineInstrBuilder.h"
|
2016-02-20 18:58:28 +08:00
|
|
|
#include "llvm/CodeGen/MachineOperand.h"
|
2015-12-04 18:53:15 +08:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
2017-11-17 09:07:10 +08:00
|
|
|
#include "llvm/CodeGen/TargetOpcodes.h"
|
|
|
|
#include "llvm/CodeGen/TargetRegisterInfo.h"
|
2017-06-06 19:49:48 +08:00
|
|
|
#include "llvm/IR/DebugInfoMetadata.h"
|
2017-10-05 08:33:50 +08:00
|
|
|
#include "llvm/IR/DebugLoc.h"
|
2015-12-04 18:53:15 +08:00
|
|
|
#include "llvm/IR/Function.h"
|
2017-10-05 08:33:50 +08:00
|
|
|
#include "llvm/MC/MCInstrDesc.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
2015-12-04 18:53:15 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2017-10-05 08:33:50 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/MathExtras.h"
|
2015-12-04 18:53:15 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2017-10-05 08:33:50 +08:00
|
|
|
#include <cassert>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <iterator>
|
2015-12-04 18:53:15 +08:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "x86-optimize-LEAs"
|
|
|
|
|
2016-02-20 19:11:55 +08:00
|
|
|
static cl::opt<bool>
|
|
|
|
DisableX86LEAOpt("disable-x86-lea-opt", cl::Hidden,
|
|
|
|
cl::desc("X86: Disable LEA optimizations."),
|
|
|
|
cl::init(false));
|
2015-12-17 15:34:39 +08:00
|
|
|
|
2015-12-04 18:53:15 +08:00
|
|
|
STATISTIC(NumSubstLEAs, "Number of LEA instruction substitutions");
|
2016-01-13 19:30:44 +08:00
|
|
|
STATISTIC(NumRedundantLEAs, "Number of redundant LEA instructions removed");
|
2015-12-04 18:53:15 +08:00
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Returns true if two machine operands are identical and they are not
|
2016-02-04 16:57:03 +08:00
|
|
|
/// physical registers.
|
|
|
|
static inline bool isIdenticalOp(const MachineOperand &MO1,
|
|
|
|
const MachineOperand &MO2);
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Returns true if two address displacement operands are of the same
|
2016-02-20 18:58:28 +08:00
|
|
|
/// type and use the same symbol/index/address regardless of the offset.
|
|
|
|
static bool isSimilarDispOp(const MachineOperand &MO1,
|
|
|
|
const MachineOperand &MO2);
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Returns true if the instruction is LEA.
|
2016-02-04 16:57:03 +08:00
|
|
|
static inline bool isLEA(const MachineInstr &MI);
|
|
|
|
|
2016-08-06 19:13:10 +08:00
|
|
|
namespace {
|
2017-10-05 08:33:50 +08:00
|
|
|
|
2016-02-04 16:57:03 +08:00
|
|
|
/// A key based on instruction's memory operands.
|
|
|
|
class MemOpKey {
|
|
|
|
public:
|
|
|
|
MemOpKey(const MachineOperand *Base, const MachineOperand *Scale,
|
|
|
|
const MachineOperand *Index, const MachineOperand *Segment,
|
2017-12-02 06:20:26 +08:00
|
|
|
const MachineOperand *Disp)
|
|
|
|
: Disp(Disp) {
|
2016-02-04 16:57:03 +08:00
|
|
|
Operands[0] = Base;
|
|
|
|
Operands[1] = Scale;
|
|
|
|
Operands[2] = Index;
|
|
|
|
Operands[3] = Segment;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const MemOpKey &Other) const {
|
|
|
|
// Addresses' bases, scales, indices and segments must be identical.
|
|
|
|
for (int i = 0; i < 4; ++i)
|
|
|
|
if (!isIdenticalOp(*Operands[i], *Other.Operands[i]))
|
|
|
|
return false;
|
|
|
|
|
2016-02-20 18:58:28 +08:00
|
|
|
// Addresses' displacements don't have to be exactly the same. It only
|
|
|
|
// matters that they use the same symbol/index/address. Immediates' or
|
|
|
|
// offsets' differences will be taken care of during instruction
|
|
|
|
// substitution.
|
|
|
|
return isSimilarDispOp(*Disp, *Other.Disp);
|
2016-02-04 16:57:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Address' base, scale, index and segment operands.
|
|
|
|
const MachineOperand *Operands[4];
|
|
|
|
|
|
|
|
// Address' displacement operand.
|
|
|
|
const MachineOperand *Disp;
|
|
|
|
};
|
2017-10-05 08:33:50 +08:00
|
|
|
|
2016-08-06 19:13:10 +08:00
|
|
|
} // end anonymous namespace
|
2016-02-04 16:57:03 +08:00
|
|
|
|
|
|
|
/// Provide DenseMapInfo for MemOpKey.
|
|
|
|
namespace llvm {
|
2017-10-05 08:33:50 +08:00
|
|
|
|
2016-02-04 16:57:03 +08:00
|
|
|
template <> struct DenseMapInfo<MemOpKey> {
|
2017-10-05 08:33:50 +08:00
|
|
|
using PtrInfo = DenseMapInfo<const MachineOperand *>;
|
2016-02-04 16:57:03 +08:00
|
|
|
|
|
|
|
static inline MemOpKey getEmptyKey() {
|
|
|
|
return MemOpKey(PtrInfo::getEmptyKey(), PtrInfo::getEmptyKey(),
|
|
|
|
PtrInfo::getEmptyKey(), PtrInfo::getEmptyKey(),
|
|
|
|
PtrInfo::getEmptyKey());
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline MemOpKey getTombstoneKey() {
|
|
|
|
return MemOpKey(PtrInfo::getTombstoneKey(), PtrInfo::getTombstoneKey(),
|
|
|
|
PtrInfo::getTombstoneKey(), PtrInfo::getTombstoneKey(),
|
|
|
|
PtrInfo::getTombstoneKey());
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned getHashValue(const MemOpKey &Val) {
|
|
|
|
// Checking any field of MemOpKey is enough to determine if the key is
|
|
|
|
// empty or tombstone.
|
|
|
|
assert(Val.Disp != PtrInfo::getEmptyKey() && "Cannot hash the empty key");
|
|
|
|
assert(Val.Disp != PtrInfo::getTombstoneKey() &&
|
|
|
|
"Cannot hash the tombstone key");
|
|
|
|
|
2017-12-02 06:20:26 +08:00
|
|
|
hash_code Hash = hash_combine(*Val.Operands[0], *Val.Operands[1],
|
|
|
|
*Val.Operands[2], *Val.Operands[3]);
|
2016-02-04 16:57:03 +08:00
|
|
|
|
|
|
|
// If the address displacement is an immediate, it should not affect the
|
|
|
|
// hash so that memory operands which differ only be immediate displacement
|
2016-02-20 18:58:28 +08:00
|
|
|
// would have the same hash. If the address displacement is something else,
|
|
|
|
// we should reflect symbol/index/address in the hash.
|
|
|
|
switch (Val.Disp->getType()) {
|
|
|
|
case MachineOperand::MO_Immediate:
|
|
|
|
break;
|
|
|
|
case MachineOperand::MO_ConstantPoolIndex:
|
|
|
|
case MachineOperand::MO_JumpTableIndex:
|
|
|
|
Hash = hash_combine(Hash, Val.Disp->getIndex());
|
|
|
|
break;
|
|
|
|
case MachineOperand::MO_ExternalSymbol:
|
|
|
|
Hash = hash_combine(Hash, Val.Disp->getSymbolName());
|
|
|
|
break;
|
|
|
|
case MachineOperand::MO_GlobalAddress:
|
2016-02-04 16:57:03 +08:00
|
|
|
Hash = hash_combine(Hash, Val.Disp->getGlobal());
|
2016-02-20 18:58:28 +08:00
|
|
|
break;
|
|
|
|
case MachineOperand::MO_BlockAddress:
|
|
|
|
Hash = hash_combine(Hash, Val.Disp->getBlockAddress());
|
|
|
|
break;
|
|
|
|
case MachineOperand::MO_MCSymbol:
|
|
|
|
Hash = hash_combine(Hash, Val.Disp->getMCSymbol());
|
|
|
|
break;
|
2016-04-26 20:18:12 +08:00
|
|
|
case MachineOperand::MO_MachineBasicBlock:
|
|
|
|
Hash = hash_combine(Hash, Val.Disp->getMBB());
|
|
|
|
break;
|
2016-02-20 18:58:28 +08:00
|
|
|
default:
|
|
|
|
llvm_unreachable("Invalid address displacement operand");
|
|
|
|
}
|
2016-02-04 16:57:03 +08:00
|
|
|
|
|
|
|
return (unsigned)Hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isEqual(const MemOpKey &LHS, const MemOpKey &RHS) {
|
|
|
|
// Checking any field of MemOpKey is enough to determine if the key is
|
|
|
|
// empty or tombstone.
|
|
|
|
if (RHS.Disp == PtrInfo::getEmptyKey())
|
|
|
|
return LHS.Disp == PtrInfo::getEmptyKey();
|
|
|
|
if (RHS.Disp == PtrInfo::getTombstoneKey())
|
|
|
|
return LHS.Disp == PtrInfo::getTombstoneKey();
|
|
|
|
return LHS == RHS;
|
|
|
|
}
|
|
|
|
};
|
2017-10-05 08:33:50 +08:00
|
|
|
|
|
|
|
} // end namespace llvm
|
2016-02-04 16:57:03 +08:00
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Returns a hash table key based on memory operands of \p MI. The
|
2016-08-06 19:13:10 +08:00
|
|
|
/// number of the first memory operand of \p MI is specified through \p N.
|
2016-02-04 16:57:03 +08:00
|
|
|
static inline MemOpKey getMemOpKey(const MachineInstr &MI, unsigned N) {
|
|
|
|
assert((isLEA(MI) || MI.mayLoadOrStore()) &&
|
|
|
|
"The instruction must be a LEA, a load or a store");
|
|
|
|
return MemOpKey(&MI.getOperand(N + X86::AddrBaseReg),
|
|
|
|
&MI.getOperand(N + X86::AddrScaleAmt),
|
|
|
|
&MI.getOperand(N + X86::AddrIndexReg),
|
|
|
|
&MI.getOperand(N + X86::AddrSegmentReg),
|
|
|
|
&MI.getOperand(N + X86::AddrDisp));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool isIdenticalOp(const MachineOperand &MO1,
|
|
|
|
const MachineOperand &MO2) {
|
|
|
|
return MO1.isIdenticalTo(MO2) &&
|
|
|
|
(!MO1.isReg() ||
|
|
|
|
!TargetRegisterInfo::isPhysicalRegister(MO1.getReg()));
|
|
|
|
}
|
|
|
|
|
2016-02-24 15:58:02 +08:00
|
|
|
#ifndef NDEBUG
|
|
|
|
static bool isValidDispOp(const MachineOperand &MO) {
|
|
|
|
return MO.isImm() || MO.isCPI() || MO.isJTI() || MO.isSymbol() ||
|
2016-04-26 20:18:12 +08:00
|
|
|
MO.isGlobal() || MO.isBlockAddress() || MO.isMCSymbol() || MO.isMBB();
|
2016-02-24 15:58:02 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-02-20 18:58:28 +08:00
|
|
|
static bool isSimilarDispOp(const MachineOperand &MO1,
|
|
|
|
const MachineOperand &MO2) {
|
|
|
|
assert(isValidDispOp(MO1) && isValidDispOp(MO2) &&
|
|
|
|
"Address displacement operand is not valid");
|
|
|
|
return (MO1.isImm() && MO2.isImm()) ||
|
|
|
|
(MO1.isCPI() && MO2.isCPI() && MO1.getIndex() == MO2.getIndex()) ||
|
|
|
|
(MO1.isJTI() && MO2.isJTI() && MO1.getIndex() == MO2.getIndex()) ||
|
|
|
|
(MO1.isSymbol() && MO2.isSymbol() &&
|
|
|
|
MO1.getSymbolName() == MO2.getSymbolName()) ||
|
|
|
|
(MO1.isGlobal() && MO2.isGlobal() &&
|
|
|
|
MO1.getGlobal() == MO2.getGlobal()) ||
|
|
|
|
(MO1.isBlockAddress() && MO2.isBlockAddress() &&
|
|
|
|
MO1.getBlockAddress() == MO2.getBlockAddress()) ||
|
|
|
|
(MO1.isMCSymbol() && MO2.isMCSymbol() &&
|
2016-04-26 20:18:12 +08:00
|
|
|
MO1.getMCSymbol() == MO2.getMCSymbol()) ||
|
|
|
|
(MO1.isMBB() && MO2.isMBB() && MO1.getMBB() == MO2.getMBB());
|
2016-02-20 18:58:28 +08:00
|
|
|
}
|
|
|
|
|
2016-02-04 16:57:03 +08:00
|
|
|
static inline bool isLEA(const MachineInstr &MI) {
|
|
|
|
unsigned Opcode = MI.getOpcode();
|
|
|
|
return Opcode == X86::LEA16r || Opcode == X86::LEA32r ||
|
|
|
|
Opcode == X86::LEA64r || Opcode == X86::LEA64_32r;
|
|
|
|
}
|
|
|
|
|
2015-12-04 18:53:15 +08:00
|
|
|
namespace {
|
2017-10-05 08:33:50 +08:00
|
|
|
|
2015-12-04 18:53:15 +08:00
|
|
|
class OptimizeLEAPass : public MachineFunctionPass {
|
|
|
|
public:
|
|
|
|
OptimizeLEAPass() : MachineFunctionPass(ID) {}
|
|
|
|
|
2016-10-01 10:56:57 +08:00
|
|
|
StringRef getPassName() const override { return "X86 LEA Optimize"; }
|
2015-12-04 18:53:15 +08:00
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Loop over all of the basic blocks, replacing address
|
2015-12-04 18:53:15 +08:00
|
|
|
/// calculations in load and store instructions, if it's already
|
|
|
|
/// been calculated by LEA. Also, remove redundant LEAs.
|
|
|
|
bool runOnMachineFunction(MachineFunction &MF) override;
|
|
|
|
|
|
|
|
private:
|
2017-10-05 08:33:50 +08:00
|
|
|
using MemOpMap = DenseMap<MemOpKey, SmallVector<MachineInstr *, 16>>;
|
2016-02-04 16:57:03 +08:00
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Returns a distance between two instructions inside one basic block.
|
2015-12-04 18:53:15 +08:00
|
|
|
/// Negative result means, that instructions occur in reverse order.
|
|
|
|
int calcInstrDist(const MachineInstr &First, const MachineInstr &Last);
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Choose the best \p LEA instruction from the \p List to replace
|
2015-12-04 18:53:15 +08:00
|
|
|
/// address calculation in \p MI instruction. Return the address displacement
|
2016-11-18 03:03:05 +08:00
|
|
|
/// and the distance between \p MI and the chosen \p BestLEA in
|
2016-02-04 16:57:03 +08:00
|
|
|
/// \p AddrDispShift and \p Dist.
|
2015-12-04 18:53:15 +08:00
|
|
|
bool chooseBestLEA(const SmallVectorImpl<MachineInstr *> &List,
|
2016-02-04 16:57:03 +08:00
|
|
|
const MachineInstr &MI, MachineInstr *&BestLEA,
|
2015-12-04 18:53:15 +08:00
|
|
|
int64_t &AddrDispShift, int &Dist);
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Returns the difference between addresses' displacements of \p MI1
|
2016-02-04 16:57:03 +08:00
|
|
|
/// and \p MI2. The numbers of the first memory operands for the instructions
|
|
|
|
/// are specified through \p N1 and \p N2.
|
|
|
|
int64_t getAddrDispShift(const MachineInstr &MI1, unsigned N1,
|
|
|
|
const MachineInstr &MI2, unsigned N2) const;
|
2015-12-04 18:53:15 +08:00
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Returns true if the \p Last LEA instruction can be replaced by the
|
2016-01-13 19:30:44 +08:00
|
|
|
/// \p First. The difference between displacements of the addresses calculated
|
|
|
|
/// by these LEAs is returned in \p AddrDispShift. It'll be used for proper
|
|
|
|
/// replacement of the \p Last LEA's uses with the \p First's def register.
|
|
|
|
bool isReplaceable(const MachineInstr &First, const MachineInstr &Last,
|
2016-02-04 16:57:03 +08:00
|
|
|
int64_t &AddrDispShift) const;
|
2015-12-04 18:53:15 +08:00
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Find all LEA instructions in the basic block. Also, assign position
|
2016-01-11 19:52:29 +08:00
|
|
|
/// numbers to all instructions in the basic block to speed up calculation of
|
|
|
|
/// distance between them.
|
2016-02-04 16:57:03 +08:00
|
|
|
void findLEAs(const MachineBasicBlock &MBB, MemOpMap &LEAs);
|
2015-12-04 18:53:15 +08:00
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Removes redundant address calculations.
|
2016-02-04 16:57:03 +08:00
|
|
|
bool removeRedundantAddrCalc(MemOpMap &LEAs);
|
2015-12-04 18:53:15 +08:00
|
|
|
|
2017-04-28 16:44:30 +08:00
|
|
|
/// Replace debug value MI with a new debug value instruction using register
|
|
|
|
/// VReg with an appropriate offset and DIExpression to incorporate the
|
|
|
|
/// address displacement AddrDispShift. Return new debug value instruction.
|
|
|
|
MachineInstr *replaceDebugValue(MachineInstr &MI, unsigned VReg,
|
|
|
|
int64_t AddrDispShift);
|
|
|
|
|
2018-05-01 23:54:18 +08:00
|
|
|
/// Removes LEAs which calculate similar addresses.
|
2016-02-04 16:57:03 +08:00
|
|
|
bool removeRedundantLEAs(MemOpMap &LEAs);
|
2016-01-13 19:30:44 +08:00
|
|
|
|
2016-01-11 19:52:29 +08:00
|
|
|
DenseMap<const MachineInstr *, unsigned> InstrPos;
|
|
|
|
|
2015-12-04 18:53:15 +08:00
|
|
|
MachineRegisterInfo *MRI;
|
|
|
|
const X86InstrInfo *TII;
|
|
|
|
const X86RegisterInfo *TRI;
|
|
|
|
|
|
|
|
static char ID;
|
|
|
|
};
|
2017-10-05 08:33:50 +08:00
|
|
|
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
2015-12-04 18:53:15 +08:00
|
|
|
char OptimizeLEAPass::ID = 0;
|
|
|
|
|
|
|
|
FunctionPass *llvm::createX86OptimizeLEAs() { return new OptimizeLEAPass(); }
|
|
|
|
|
|
|
|
int OptimizeLEAPass::calcInstrDist(const MachineInstr &First,
|
|
|
|
const MachineInstr &Last) {
|
2016-01-11 19:52:29 +08:00
|
|
|
// Both instructions must be in the same basic block and they must be
|
|
|
|
// presented in InstrPos.
|
|
|
|
assert(Last.getParent() == First.getParent() &&
|
2015-12-04 18:53:15 +08:00
|
|
|
"Instructions are in different basic blocks");
|
2016-01-11 19:52:29 +08:00
|
|
|
assert(InstrPos.find(&First) != InstrPos.end() &&
|
|
|
|
InstrPos.find(&Last) != InstrPos.end() &&
|
|
|
|
"Instructions' positions are undefined");
|
2015-12-04 18:53:15 +08:00
|
|
|
|
2016-01-11 19:52:29 +08:00
|
|
|
return InstrPos[&Last] - InstrPos[&First];
|
2015-12-04 18:53:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find the best LEA instruction in the List to replace address recalculation in
|
|
|
|
// MI. Such LEA must meet these requirements:
|
|
|
|
// 1) The address calculated by the LEA differs only by the displacement from
|
|
|
|
// the address used in MI.
|
|
|
|
// 2) The register class of the definition of the LEA is compatible with the
|
|
|
|
// register class of the address base register of MI.
|
|
|
|
// 3) Displacement of the new memory operand should fit in 1 byte if possible.
|
|
|
|
// 4) The LEA should be as close to MI as possible, and prior to it if
|
|
|
|
// possible.
|
|
|
|
bool OptimizeLEAPass::chooseBestLEA(const SmallVectorImpl<MachineInstr *> &List,
|
2016-02-04 16:57:03 +08:00
|
|
|
const MachineInstr &MI,
|
|
|
|
MachineInstr *&BestLEA,
|
2015-12-04 18:53:15 +08:00
|
|
|
int64_t &AddrDispShift, int &Dist) {
|
|
|
|
const MachineFunction *MF = MI.getParent()->getParent();
|
|
|
|
const MCInstrDesc &Desc = MI.getDesc();
|
2016-04-28 13:58:46 +08:00
|
|
|
int MemOpNo = X86II::getMemoryOperandNo(Desc.TSFlags) +
|
2015-12-04 18:53:15 +08:00
|
|
|
X86II::getOperandBias(Desc);
|
|
|
|
|
2016-02-04 16:57:03 +08:00
|
|
|
BestLEA = nullptr;
|
2015-12-04 18:53:15 +08:00
|
|
|
|
|
|
|
// Loop over all LEA instructions.
|
|
|
|
for (auto DefMI : List) {
|
2016-02-04 16:57:03 +08:00
|
|
|
// Get new address displacement.
|
|
|
|
int64_t AddrDispShiftTemp = getAddrDispShift(MI, MemOpNo, *DefMI, 1);
|
2015-12-04 18:53:15 +08:00
|
|
|
|
|
|
|
// Make sure address displacement fits 4 bytes.
|
|
|
|
if (!isInt<32>(AddrDispShiftTemp))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Check that LEA def register can be used as MI address base. Some
|
|
|
|
// instructions can use a limited set of registers as address base, for
|
|
|
|
// example MOV8mr_NOREX. We could constrain the register class of the LEA
|
|
|
|
// def to suit MI, however since this case is very rare and hard to
|
|
|
|
// reproduce in a test it's just more reliable to skip the LEA.
|
|
|
|
if (TII->getRegClass(Desc, MemOpNo + X86::AddrBaseReg, TRI, *MF) !=
|
|
|
|
MRI->getRegClass(DefMI->getOperand(0).getReg()))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Choose the closest LEA instruction from the list, prior to MI if
|
|
|
|
// possible. Note that we took into account resulting address displacement
|
|
|
|
// as well. Also note that the list is sorted by the order in which the LEAs
|
|
|
|
// occur, so the break condition is pretty simple.
|
|
|
|
int DistTemp = calcInstrDist(*DefMI, MI);
|
|
|
|
assert(DistTemp != 0 &&
|
|
|
|
"The distance between two different instructions cannot be zero");
|
2016-02-04 16:57:03 +08:00
|
|
|
if (DistTemp > 0 || BestLEA == nullptr) {
|
2015-12-04 18:53:15 +08:00
|
|
|
// Do not update return LEA, if the current one provides a displacement
|
|
|
|
// which fits in 1 byte, while the new candidate does not.
|
2016-02-04 16:57:03 +08:00
|
|
|
if (BestLEA != nullptr && !isInt<8>(AddrDispShiftTemp) &&
|
2015-12-04 18:53:15 +08:00
|
|
|
isInt<8>(AddrDispShift))
|
|
|
|
continue;
|
|
|
|
|
2016-02-04 16:57:03 +08:00
|
|
|
BestLEA = DefMI;
|
2015-12-04 18:53:15 +08:00
|
|
|
AddrDispShift = AddrDispShiftTemp;
|
|
|
|
Dist = DistTemp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Maybe we should not always stop at the first LEA after MI.
|
|
|
|
if (DistTemp < 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-02-04 16:57:03 +08:00
|
|
|
return BestLEA != nullptr;
|
2015-12-04 18:53:15 +08:00
|
|
|
}
|
|
|
|
|
2016-02-04 16:57:03 +08:00
|
|
|
// Get the difference between the addresses' displacements of the two
|
|
|
|
// instructions \p MI1 and \p MI2. The numbers of the first memory operands are
|
|
|
|
// passed through \p N1 and \p N2.
|
|
|
|
int64_t OptimizeLEAPass::getAddrDispShift(const MachineInstr &MI1, unsigned N1,
|
|
|
|
const MachineInstr &MI2,
|
|
|
|
unsigned N2) const {
|
|
|
|
const MachineOperand &Op1 = MI1.getOperand(N1 + X86::AddrDisp);
|
|
|
|
const MachineOperand &Op2 = MI2.getOperand(N2 + X86::AddrDisp);
|
2016-02-20 18:58:28 +08:00
|
|
|
|
|
|
|
assert(isSimilarDispOp(Op1, Op2) &&
|
|
|
|
"Address displacement operands are not compatible");
|
|
|
|
|
|
|
|
// After the assert above we can be sure that both operands are of the same
|
|
|
|
// valid type and use the same symbol/index/address, thus displacement shift
|
|
|
|
// calculation is rather simple.
|
|
|
|
if (Op1.isJTI())
|
|
|
|
return 0;
|
|
|
|
return Op1.isImm() ? Op1.getImm() - Op2.getImm()
|
|
|
|
: Op1.getOffset() - Op2.getOffset();
|
2015-12-04 18:53:15 +08:00
|
|
|
}
|
|
|
|
|
2016-01-13 19:30:44 +08:00
|
|
|
// Check that the Last LEA can be replaced by the First LEA. To be so,
|
|
|
|
// these requirements must be met:
|
|
|
|
// 1) Addresses calculated by LEAs differ only by displacement.
|
|
|
|
// 2) Def registers of LEAs belong to the same class.
|
|
|
|
// 3) All uses of the Last LEA def register are replaceable, thus the
|
|
|
|
// register is used only as address base.
|
|
|
|
bool OptimizeLEAPass::isReplaceable(const MachineInstr &First,
|
|
|
|
const MachineInstr &Last,
|
2016-02-04 16:57:03 +08:00
|
|
|
int64_t &AddrDispShift) const {
|
2016-01-13 19:30:44 +08:00
|
|
|
assert(isLEA(First) && isLEA(Last) &&
|
|
|
|
"The function works only with LEA instructions");
|
|
|
|
|
|
|
|
// Make sure that LEA def registers belong to the same class. There may be
|
|
|
|
// instructions (like MOV8mr_NOREX) which allow a limited set of registers to
|
|
|
|
// be used as their operands, so we must be sure that replacing one LEA
|
|
|
|
// with another won't lead to putting a wrong register in the instruction.
|
|
|
|
if (MRI->getRegClass(First.getOperand(0).getReg()) !=
|
|
|
|
MRI->getRegClass(Last.getOperand(0).getReg()))
|
|
|
|
return false;
|
|
|
|
|
2017-03-21 19:36:21 +08:00
|
|
|
// Get new address displacement.
|
|
|
|
AddrDispShift = getAddrDispShift(Last, 1, First, 1);
|
|
|
|
|
2016-01-13 19:30:44 +08:00
|
|
|
// Loop over all uses of the Last LEA to check that its def register is
|
|
|
|
// used only as address base for memory accesses. If so, it can be
|
|
|
|
// replaced, otherwise - no.
|
2017-03-21 19:36:21 +08:00
|
|
|
for (auto &MO : MRI->use_nodbg_operands(Last.getOperand(0).getReg())) {
|
2016-01-13 19:30:44 +08:00
|
|
|
MachineInstr &MI = *MO.getParent();
|
|
|
|
|
|
|
|
// Get the number of the first memory operand.
|
|
|
|
const MCInstrDesc &Desc = MI.getDesc();
|
2016-04-28 13:58:46 +08:00
|
|
|
int MemOpNo = X86II::getMemoryOperandNo(Desc.TSFlags);
|
2016-01-13 19:30:44 +08:00
|
|
|
|
|
|
|
// If the use instruction has no memory operand - the LEA is not
|
|
|
|
// replaceable.
|
|
|
|
if (MemOpNo < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
MemOpNo += X86II::getOperandBias(Desc);
|
|
|
|
|
|
|
|
// If the address base of the use instruction is not the LEA def register -
|
|
|
|
// the LEA is not replaceable.
|
|
|
|
if (!isIdenticalOp(MI.getOperand(MemOpNo + X86::AddrBaseReg), MO))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// If the LEA def register is used as any other operand of the use
|
|
|
|
// instruction - the LEA is not replaceable.
|
|
|
|
for (unsigned i = 0; i < MI.getNumOperands(); i++)
|
|
|
|
if (i != (unsigned)(MemOpNo + X86::AddrBaseReg) &&
|
|
|
|
isIdenticalOp(MI.getOperand(i), MO))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Check that the new address displacement will fit 4 bytes.
|
|
|
|
if (MI.getOperand(MemOpNo + X86::AddrDisp).isImm() &&
|
|
|
|
!isInt<32>(MI.getOperand(MemOpNo + X86::AddrDisp).getImm() +
|
|
|
|
AddrDispShift))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-02-04 16:57:03 +08:00
|
|
|
void OptimizeLEAPass::findLEAs(const MachineBasicBlock &MBB, MemOpMap &LEAs) {
|
2016-01-11 19:52:29 +08:00
|
|
|
unsigned Pos = 0;
|
2015-12-04 18:53:15 +08:00
|
|
|
for (auto &MI : MBB) {
|
2016-01-11 19:52:29 +08:00
|
|
|
// Assign the position number to the instruction. Note that we are going to
|
|
|
|
// move some instructions during the optimization however there will never
|
|
|
|
// be a need to move two instructions before any selected instruction. So to
|
|
|
|
// avoid multiple positions' updates during moves we just increase position
|
|
|
|
// counter by two leaving a free space for instructions which will be moved.
|
|
|
|
InstrPos[&MI] = Pos += 2;
|
|
|
|
|
2015-12-04 18:53:15 +08:00
|
|
|
if (isLEA(MI))
|
2016-02-04 16:57:03 +08:00
|
|
|
LEAs[getMemOpKey(MI, 1)].push_back(const_cast<MachineInstr *>(&MI));
|
2015-12-04 18:53:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to find load and store instructions which recalculate addresses already
|
|
|
|
// calculated by some LEA and replace their memory operands with its def
|
|
|
|
// register.
|
2016-02-04 16:57:03 +08:00
|
|
|
bool OptimizeLEAPass::removeRedundantAddrCalc(MemOpMap &LEAs) {
|
2015-12-04 18:53:15 +08:00
|
|
|
bool Changed = false;
|
|
|
|
|
2017-12-02 06:20:26 +08:00
|
|
|
assert(!LEAs.empty());
|
2016-02-04 16:57:03 +08:00
|
|
|
MachineBasicBlock *MBB = (*LEAs.begin()->second.begin())->getParent();
|
2015-12-04 18:53:15 +08:00
|
|
|
|
|
|
|
// Process all instructions in basic block.
|
|
|
|
for (auto I = MBB->begin(), E = MBB->end(); I != E;) {
|
|
|
|
MachineInstr &MI = *I++;
|
|
|
|
|
|
|
|
// Instruction must be load or store.
|
|
|
|
if (!MI.mayLoadOrStore())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// Get the number of the first memory operand.
|
|
|
|
const MCInstrDesc &Desc = MI.getDesc();
|
2016-04-28 13:58:46 +08:00
|
|
|
int MemOpNo = X86II::getMemoryOperandNo(Desc.TSFlags);
|
2015-12-04 18:53:15 +08:00
|
|
|
|
|
|
|
// If instruction has no memory operand - skip it.
|
|
|
|
if (MemOpNo < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
MemOpNo += X86II::getOperandBias(Desc);
|
|
|
|
|
2018-08-23 02:24:13 +08:00
|
|
|
// Do not call chooseBestLEA if there was no matching LEA
|
|
|
|
auto Insns = LEAs.find(getMemOpKey(MI, MemOpNo));
|
|
|
|
if (Insns == LEAs.end())
|
|
|
|
continue;
|
|
|
|
|
2015-12-04 18:53:15 +08:00
|
|
|
// Get the best LEA instruction to replace address calculation.
|
|
|
|
MachineInstr *DefMI;
|
|
|
|
int64_t AddrDispShift;
|
|
|
|
int Dist;
|
2018-08-23 02:24:13 +08:00
|
|
|
if (!chooseBestLEA(Insns->second, MI, DefMI, AddrDispShift, Dist))
|
2015-12-04 18:53:15 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
// If LEA occurs before current instruction, we can freely replace
|
|
|
|
// the instruction. If LEA occurs after, we can lift LEA above the
|
|
|
|
// instruction and this way to be able to replace it. Since LEA and the
|
|
|
|
// instruction have similar memory operands (thus, the same def
|
|
|
|
// instructions for these operands), we can always do that, without
|
|
|
|
// worries of using registers before their defs.
|
|
|
|
if (Dist < 0) {
|
|
|
|
DefMI->removeFromParent();
|
|
|
|
MBB->insert(MachineBasicBlock::iterator(&MI), DefMI);
|
2016-01-11 19:52:29 +08:00
|
|
|
InstrPos[DefMI] = InstrPos[&MI] - 1;
|
|
|
|
|
|
|
|
// Make sure the instructions' position numbers are sane.
|
2016-07-12 11:18:50 +08:00
|
|
|
assert(((InstrPos[DefMI] == 1 &&
|
|
|
|
MachineBasicBlock::iterator(DefMI) == MBB->begin()) ||
|
2016-01-11 19:52:29 +08:00
|
|
|
InstrPos[DefMI] >
|
2016-07-12 11:18:50 +08:00
|
|
|
InstrPos[&*std::prev(MachineBasicBlock::iterator(DefMI))]) &&
|
2016-01-11 19:52:29 +08:00
|
|
|
"Instruction positioning is broken");
|
2015-12-04 18:53:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Since we can possibly extend register lifetime, clear kill flags.
|
|
|
|
MRI->clearKillFlags(DefMI->getOperand(0).getReg());
|
|
|
|
|
|
|
|
++NumSubstLEAs;
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "OptimizeLEAs: Candidate to replace: "; MI.dump(););
|
2015-12-04 18:53:15 +08:00
|
|
|
|
|
|
|
// Change instruction operands.
|
|
|
|
MI.getOperand(MemOpNo + X86::AddrBaseReg)
|
|
|
|
.ChangeToRegister(DefMI->getOperand(0).getReg(), false);
|
|
|
|
MI.getOperand(MemOpNo + X86::AddrScaleAmt).ChangeToImmediate(1);
|
|
|
|
MI.getOperand(MemOpNo + X86::AddrIndexReg)
|
|
|
|
.ChangeToRegister(X86::NoRegister, false);
|
|
|
|
MI.getOperand(MemOpNo + X86::AddrDisp).ChangeToImmediate(AddrDispShift);
|
|
|
|
MI.getOperand(MemOpNo + X86::AddrSegmentReg)
|
|
|
|
.ChangeToRegister(X86::NoRegister, false);
|
|
|
|
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "OptimizeLEAs: Replaced by: "; MI.dump(););
|
2015-12-04 18:53:15 +08:00
|
|
|
|
|
|
|
Changed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2017-04-28 16:44:30 +08:00
|
|
|
MachineInstr *OptimizeLEAPass::replaceDebugValue(MachineInstr &MI,
|
|
|
|
unsigned VReg,
|
|
|
|
int64_t AddrDispShift) {
|
|
|
|
DIExpression *Expr = const_cast<DIExpression *>(MI.getDebugExpression());
|
|
|
|
|
2017-04-29 01:51:05 +08:00
|
|
|
if (AddrDispShift != 0)
|
|
|
|
Expr = DIExpression::prepend(Expr, DIExpression::NoDeref, AddrDispShift,
|
2017-12-09 05:58:18 +08:00
|
|
|
DIExpression::NoDeref,
|
2017-04-29 01:51:05 +08:00
|
|
|
DIExpression::WithStackValue);
|
2017-04-28 16:44:30 +08:00
|
|
|
|
|
|
|
// Replace DBG_VALUE instruction with modified version.
|
|
|
|
MachineBasicBlock *MBB = MI.getParent();
|
|
|
|
DebugLoc DL = MI.getDebugLoc();
|
|
|
|
bool IsIndirect = MI.isIndirectDebugValue();
|
|
|
|
const MDNode *Var = MI.getDebugVariable();
|
2017-07-29 07:00:45 +08:00
|
|
|
if (IsIndirect)
|
|
|
|
assert(MI.getOperand(1).getImm() == 0 && "DBG_VALUE with nonzero offset");
|
2017-04-28 16:44:30 +08:00
|
|
|
return BuildMI(*MBB, MBB->erase(&MI), DL, TII->get(TargetOpcode::DBG_VALUE),
|
2017-07-29 07:00:45 +08:00
|
|
|
IsIndirect, VReg, Var, Expr);
|
2017-04-28 16:44:30 +08:00
|
|
|
}
|
|
|
|
|
2016-01-13 19:30:44 +08:00
|
|
|
// Try to find similar LEAs in the list and replace one with another.
|
2016-02-04 16:57:03 +08:00
|
|
|
bool OptimizeLEAPass::removeRedundantLEAs(MemOpMap &LEAs) {
|
2016-01-13 19:30:44 +08:00
|
|
|
bool Changed = false;
|
|
|
|
|
2016-02-04 16:57:03 +08:00
|
|
|
// Loop over all entries in the table.
|
|
|
|
for (auto &E : LEAs) {
|
|
|
|
auto &List = E.second;
|
|
|
|
|
|
|
|
// Loop over all LEA pairs.
|
|
|
|
auto I1 = List.begin();
|
|
|
|
while (I1 != List.end()) {
|
|
|
|
MachineInstr &First = **I1;
|
|
|
|
auto I2 = std::next(I1);
|
|
|
|
while (I2 != List.end()) {
|
|
|
|
MachineInstr &Last = **I2;
|
|
|
|
int64_t AddrDispShift;
|
|
|
|
|
2016-11-18 03:03:05 +08:00
|
|
|
// LEAs should be in occurrence order in the list, so we can freely
|
2016-02-04 16:57:03 +08:00
|
|
|
// replace later LEAs with earlier ones.
|
|
|
|
assert(calcInstrDist(First, Last) > 0 &&
|
2016-11-18 03:03:05 +08:00
|
|
|
"LEAs must be in occurrence order in the list");
|
2016-02-04 16:57:03 +08:00
|
|
|
|
|
|
|
// Check that the Last LEA instruction can be replaced by the First.
|
|
|
|
if (!isReplaceable(First, Last, AddrDispShift)) {
|
|
|
|
++I2;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Loop over all uses of the Last LEA and update their operands. Note
|
|
|
|
// that the correctness of this has already been checked in the
|
|
|
|
// isReplaceable function.
|
2017-04-28 16:44:30 +08:00
|
|
|
unsigned FirstVReg = First.getOperand(0).getReg();
|
2017-03-21 19:36:21 +08:00
|
|
|
unsigned LastVReg = Last.getOperand(0).getReg();
|
2017-04-28 16:44:30 +08:00
|
|
|
for (auto UI = MRI->use_begin(LastVReg), UE = MRI->use_end();
|
2016-02-04 16:57:03 +08:00
|
|
|
UI != UE;) {
|
|
|
|
MachineOperand &MO = *UI++;
|
|
|
|
MachineInstr &MI = *MO.getParent();
|
|
|
|
|
2017-04-28 16:44:30 +08:00
|
|
|
if (MI.isDebugValue()) {
|
|
|
|
// Replace DBG_VALUE instruction with modified version using the
|
|
|
|
// register from the replacing LEA and the address displacement
|
|
|
|
// between the LEA instructions.
|
|
|
|
replaceDebugValue(MI, FirstVReg, AddrDispShift);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-02-04 16:57:03 +08:00
|
|
|
// Get the number of the first memory operand.
|
|
|
|
const MCInstrDesc &Desc = MI.getDesc();
|
|
|
|
int MemOpNo =
|
2016-04-28 13:58:46 +08:00
|
|
|
X86II::getMemoryOperandNo(Desc.TSFlags) +
|
2016-02-04 16:57:03 +08:00
|
|
|
X86II::getOperandBias(Desc);
|
|
|
|
|
|
|
|
// Update address base.
|
2017-04-28 16:44:30 +08:00
|
|
|
MO.setReg(FirstVReg);
|
2016-02-04 16:57:03 +08:00
|
|
|
|
|
|
|
// Update address disp.
|
2016-02-20 18:58:28 +08:00
|
|
|
MachineOperand &Op = MI.getOperand(MemOpNo + X86::AddrDisp);
|
|
|
|
if (Op.isImm())
|
|
|
|
Op.setImm(Op.getImm() + AddrDispShift);
|
|
|
|
else if (!Op.isJTI())
|
|
|
|
Op.setOffset(Op.getOffset() + AddrDispShift);
|
2016-02-04 16:57:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Since we can possibly extend register lifetime, clear kill flags.
|
2017-04-28 16:44:30 +08:00
|
|
|
MRI->clearKillFlags(FirstVReg);
|
2016-02-04 16:57:03 +08:00
|
|
|
|
|
|
|
++NumRedundantLEAs;
|
2018-05-14 20:53:11 +08:00
|
|
|
LLVM_DEBUG(dbgs() << "OptimizeLEAs: Remove redundant LEA: ";
|
|
|
|
Last.dump(););
|
2016-02-04 16:57:03 +08:00
|
|
|
|
|
|
|
// By this moment, all of the Last LEA's uses must be replaced. So we
|
|
|
|
// can freely remove it.
|
2017-03-21 19:36:21 +08:00
|
|
|
assert(MRI->use_empty(LastVReg) &&
|
2016-02-04 16:57:03 +08:00
|
|
|
"The LEA's def register must have no uses");
|
|
|
|
Last.eraseFromParent();
|
|
|
|
|
|
|
|
// Erase removed LEA from the list.
|
|
|
|
I2 = List.erase(I2);
|
|
|
|
|
|
|
|
Changed = true;
|
2016-01-13 19:30:44 +08:00
|
|
|
}
|
2016-02-04 16:57:03 +08:00
|
|
|
++I1;
|
2016-01-13 19:30:44 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2015-12-04 18:53:15 +08:00
|
|
|
bool OptimizeLEAPass::runOnMachineFunction(MachineFunction &MF) {
|
|
|
|
bool Changed = false;
|
|
|
|
|
2017-12-16 06:22:58 +08:00
|
|
|
if (DisableX86LEAOpt || skipFunction(MF.getFunction()))
|
2015-12-04 18:53:15 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
MRI = &MF.getRegInfo();
|
|
|
|
TII = MF.getSubtarget<X86Subtarget>().getInstrInfo();
|
|
|
|
TRI = MF.getSubtarget<X86Subtarget>().getRegisterInfo();
|
|
|
|
|
|
|
|
// Process all basic blocks.
|
|
|
|
for (auto &MBB : MF) {
|
2016-02-04 16:57:03 +08:00
|
|
|
MemOpMap LEAs;
|
2016-01-11 19:52:29 +08:00
|
|
|
InstrPos.clear();
|
2015-12-04 18:53:15 +08:00
|
|
|
|
|
|
|
// Find all LEA instructions in basic block.
|
|
|
|
findLEAs(MBB, LEAs);
|
|
|
|
|
|
|
|
// If current basic block has no LEAs, move on to the next one.
|
|
|
|
if (LEAs.empty())
|
|
|
|
continue;
|
|
|
|
|
2016-05-19 18:18:29 +08:00
|
|
|
// Remove redundant LEA instructions.
|
|
|
|
Changed |= removeRedundantLEAs(LEAs);
|
2016-01-13 19:30:44 +08:00
|
|
|
|
2016-05-19 18:18:29 +08:00
|
|
|
// Remove redundant address calculations. Do it only for -Os/-Oz since only
|
|
|
|
// a code size gain is expected from this part of the pass.
|
2017-12-16 06:22:58 +08:00
|
|
|
if (MF.getFunction().optForSize())
|
2016-05-19 18:18:29 +08:00
|
|
|
Changed |= removeRedundantAddrCalc(LEAs);
|
2015-12-04 18:53:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|