[vmkit-commits] [PATCH] Fix LSHR by masking the shift operand.

Will Dietz wdietz2 at illinois.edu
Mon Nov 7 12:16:14 PST 2011


Same thing as previous LSHL patch, only for LSHR.

~Will

>From fc51294c2ddb78189092fd87ed4950ecdb6f43c0 Mon Sep 17 00:00:00 2001
From: Will Dietz <w at wdtz.org>
Date: Mon, 7 Nov 2011 13:56:25 -0600
Subject: [PATCH] Fix LSHR by masking the shift operand.

Sample test case:

class Test {
    public static void main(String[] args) {
      long l = 1;
      System.out.println(l);
      System.out.println(l >> 10);
      System.out.println(l >> 32);
      System.out.println(l >> 64);
      System.out.println(l >> 128);
      System.out.println(l >> -10);
    }
}

java produces (Hotspot 1.6.0_27):
1
0
0
1
1
0

j3 before this patch produces:
1
0
0
0
0
0
---
 lib/J3/Compiler/JavaJITOpcodes.cpp |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/lib/J3/Compiler/JavaJITOpcodes.cpp
b/lib/J3/Compiler/JavaJITOpcodes.cpp
index 93b9c3c..682e406 100644
--- a/lib/J3/Compiler/JavaJITOpcodes.cpp
+++ b/lib/J3/Compiler/JavaJITOpcodes.cpp
@@ -1207,6 +1207,8 @@ void JavaJIT::compileOpcodes(Reader& reader,
uint32 codeLength) {

       case LSHR : {
         Value* val2 = new ZExtInst(pop(),
Type::getInt64Ty(*llvmContext), "", currentBlock);
+        Value* mask = ConstantInt::get(Type::getInt64Ty(*llvmContext), 0x3F);
+        val2 = BinaryOperator::CreateAnd(val2, mask, "", currentBlock);
         pop(); // remove the 0 on the stack
         Value* val1 = pop();
         push(BinaryOperator::CreateAShr(val1, val2, "", currentBlock),
-- 
1.7.5.1



More information about the vmkit-commits mailing list