From: Brian Gaeke Date: Thu, 24 Jun 2004 09:17:47 +0000 (+0000) Subject: Fix a dyn_cast in copyConstantToRegister which should have been a cast. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=13dc433df3cc0a6fa101d56ae61deea49be578b1;p=oota-llvm.git Fix a dyn_cast in copyConstantToRegister which should have been a cast. Compactify the code that emits copies of constant ints into registers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14365 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/Sparc/InstSelectSimple.cpp b/lib/Target/Sparc/InstSelectSimple.cpp index 9d79ae8a7b2..bbfe3cb65f5 100644 --- a/lib/Target/Sparc/InstSelectSimple.cpp +++ b/lib/Target/Sparc/InstSelectSimple.cpp @@ -253,33 +253,30 @@ void V8ISel::copyConstantToRegister(MachineBasicBlock *MBB, if (C->getType() == Type::BoolTy) { Val = (C == ConstantBool::True); } else { - ConstantInt *CI = dyn_cast (C); + ConstantInt *CI = cast (C); Val = CI->getRawValue (); } switch (Class) { - case cByte: - BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (V8::G0).addSImm((uint8_t)Val); - return; - case cShort: { - unsigned TmpReg = makeAnotherReg (C->getType ()); - BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg) - .addSImm (((uint16_t) Val) >> 10); - BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg) - .addSImm (((uint16_t) Val) & 0x03ff); - return; - } - case cInt: { - unsigned TmpReg = makeAnotherReg (C->getType ()); - BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg).addZImm(((uint32_t)Val) >> 10); - BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg) - .addSImm (((uint32_t) Val) & 0x03ff); - return; - } + case cByte: Val = (int8_t) Val; break; + case cShort: Val = (int16_t) Val; break; + case cInt: Val = (int32_t) Val; break; default: std::cerr << "Offending constant: " << *C << "\n"; assert (0 && "Can't copy this kind of constant into register yet"); return; } + if (Val == 0) { + BuildMI (*MBB, IP, V8::ORrr, 2, R).addReg (V8::G0).addReg(V8::G0); + } else if (((int64_t)Val >= -4096) && ((int64_t)Val <= 4095)) { + BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (V8::G0).addSImm(Val); + } else { + unsigned TmpReg = makeAnotherReg (C->getType ()); + BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg) + .addSImm (((uint32_t) Val) >> 10); + BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg) + .addSImm (((uint32_t) Val) & 0x03ff); + return; + } } else if (ConstantFP *CFP = dyn_cast(C)) { // We need to spill the constant to memory... MachineConstantPool *CP = F->getConstantPool(); diff --git a/lib/Target/Sparc/SparcV8ISelSimple.cpp b/lib/Target/Sparc/SparcV8ISelSimple.cpp index 9d79ae8a7b2..bbfe3cb65f5 100644 --- a/lib/Target/Sparc/SparcV8ISelSimple.cpp +++ b/lib/Target/Sparc/SparcV8ISelSimple.cpp @@ -253,33 +253,30 @@ void V8ISel::copyConstantToRegister(MachineBasicBlock *MBB, if (C->getType() == Type::BoolTy) { Val = (C == ConstantBool::True); } else { - ConstantInt *CI = dyn_cast (C); + ConstantInt *CI = cast (C); Val = CI->getRawValue (); } switch (Class) { - case cByte: - BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (V8::G0).addSImm((uint8_t)Val); - return; - case cShort: { - unsigned TmpReg = makeAnotherReg (C->getType ()); - BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg) - .addSImm (((uint16_t) Val) >> 10); - BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg) - .addSImm (((uint16_t) Val) & 0x03ff); - return; - } - case cInt: { - unsigned TmpReg = makeAnotherReg (C->getType ()); - BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg).addZImm(((uint32_t)Val) >> 10); - BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg) - .addSImm (((uint32_t) Val) & 0x03ff); - return; - } + case cByte: Val = (int8_t) Val; break; + case cShort: Val = (int16_t) Val; break; + case cInt: Val = (int32_t) Val; break; default: std::cerr << "Offending constant: " << *C << "\n"; assert (0 && "Can't copy this kind of constant into register yet"); return; } + if (Val == 0) { + BuildMI (*MBB, IP, V8::ORrr, 2, R).addReg (V8::G0).addReg(V8::G0); + } else if (((int64_t)Val >= -4096) && ((int64_t)Val <= 4095)) { + BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (V8::G0).addSImm(Val); + } else { + unsigned TmpReg = makeAnotherReg (C->getType ()); + BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg) + .addSImm (((uint32_t) Val) >> 10); + BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg) + .addSImm (((uint32_t) Val) & 0x03ff); + return; + } } else if (ConstantFP *CFP = dyn_cast(C)) { // We need to spill the constant to memory... MachineConstantPool *CP = F->getConstantPool(); diff --git a/lib/Target/SparcV8/InstSelectSimple.cpp b/lib/Target/SparcV8/InstSelectSimple.cpp index 9d79ae8a7b2..bbfe3cb65f5 100644 --- a/lib/Target/SparcV8/InstSelectSimple.cpp +++ b/lib/Target/SparcV8/InstSelectSimple.cpp @@ -253,33 +253,30 @@ void V8ISel::copyConstantToRegister(MachineBasicBlock *MBB, if (C->getType() == Type::BoolTy) { Val = (C == ConstantBool::True); } else { - ConstantInt *CI = dyn_cast (C); + ConstantInt *CI = cast (C); Val = CI->getRawValue (); } switch (Class) { - case cByte: - BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (V8::G0).addSImm((uint8_t)Val); - return; - case cShort: { - unsigned TmpReg = makeAnotherReg (C->getType ()); - BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg) - .addSImm (((uint16_t) Val) >> 10); - BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg) - .addSImm (((uint16_t) Val) & 0x03ff); - return; - } - case cInt: { - unsigned TmpReg = makeAnotherReg (C->getType ()); - BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg).addZImm(((uint32_t)Val) >> 10); - BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg) - .addSImm (((uint32_t) Val) & 0x03ff); - return; - } + case cByte: Val = (int8_t) Val; break; + case cShort: Val = (int16_t) Val; break; + case cInt: Val = (int32_t) Val; break; default: std::cerr << "Offending constant: " << *C << "\n"; assert (0 && "Can't copy this kind of constant into register yet"); return; } + if (Val == 0) { + BuildMI (*MBB, IP, V8::ORrr, 2, R).addReg (V8::G0).addReg(V8::G0); + } else if (((int64_t)Val >= -4096) && ((int64_t)Val <= 4095)) { + BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (V8::G0).addSImm(Val); + } else { + unsigned TmpReg = makeAnotherReg (C->getType ()); + BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg) + .addSImm (((uint32_t) Val) >> 10); + BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg) + .addSImm (((uint32_t) Val) & 0x03ff); + return; + } } else if (ConstantFP *CFP = dyn_cast(C)) { // We need to spill the constant to memory... MachineConstantPool *CP = F->getConstantPool(); diff --git a/lib/Target/SparcV8/SparcV8ISelSimple.cpp b/lib/Target/SparcV8/SparcV8ISelSimple.cpp index 9d79ae8a7b2..bbfe3cb65f5 100644 --- a/lib/Target/SparcV8/SparcV8ISelSimple.cpp +++ b/lib/Target/SparcV8/SparcV8ISelSimple.cpp @@ -253,33 +253,30 @@ void V8ISel::copyConstantToRegister(MachineBasicBlock *MBB, if (C->getType() == Type::BoolTy) { Val = (C == ConstantBool::True); } else { - ConstantInt *CI = dyn_cast (C); + ConstantInt *CI = cast (C); Val = CI->getRawValue (); } switch (Class) { - case cByte: - BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (V8::G0).addSImm((uint8_t)Val); - return; - case cShort: { - unsigned TmpReg = makeAnotherReg (C->getType ()); - BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg) - .addSImm (((uint16_t) Val) >> 10); - BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg) - .addSImm (((uint16_t) Val) & 0x03ff); - return; - } - case cInt: { - unsigned TmpReg = makeAnotherReg (C->getType ()); - BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg).addZImm(((uint32_t)Val) >> 10); - BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg) - .addSImm (((uint32_t) Val) & 0x03ff); - return; - } + case cByte: Val = (int8_t) Val; break; + case cShort: Val = (int16_t) Val; break; + case cInt: Val = (int32_t) Val; break; default: std::cerr << "Offending constant: " << *C << "\n"; assert (0 && "Can't copy this kind of constant into register yet"); return; } + if (Val == 0) { + BuildMI (*MBB, IP, V8::ORrr, 2, R).addReg (V8::G0).addReg(V8::G0); + } else if (((int64_t)Val >= -4096) && ((int64_t)Val <= 4095)) { + BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (V8::G0).addSImm(Val); + } else { + unsigned TmpReg = makeAnotherReg (C->getType ()); + BuildMI (*MBB, IP, V8::SETHIi, 1, TmpReg) + .addSImm (((uint32_t) Val) >> 10); + BuildMI (*MBB, IP, V8::ORri, 2, R).addReg (TmpReg) + .addSImm (((uint32_t) Val) & 0x03ff); + return; + } } else if (ConstantFP *CFP = dyn_cast(C)) { // We need to spill the constant to memory... MachineConstantPool *CP = F->getConstantPool();