From 1c10f17552c4794d65c8d0019a4111b367518be6 Mon Sep 17 00:00:00 2001 From: "Vikram S. Adve" Date: Fri, 27 Sep 2002 14:26:20 +0000 Subject: [PATCH] Sign-extend integer constants from original type size to 64 bits! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3958 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../InstrSelection/InstrSelectionSupport.cpp | 14 +++++++++----- .../InstrSelection/InstrSelectionSupport.cpp | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/CodeGen/InstrSelection/InstrSelectionSupport.cpp b/lib/CodeGen/InstrSelection/InstrSelectionSupport.cpp index 508c0b6e5e0..a8f14e20bca 100644 --- a/lib/CodeGen/InstrSelection/InstrSelectionSupport.cpp +++ b/lib/CodeGen/InstrSelection/InstrSelectionSupport.cpp @@ -373,11 +373,15 @@ ChooseRegOrImmed(Value* val, else if (CPV->getType()->isSigned()) intValue = cast(CPV)->getValue(); else - { - assert(CPV->getType()->isUnsigned() && "Not pointer, bool, or integer?"); - uint64_t V = cast(CPV)->getValue(); - if (V >= INT64_MAX) return MachineOperand::MO_VirtualRegister; - intValue = (int64_t) V; + { // get the int value and sign-extend if original was less than 64 bits + intValue = (int64_t) cast(CPV)->getValue(); + switch(CPV->getType()->getPrimitiveID()) + { + case Type::UByteTyID: intValue = (int64_t) (int8_t) intValue; break; + case Type::UShortTyID: intValue = (int64_t) (short) intValue; break; + case Type::UIntTyID: intValue = (int64_t) (int) intValue; break; + default: break; + } } return ChooseRegOrImmed(intValue, CPV->getType()->isSigned(), diff --git a/lib/Target/SparcV9/InstrSelection/InstrSelectionSupport.cpp b/lib/Target/SparcV9/InstrSelection/InstrSelectionSupport.cpp index 508c0b6e5e0..a8f14e20bca 100644 --- a/lib/Target/SparcV9/InstrSelection/InstrSelectionSupport.cpp +++ b/lib/Target/SparcV9/InstrSelection/InstrSelectionSupport.cpp @@ -373,11 +373,15 @@ ChooseRegOrImmed(Value* val, else if (CPV->getType()->isSigned()) intValue = cast(CPV)->getValue(); else - { - assert(CPV->getType()->isUnsigned() && "Not pointer, bool, or integer?"); - uint64_t V = cast(CPV)->getValue(); - if (V >= INT64_MAX) return MachineOperand::MO_VirtualRegister; - intValue = (int64_t) V; + { // get the int value and sign-extend if original was less than 64 bits + intValue = (int64_t) cast(CPV)->getValue(); + switch(CPV->getType()->getPrimitiveID()) + { + case Type::UByteTyID: intValue = (int64_t) (int8_t) intValue; break; + case Type::UShortTyID: intValue = (int64_t) (short) intValue; break; + case Type::UIntTyID: intValue = (int64_t) (int) intValue; break; + default: break; + } } return ChooseRegOrImmed(intValue, CPV->getType()->isSigned(), -- 2.34.1