From 8c293deaadbe12c0a4a0f5d63b60888c22d043bf Mon Sep 17 00:00:00 2001 From: Misha Brukman Date: Wed, 28 Jul 2004 00:56:04 +0000 Subject: [PATCH] LI can only take signed values, so values > 32767 can only be loaded with ORI llvm-svn: 15299 --- lib/Target/PowerPC/PPC32ISelSimple.cpp | 8 +++++++- lib/Target/PowerPC/PowerPCISelSimple.cpp | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/Target/PowerPC/PPC32ISelSimple.cpp b/lib/Target/PowerPC/PPC32ISelSimple.cpp index 062df545fc9..790aab42c55 100644 --- a/lib/Target/PowerPC/PPC32ISelSimple.cpp +++ b/lib/Target/PowerPC/PPC32ISelSimple.cpp @@ -555,7 +555,13 @@ void ISel::copyConstantToRegister(MachineBasicBlock *MBB, BuildMI(*MBB, IP, PPC32::ORI, 2, R+1).addReg(Temp).addImm(Val & 0xFFFF); } else if (Val < (1ULL << 48)) { unsigned Temp = makeAnotherReg(Type::IntTy); - BuildMI(*MBB, IP, PPC32::LI, 1, R).addSImm((Val >> 32) & 0xFFFF); + int HiBits = (Val >> 32) & 0xFFFF; + if (HiBits > 32767) { + BuildMI(*MBB, IP, PPC32::LI, 1, PPC32::R0).addImm(0); + BuildMI(*MBB, IP, PPC32::ORI, 2, R).addReg(PPC32::R0).addSImm(HiBits); + } else { + BuildMI(*MBB, IP, PPC32::LI, 1, R).addSImm(HiBits); + } BuildMI(*MBB, IP, PPC32::LIS, 1, Temp).addSImm((Val >> 16) & 0xFFFF); BuildMI(*MBB, IP, PPC32::ORI, 2, R+1).addReg(Temp).addImm(Val & 0xFFFF); } else { diff --git a/lib/Target/PowerPC/PowerPCISelSimple.cpp b/lib/Target/PowerPC/PowerPCISelSimple.cpp index 062df545fc9..790aab42c55 100644 --- a/lib/Target/PowerPC/PowerPCISelSimple.cpp +++ b/lib/Target/PowerPC/PowerPCISelSimple.cpp @@ -555,7 +555,13 @@ void ISel::copyConstantToRegister(MachineBasicBlock *MBB, BuildMI(*MBB, IP, PPC32::ORI, 2, R+1).addReg(Temp).addImm(Val & 0xFFFF); } else if (Val < (1ULL << 48)) { unsigned Temp = makeAnotherReg(Type::IntTy); - BuildMI(*MBB, IP, PPC32::LI, 1, R).addSImm((Val >> 32) & 0xFFFF); + int HiBits = (Val >> 32) & 0xFFFF; + if (HiBits > 32767) { + BuildMI(*MBB, IP, PPC32::LI, 1, PPC32::R0).addImm(0); + BuildMI(*MBB, IP, PPC32::ORI, 2, R).addReg(PPC32::R0).addSImm(HiBits); + } else { + BuildMI(*MBB, IP, PPC32::LI, 1, R).addSImm(HiBits); + } BuildMI(*MBB, IP, PPC32::LIS, 1, Temp).addSImm((Val >> 16) & 0xFFFF); BuildMI(*MBB, IP, PPC32::ORI, 2, R+1).addReg(Temp).addImm(Val & 0xFFFF); } else {