bug 122:
- Replace ConstantPointerRef usage with GlobalValue usage - Minimize redundant isa<GlobalValue> usage - Correct isa<Constant> for GlobalValue subclass llvm-svn: 14950
This commit is contained in:
parent
3074d3cfe7
commit
874368790f
|
@ -244,8 +244,7 @@ InstructionNode* InstrForest::buildTreeForInstruction(Instruction *instr) {
|
||||||
&& !instr->isTerminator();
|
&& !instr->isTerminator();
|
||||||
|
|
||||||
if (includeAddressOperand || isa<Instruction>(operand) ||
|
if (includeAddressOperand || isa<Instruction>(operand) ||
|
||||||
isa<Constant>(operand) || isa<Argument>(operand) ||
|
isa<Constant>(operand) || isa<Argument>(operand))
|
||||||
isa<GlobalVariable>(operand))
|
|
||||||
{
|
{
|
||||||
// This operand is a data value
|
// This operand is a data value
|
||||||
|
|
||||||
|
@ -273,6 +272,9 @@ InstructionNode* InstrForest::buildTreeForInstruction(Instruction *instr) {
|
||||||
// Recursively create a treeNode for it.
|
// Recursively create a treeNode for it.
|
||||||
opTreeNode = buildTreeForInstruction((Instruction*)operand);
|
opTreeNode = buildTreeForInstruction((Instruction*)operand);
|
||||||
} else if (Constant *CPV = dyn_cast<Constant>(operand)) {
|
} else if (Constant *CPV = dyn_cast<Constant>(operand)) {
|
||||||
|
if (isa<GlobalValue>(CPV))
|
||||||
|
opTreeNode = new VRegNode(operand);
|
||||||
|
else
|
||||||
// Create a leaf node for a constant
|
// Create a leaf node for a constant
|
||||||
opTreeNode = new ConstantNode(CPV);
|
opTreeNode = new ConstantNode(CPV);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "llvm/Constants.h"
|
#include "llvm/Constants.h"
|
||||||
#include "llvm/BasicBlock.h"
|
#include "llvm/BasicBlock.h"
|
||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
|
#include "llvm/GlobalValue.h"
|
||||||
#include "../SparcV9InstrSelectionSupport.h"
|
#include "../SparcV9InstrSelectionSupport.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
@ -159,7 +160,8 @@ FixConstantOperandsForInstr(Instruction* vmInstr,
|
||||||
if (mop.getType() == MachineOperand::MO_VirtualRegister) {
|
if (mop.getType() == MachineOperand::MO_VirtualRegister) {
|
||||||
assert(mop.getVRegValue() != NULL);
|
assert(mop.getVRegValue() != NULL);
|
||||||
opValue = mop.getVRegValue();
|
opValue = mop.getVRegValue();
|
||||||
if (Constant *opConst = dyn_cast<Constant>(opValue)) {
|
if (Constant *opConst = dyn_cast<Constant>(opValue))
|
||||||
|
if (!isa<GlobalValue>(opConst)) {
|
||||||
opType = ChooseRegOrImmed(opConst, opCode, target,
|
opType = ChooseRegOrImmed(opConst, opCode, target,
|
||||||
(immedPos == (int)op), machineRegNum,
|
(immedPos == (int)op), machineRegNum,
|
||||||
immedValue);
|
immedValue);
|
||||||
|
@ -242,8 +244,7 @@ FixConstantOperandsForInstr(Instruction* vmInstr,
|
||||||
argDesc = CallArgsDescriptor::get(minstr);
|
argDesc = CallArgsDescriptor::get(minstr);
|
||||||
|
|
||||||
for (unsigned i=0, N=minstr->getNumImplicitRefs(); i < N; ++i)
|
for (unsigned i=0, N=minstr->getNumImplicitRefs(); i < N; ++i)
|
||||||
if (isa<Constant>(minstr->getImplicitRef(i)) ||
|
if (isa<Constant>(minstr->getImplicitRef(i)))
|
||||||
isa<GlobalValue>(minstr->getImplicitRef(i)))
|
|
||||||
{
|
{
|
||||||
Value* oldVal = minstr->getImplicitRef(i);
|
Value* oldVal = minstr->getImplicitRef(i);
|
||||||
TmpInstruction* tmpReg =
|
TmpInstruction* tmpReg =
|
||||||
|
|
|
@ -56,16 +56,14 @@ SparcV9InstrInfo::ConvertConstantToIntType(const TargetMachine &target,
|
||||||
if (! destType->isIntegral() && ! isa<PointerType>(destType))
|
if (! destType->isIntegral() && ! isa<PointerType>(destType))
|
||||||
return C;
|
return C;
|
||||||
|
|
||||||
if (! isa<Constant>(V))
|
if (! isa<Constant>(V) || isa<GlobalValue>(V))
|
||||||
return C;
|
return C;
|
||||||
|
|
||||||
// ConstantPointerRef: no conversions needed: get value and return it
|
// GlobalValue: no conversions needed: get value and return it
|
||||||
if (const ConstantPointerRef* CPR = dyn_cast<ConstantPointerRef>(V)) {
|
if (const GlobalValue* GV = dyn_cast<GlobalValue>(V)) {
|
||||||
// A ConstantPointerRef is just a reference to GlobalValue.
|
|
||||||
isValidConstant = true; // may be overwritten by recursive call
|
isValidConstant = true; // may be overwritten by recursive call
|
||||||
return (CPR->isNullValue()? 0
|
return GV->isNullValue() ? 0 :
|
||||||
: ConvertConstantToIntType(target, CPR->getValue(), destType,
|
ConvertConstantToIntType(target, GV, destType, isValidConstant);
|
||||||
isValidConstant));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConstantBool: no conversions needed: get value and return it
|
// ConstantBool: no conversions needed: get value and return it
|
||||||
|
@ -284,7 +282,7 @@ CreateSETXLabel(const TargetMachine& target,
|
||||||
Value* val, Instruction* tmpReg, Instruction* dest,
|
Value* val, Instruction* tmpReg, Instruction* dest,
|
||||||
std::vector<MachineInstr*>& mvec)
|
std::vector<MachineInstr*>& mvec)
|
||||||
{
|
{
|
||||||
assert(isa<Constant>(val) || isa<GlobalValue>(val) &&
|
assert(isa<Constant>(val) &&
|
||||||
"I only know about constant values and global addresses");
|
"I only know about constant values and global addresses");
|
||||||
|
|
||||||
MachineInstr* MI;
|
MachineInstr* MI;
|
||||||
|
@ -467,7 +465,7 @@ SparcV9InstrInfo::CreateCodeToLoadConst(const TargetMachine& target,
|
||||||
std::vector<MachineInstr*>& mvec,
|
std::vector<MachineInstr*>& mvec,
|
||||||
MachineCodeForInstruction& mcfi) const
|
MachineCodeForInstruction& mcfi) const
|
||||||
{
|
{
|
||||||
assert(isa<Constant>(val) || isa<GlobalValue>(val) &&
|
assert(isa<Constant>(val) &&
|
||||||
"I only know about constant values and global addresses");
|
"I only know about constant values and global addresses");
|
||||||
|
|
||||||
// Use a "set" instruction for known constants or symbolic constants (labels)
|
// Use a "set" instruction for known constants or symbolic constants (labels)
|
||||||
|
@ -477,10 +475,6 @@ SparcV9InstrInfo::CreateCodeToLoadConst(const TargetMachine& target,
|
||||||
//
|
//
|
||||||
const Type* valType = val->getType();
|
const Type* valType = val->getType();
|
||||||
|
|
||||||
// A ConstantPointerRef is just a reference to GlobalValue.
|
|
||||||
while (isa<ConstantPointerRef>(val))
|
|
||||||
val = cast<ConstantPointerRef>(val)->getValue();
|
|
||||||
|
|
||||||
if (isa<GlobalValue>(val)) {
|
if (isa<GlobalValue>(val)) {
|
||||||
TmpInstruction* tmpReg =
|
TmpInstruction* tmpReg =
|
||||||
new TmpInstruction(mcfi, PointerType::get(val->getType()), val);
|
new TmpInstruction(mcfi, PointerType::get(val->getType()), val);
|
||||||
|
@ -688,7 +682,9 @@ SparcV9InstrInfo::CreateCopyInstructionsByType(const TargetMachine& target,
|
||||||
// a global variable (i.e., a constant address), generate a load
|
// a global variable (i.e., a constant address), generate a load
|
||||||
// instruction instead of an add
|
// instruction instead of an add
|
||||||
//
|
//
|
||||||
if (isa<Constant>(src)) {
|
if (isa<GlobalValue>(src))
|
||||||
|
loadConstantToReg = true;
|
||||||
|
else if (isa<Constant>(src)) {
|
||||||
unsigned int machineRegNum;
|
unsigned int machineRegNum;
|
||||||
int64_t immedValue;
|
int64_t immedValue;
|
||||||
MachineOperand::MachineOperandType opType =
|
MachineOperand::MachineOperandType opType =
|
||||||
|
@ -698,8 +694,6 @@ SparcV9InstrInfo::CreateCopyInstructionsByType(const TargetMachine& target,
|
||||||
if (opType == MachineOperand::MO_VirtualRegister)
|
if (opType == MachineOperand::MO_VirtualRegister)
|
||||||
loadConstantToReg = true;
|
loadConstantToReg = true;
|
||||||
}
|
}
|
||||||
else if (isa<GlobalValue>(src))
|
|
||||||
loadConstantToReg = true;
|
|
||||||
|
|
||||||
if (loadConstantToReg) {
|
if (loadConstantToReg) {
|
||||||
// `src' is constant and cannot fit in immed field for the ADD
|
// `src' is constant and cannot fit in immed field for the ADD
|
||||||
|
|
|
@ -85,8 +85,6 @@ namespace {
|
||||||
|
|
||||||
// getGlobalAddr(): Put address of a global into a v. register.
|
// getGlobalAddr(): Put address of a global into a v. register.
|
||||||
static GetElementPtrInst* getGlobalAddr(Value* ptr, Instruction& insertBefore) {
|
static GetElementPtrInst* getGlobalAddr(Value* ptr, Instruction& insertBefore) {
|
||||||
if (isa<ConstantPointerRef>(ptr))
|
|
||||||
ptr = cast<ConstantPointerRef>(ptr)->getValue();
|
|
||||||
|
|
||||||
return (isa<GlobalVariable>(ptr))
|
return (isa<GlobalVariable>(ptr))
|
||||||
? new GetElementPtrInst(ptr,
|
? new GetElementPtrInst(ptr,
|
||||||
|
|
|
@ -394,16 +394,10 @@ unsigned ISel::getReg(Value *V, MachineBasicBlock *MBB,
|
||||||
MachineBasicBlock::iterator IPt) {
|
MachineBasicBlock::iterator IPt) {
|
||||||
// If this operand is a constant, emit the code to copy the constant into
|
// If this operand is a constant, emit the code to copy the constant into
|
||||||
// the register here...
|
// the register here...
|
||||||
//
|
|
||||||
if (Constant *C = dyn_cast<Constant>(V)) {
|
if (Constant *C = dyn_cast<Constant>(V)) {
|
||||||
unsigned Reg = makeAnotherReg(V->getType());
|
unsigned Reg = makeAnotherReg(V->getType());
|
||||||
copyConstantToRegister(MBB, IPt, C, Reg);
|
copyConstantToRegister(MBB, IPt, C, Reg);
|
||||||
return Reg;
|
return Reg;
|
||||||
} else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
|
|
||||||
unsigned Reg = makeAnotherReg(V->getType());
|
|
||||||
// Move the address of the global into the register
|
|
||||||
BuildMI(*MBB, IPt, X86::MOV32ri, 1, Reg).addGlobalAddress(GV);
|
|
||||||
return Reg;
|
|
||||||
} else if (CastInst *CI = dyn_cast<CastInst>(V)) {
|
} else if (CastInst *CI = dyn_cast<CastInst>(V)) {
|
||||||
// Do not emit noop casts at all, unless it's a double -> float cast.
|
// Do not emit noop casts at all, unless it's a double -> float cast.
|
||||||
if (getClassB(CI->getType()) == getClassB(CI->getOperand(0)->getType()) &&
|
if (getClassB(CI->getType()) == getClassB(CI->getOperand(0)->getType()) &&
|
||||||
|
@ -554,8 +548,8 @@ void ISel::copyConstantToRegister(MachineBasicBlock *MBB,
|
||||||
} else if (isa<ConstantPointerNull>(C)) {
|
} else if (isa<ConstantPointerNull>(C)) {
|
||||||
// Copy zero (null pointer) to the register.
|
// Copy zero (null pointer) to the register.
|
||||||
BuildMI(*MBB, IP, X86::MOV32ri, 1, R).addImm(0);
|
BuildMI(*MBB, IP, X86::MOV32ri, 1, R).addImm(0);
|
||||||
} else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(C)) {
|
} else if (GlobalValue *GV = dyn_cast<GlobalValue>(C)) {
|
||||||
BuildMI(*MBB, IP, X86::MOV32ri, 1, R).addGlobalAddress(CPR->getValue());
|
BuildMI(*MBB, IP, X86::MOV32ri, 1, R).addGlobalAddress(GV);
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "Offending constant: " << *C << "\n";
|
std::cerr << "Offending constant: " << *C << "\n";
|
||||||
assert(0 && "Type not handled yet!");
|
assert(0 && "Type not handled yet!");
|
||||||
|
@ -688,8 +682,7 @@ void ISel::SelectPHINodes() {
|
||||||
|
|
||||||
// If this is a constant or GlobalValue, we may have to insert code
|
// If this is a constant or GlobalValue, we may have to insert code
|
||||||
// into the basic block to compute it into a virtual register.
|
// into the basic block to compute it into a virtual register.
|
||||||
if ((isa<Constant>(Val) && !isa<ConstantExpr>(Val)) ||
|
if ((isa<Constant>(Val) && !isa<ConstantExpr>(Val))) {
|
||||||
isa<GlobalValue>(Val)) {
|
|
||||||
// Simple constants get emitted at the end of the basic block,
|
// Simple constants get emitted at the end of the basic block,
|
||||||
// before any terminator instructions. We "know" that the code to
|
// before any terminator instructions. We "know" that the code to
|
||||||
// move a constant into a register will never clobber any flags.
|
// move a constant into a register will never clobber any flags.
|
||||||
|
@ -3635,8 +3628,6 @@ bool ISel::isGEPFoldable(MachineBasicBlock *MBB,
|
||||||
Value *Src, User::op_iterator IdxBegin,
|
Value *Src, User::op_iterator IdxBegin,
|
||||||
User::op_iterator IdxEnd, unsigned &BaseReg,
|
User::op_iterator IdxEnd, unsigned &BaseReg,
|
||||||
unsigned &Scale, unsigned &IndexReg, unsigned &Disp) {
|
unsigned &Scale, unsigned &IndexReg, unsigned &Disp) {
|
||||||
if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(Src))
|
|
||||||
Src = CPR->getValue();
|
|
||||||
|
|
||||||
std::vector<Value*> GEPOps;
|
std::vector<Value*> GEPOps;
|
||||||
GEPOps.resize(IdxEnd-IdxBegin+1);
|
GEPOps.resize(IdxEnd-IdxBegin+1);
|
||||||
|
@ -3660,8 +3651,6 @@ void ISel::emitGEPOperation(MachineBasicBlock *MBB,
|
||||||
Value *Src, User::op_iterator IdxBegin,
|
Value *Src, User::op_iterator IdxBegin,
|
||||||
User::op_iterator IdxEnd, unsigned TargetReg) {
|
User::op_iterator IdxEnd, unsigned TargetReg) {
|
||||||
const TargetData &TD = TM.getTargetData();
|
const TargetData &TD = TM.getTargetData();
|
||||||
if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(Src))
|
|
||||||
Src = CPR->getValue();
|
|
||||||
|
|
||||||
// If this is a getelementptr null, with all constant integer indices, just
|
// If this is a getelementptr null, with all constant integer indices, just
|
||||||
// replace it with TargetReg = 42.
|
// replace it with TargetReg = 42.
|
||||||
|
|
|
@ -178,10 +178,10 @@ void Printer::emitConstantValueOnly(const Constant *CV) {
|
||||||
O << (unsigned long long)CI->getValue();
|
O << (unsigned long long)CI->getValue();
|
||||||
else if (const ConstantUInt *CI = dyn_cast<ConstantUInt>(CV))
|
else if (const ConstantUInt *CI = dyn_cast<ConstantUInt>(CV))
|
||||||
O << CI->getValue();
|
O << CI->getValue();
|
||||||
else if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(CV))
|
else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV))
|
||||||
// This is a constant address for a global variable or function. Use the
|
// This is a constant address for a global variable or function. Use the
|
||||||
// name of the variable or function as the address value.
|
// name of the variable or function as the address value.
|
||||||
O << Mang->getValueName(CPR->getValue());
|
O << Mang->getValueName(GV);
|
||||||
else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
|
else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
|
||||||
const TargetData &TD = TM.getTargetData();
|
const TargetData &TD = TM.getTargetData();
|
||||||
switch(CE->getOpcode()) {
|
switch(CE->getOpcode()) {
|
||||||
|
|
|
@ -316,13 +316,13 @@ namespace {
|
||||||
// If this operand is a constant, emit the code to copy the constant into
|
// If this operand is a constant, emit the code to copy the constant into
|
||||||
// the register here...
|
// the register here...
|
||||||
//
|
//
|
||||||
if (Constant *C = dyn_cast<Constant>(V)) {
|
if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
|
||||||
copyConstantToRegister(MBB, IPt, C, Reg);
|
|
||||||
RegMap.erase(V); // Assign a new name to this constant if ref'd again
|
|
||||||
} else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
|
|
||||||
// Move the address of the global into the register
|
// Move the address of the global into the register
|
||||||
BuildMI(*MBB, IPt, X86::MOV32ri, 1, Reg).addGlobalAddress(GV);
|
BuildMI(*MBB, IPt, X86::MOV32ri, 1, Reg).addGlobalAddress(GV);
|
||||||
RegMap.erase(V); // Assign a new name to this address if ref'd again
|
RegMap.erase(V); // Assign a new name to this address if ref'd again
|
||||||
|
} else if (Constant *C = dyn_cast<Constant>(V)) {
|
||||||
|
copyConstantToRegister(MBB, IPt, C, Reg);
|
||||||
|
RegMap.erase(V); // Assign a new name to this constant if ref'd again
|
||||||
}
|
}
|
||||||
|
|
||||||
return Reg;
|
return Reg;
|
||||||
|
@ -480,8 +480,8 @@ void ISel::copyConstantToRegister(MachineBasicBlock *MBB,
|
||||||
} else if (isa<ConstantPointerNull>(C)) {
|
} else if (isa<ConstantPointerNull>(C)) {
|
||||||
// Copy zero (null pointer) to the register.
|
// Copy zero (null pointer) to the register.
|
||||||
BuildMI(*MBB, IP, X86::MOV32ri, 1, R).addImm(0);
|
BuildMI(*MBB, IP, X86::MOV32ri, 1, R).addImm(0);
|
||||||
} else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(C)) {
|
} else if (GlobalValue *GV = dyn_cast<GlobalValue>(C)) {
|
||||||
BuildMI(*MBB, IP, X86::MOV32ri, 1, R).addGlobalAddress(CPR->getValue());
|
BuildMI(*MBB, IP, X86::MOV32ri, 1, R).addGlobalAddress(GV);
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "Offending constant: " << *C << "\n";
|
std::cerr << "Offending constant: " << *C << "\n";
|
||||||
assert(0 && "Type not handled yet!");
|
assert(0 && "Type not handled yet!");
|
||||||
|
@ -602,7 +602,7 @@ void ISel::SelectPHINodes() {
|
||||||
|
|
||||||
// If this is a constant or GlobalValue, we may have to insert code
|
// If this is a constant or GlobalValue, we may have to insert code
|
||||||
// into the basic block to compute it into a virtual register.
|
// into the basic block to compute it into a virtual register.
|
||||||
if (isa<Constant>(Val) || isa<GlobalValue>(Val)) {
|
if (isa<Constant>(Val)) {
|
||||||
// Because we don't want to clobber any values which might be in
|
// Because we don't want to clobber any values which might be in
|
||||||
// physical registers with the computation of this constant (which
|
// physical registers with the computation of this constant (which
|
||||||
// might be arbitrarily complex if it is a constant expression),
|
// might be arbitrarily complex if it is a constant expression),
|
||||||
|
@ -2589,9 +2589,6 @@ bool ISel::isGEPFoldable(MachineBasicBlock *MBB,
|
||||||
Value *Src, User::op_iterator IdxBegin,
|
Value *Src, User::op_iterator IdxBegin,
|
||||||
User::op_iterator IdxEnd, unsigned &BaseReg,
|
User::op_iterator IdxEnd, unsigned &BaseReg,
|
||||||
unsigned &Scale, unsigned &IndexReg, unsigned &Disp) {
|
unsigned &Scale, unsigned &IndexReg, unsigned &Disp) {
|
||||||
if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(Src))
|
|
||||||
Src = CPR->getValue();
|
|
||||||
|
|
||||||
std::vector<Value*> GEPOps;
|
std::vector<Value*> GEPOps;
|
||||||
GEPOps.resize(IdxEnd-IdxBegin+1);
|
GEPOps.resize(IdxEnd-IdxBegin+1);
|
||||||
GEPOps[0] = Src;
|
GEPOps[0] = Src;
|
||||||
|
@ -2614,8 +2611,6 @@ void ISel::emitGEPOperation(MachineBasicBlock *MBB,
|
||||||
Value *Src, User::op_iterator IdxBegin,
|
Value *Src, User::op_iterator IdxBegin,
|
||||||
User::op_iterator IdxEnd, unsigned TargetReg) {
|
User::op_iterator IdxEnd, unsigned TargetReg) {
|
||||||
const TargetData &TD = TM.getTargetData();
|
const TargetData &TD = TM.getTargetData();
|
||||||
if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(Src))
|
|
||||||
Src = CPR->getValue();
|
|
||||||
|
|
||||||
std::vector<Value*> GEPOps;
|
std::vector<Value*> GEPOps;
|
||||||
GEPOps.resize(IdxEnd-IdxBegin+1);
|
GEPOps.resize(IdxEnd-IdxBegin+1);
|
||||||
|
|
|
@ -2457,11 +2457,10 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
|
||||||
if (!isa<ConstantExpr>(CS.getCalledValue())) return false;
|
if (!isa<ConstantExpr>(CS.getCalledValue())) return false;
|
||||||
ConstantExpr *CE = cast<ConstantExpr>(CS.getCalledValue());
|
ConstantExpr *CE = cast<ConstantExpr>(CS.getCalledValue());
|
||||||
if (CE->getOpcode() != Instruction::Cast ||
|
if (CE->getOpcode() != Instruction::Cast ||
|
||||||
!isa<ConstantPointerRef>(CE->getOperand(0)))
|
!isa<GlobalValue>(CE->getOperand(0)))
|
||||||
return false;
|
return false;
|
||||||
ConstantPointerRef *CPR = cast<ConstantPointerRef>(CE->getOperand(0));
|
if (!isa<Function>(CE->getOperand(0))) return false;
|
||||||
if (!isa<Function>(CPR->getValue())) return false;
|
Function *Callee = cast<Function>(CE->getOperand(0));
|
||||||
Function *Callee = cast<Function>(CPR->getValue());
|
|
||||||
Instruction *Caller = CS.getInstruction();
|
Instruction *Caller = CS.getInstruction();
|
||||||
|
|
||||||
// Okay, this is a cast from a function to a different type. Unless doing so
|
// Okay, this is a cast from a function to a different type. Unless doing so
|
||||||
|
@ -2811,7 +2810,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
|
||||||
|
|
||||||
if (I == E) { // If they are all constants...
|
if (I == E) { // If they are all constants...
|
||||||
Constant *CE =
|
Constant *CE =
|
||||||
ConstantExpr::getGetElementPtr(ConstantPointerRef::get(GV), Indices);
|
ConstantExpr::getGetElementPtr(GV, Indices);
|
||||||
|
|
||||||
// Replace all uses of the GEP with the new constexpr...
|
// Replace all uses of the GEP with the new constexpr...
|
||||||
return ReplaceInstUsesWith(GEP, CE);
|
return ReplaceInstUsesWith(GEP, CE);
|
||||||
|
@ -2978,8 +2977,8 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
|
||||||
if (Constant *C = dyn_cast<Constant>(Op))
|
if (Constant *C = dyn_cast<Constant>(Op))
|
||||||
if (C->isNullValue()) // load null -> 0
|
if (C->isNullValue()) // load null -> 0
|
||||||
return ReplaceInstUsesWith(LI, Constant::getNullValue(LI.getType()));
|
return ReplaceInstUsesWith(LI, Constant::getNullValue(LI.getType()));
|
||||||
else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(C))
|
else if (isa<GlobalValue>(C))
|
||||||
Op = CPR->getValue();
|
Op = C;
|
||||||
|
|
||||||
// Instcombine load (constant global) into the value loaded...
|
// Instcombine load (constant global) into the value loaded...
|
||||||
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Op))
|
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Op))
|
||||||
|
@ -2989,8 +2988,7 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
|
||||||
// Instcombine load (constantexpr_GEP global, 0, ...) into the value loaded...
|
// Instcombine load (constantexpr_GEP global, 0, ...) into the value loaded...
|
||||||
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Op))
|
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Op))
|
||||||
if (CE->getOpcode() == Instruction::GetElementPtr) {
|
if (CE->getOpcode() == Instruction::GetElementPtr) {
|
||||||
if (ConstantPointerRef *G=dyn_cast<ConstantPointerRef>(CE->getOperand(0)))
|
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(CE->getOperand(0)))
|
||||||
if (GlobalVariable *GV = dyn_cast<GlobalVariable>(G->getValue()))
|
|
||||||
if (GV->isConstant() && !GV->isExternal())
|
if (GV->isConstant() && !GV->isExternal())
|
||||||
if (Constant *V = GetGEPGlobalInitializer(GV->getInitializer(), CE))
|
if (Constant *V = GetGEPGlobalInitializer(GV->getInitializer(), CE))
|
||||||
return ReplaceInstUsesWith(LI, V);
|
return ReplaceInstUsesWith(LI, V);
|
||||||
|
@ -3106,12 +3104,11 @@ bool InstCombiner::runOnFunction(Function &F) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check to see if any of the operands of this instruction are a
|
// Check to see if any of the operands of this instruction are a
|
||||||
// ConstantPointerRef. Since they sneak in all over the place and inhibit
|
// GlobalValue. Since they sneak in all over the place and inhibit
|
||||||
// optimization, we want to strip them out unconditionally!
|
// optimization, we want to strip them out unconditionally!
|
||||||
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
|
for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
|
||||||
if (ConstantPointerRef *CPR =
|
if (isa<GlobalValue>(I->getOperand(i))) {
|
||||||
dyn_cast<ConstantPointerRef>(I->getOperand(i))) {
|
I->setOperand(i, I->getOperand(i));
|
||||||
I->setOperand(i, CPR->getValue());
|
|
||||||
Changed = true;
|
Changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue