Bug in LIRGenerator::generate_address on sparc?

Gary Benson gbenson at redhat.com
Mon Nov 26 07:04:57 PST 2007


Hi all,

I'm currently working on porting c1 to PPC.  I copied the sparc
implementation of LIRGenerator::generate_address, and at first
I thought it was wasting a register when called with a register
index, nonzero shift and nonzero simm13 displacement, but as I
looked at it it seems broken.  It does this:

  LIR_Opr tmp = new_register(T_INT);
  __ add(tmp, LIR_OprFact::intConst(disp), tmp);

which as far as I can see is starting with a random value in tmp.
I guess this particular case doesn't get used, but here is my
(untested) fix for both the bug and the register wastage.

Cheers,
Gary
-------------- next part --------------
diff -r 8bf719a5aa0c openjdk/hotspot/src/cpu/sparc/vm/c1_LIRGenerator_sparc.cpp
--- a/openjdk/hotspot/src/cpu/sparc/vm/c1_LIRGenerator_sparc.cpp	Mon Nov 26 14:56:30 2007 +0000
+++ b/openjdk/hotspot/src/cpu/sparc/vm/c1_LIRGenerator_sparc.cpp	Mon Nov 26 14:57:58 2007 +0000
@@ -149,11 +149,17 @@ LIR_Address* LIRGenerator::generate_addr
       index = tmp;
     }
     if (disp != 0) {
-      LIR_Opr tmp = new_register(T_INT);
       if (Assembler::is_simm13(disp)) {
-        __ add(tmp, LIR_OprFact::intConst(disp), tmp);
-        index = tmp;
+        if (shift > 0) {
+          __ add(index, LIR_OprFact::intConst(disp), index);
+        }
+        else {
+          LIR_Opr tmp = new_register(T_INT);
+          __ add(index, LIR_OprFact::intConst(disp), tmp);    
+          index = tmp;
+        }
       } else {
+        LIR_Opr tmp = new_register(T_INT);
         __ move(LIR_OprFact::intConst(disp), tmp);
         __ add(tmp, index, tmp);
         index = tmp;


More information about the hotspot-compiler-dev mailing list