[llvm-commits] CVS: llvm/lib/Target/X86/X86ISelSimple.cpp
Chris Lattner
lattner at cs.uiuc.edu
Tue Oct 5 21:19:54 PDT 2004
Changes in directory llvm/lib/Target/X86:
X86ISelSimple.cpp updated: 1.281 -> 1.282
---
Log message:
Fix a scary bug with signed division by a power of two. We used to generate:
s: ;; X / 4
mov %EAX, DWORD PTR [%ESP + 4]
mov %ECX, %EAX
sar %ECX, 1
shr %ECX, 30
mov %EDX, %EAX
add %EDX, %ECX
sar %EAX, 2
ret
When we really meant:
s:
mov %EAX, DWORD PTR [%ESP + 4]
mov %ECX, %EAX
sar %ECX, 1
shr %ECX, 30
add %EAX, %ECX
sar %EAX, 2
ret
Hey, this also reduces register pressure too :)
---
Diffs of the changes: (+3 -6)
Index: llvm/lib/Target/X86/X86ISelSimple.cpp
diff -u llvm/lib/Target/X86/X86ISelSimple.cpp:1.281 llvm/lib/Target/X86/X86ISelSimple.cpp:1.282
--- llvm/lib/Target/X86/X86ISelSimple.cpp:1.281 Tue Oct 5 23:02:39 2004
+++ llvm/lib/Target/X86/X86ISelSimple.cpp Tue Oct 5 23:19:43 2004
@@ -2726,11 +2726,8 @@
--Log;
unsigned Op0Reg = getReg(Op0, BB, IP);
unsigned TmpReg = makeAnotherReg(Op0->getType());
- if (Log != 1)
- BuildMI(*BB, IP, SAROpcode[Class], 2, TmpReg)
- .addReg(Op0Reg).addImm(Log-1);
- else
- BuildMI(*BB, IP, MovOpcode[Class], 1, TmpReg).addReg(Op0Reg);
+ BuildMI(*BB, IP, SAROpcode[Class], 2, TmpReg)
+ .addReg(Op0Reg).addImm(Log-1);
unsigned TmpReg2 = makeAnotherReg(Op0->getType());
BuildMI(*BB, IP, SHROpcode[Class], 2, TmpReg2)
.addReg(TmpReg).addImm(32-Log);
@@ -2740,7 +2737,7 @@
unsigned TmpReg4 = isNeg ? makeAnotherReg(Op0->getType()) : ResultReg;
BuildMI(*BB, IP, SAROpcode[Class], 2, TmpReg4)
- .addReg(Op0Reg).addImm(Log);
+ .addReg(TmpReg3).addImm(Log);
if (isNeg)
BuildMI(*BB, IP, NEGOpcode[Class], 1, ResultReg).addReg(TmpReg4);
return;
More information about the llvm-commits
mailing list