From 893cace8e2a771799b836b745a3ffc663cc00d51 Mon Sep 17 00:00:00 2001 From: "Vikram S. Adve" Date: Sun, 13 Oct 2002 00:04:26 +0000 Subject: [PATCH] Make sure to handle small negative values hiding as large unsigned longs -- this is a common case created by the front-end. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4127 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/SparcV9/SparcV9InstrInfo.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/Target/SparcV9/SparcV9InstrInfo.cpp b/lib/Target/SparcV9/SparcV9InstrInfo.cpp index 993f2a2ffa1..148b76ef5a0 100644 --- a/lib/Target/SparcV9/SparcV9InstrInfo.cpp +++ b/lib/Target/SparcV9/SparcV9InstrInfo.cpp @@ -266,7 +266,7 @@ CreateIntSetInstruction(const TargetMachine& target, // Entry == 0 ==> no immediate constant field exists at all. // Entry > 0 ==> abs(immediate constant) <= Entry // -vector MaxConstantsTable(Instruction::NumOtherOps); +vector MaxConstantsTable(Instruction::NumOtherOps); static int MaxConstantForInstr(unsigned llvmOpCode) @@ -343,13 +343,14 @@ UltraSparcInstrInfo::ConstantMayNotFitInImmedField(const Constant* CV, return false; if (const ConstantUInt* U = dyn_cast(CV)) - return (U->getValue() > MaxConstantsTable[I->getOpcode()]); + /* Large unsigned longs may really just be small negative signed longs */ + return (labs((int64_t) U->getValue()) > MaxConstantsTable[I->getOpcode()]); if (const ConstantSInt* S = dyn_cast(CV)) - return (labs(S->getValue()) > (int) MaxConstantsTable[I->getOpcode()]); + return (labs(S->getValue()) > MaxConstantsTable[I->getOpcode()]); if (isa(CV)) - return (1U > MaxConstantsTable[I->getOpcode()]); + return (1 > MaxConstantsTable[I->getOpcode()]); return true; } @@ -380,6 +381,11 @@ UltraSparcInstrInfo::CreateCodeToLoadConst(const TargetMachine& target, // const Type* valType = val->getType(); + // Unfortunate special case: a ConstantPointerRef is just a + // reference to GlobalValue. + if (isa(val)) + val = cast(val)->getValue(); + if (isa(val)) { TmpInstruction* tmpReg =