[vmkit-commits] [PATCH] Fix LSHL to mask the shift operand.

Nicolas Geoffray nicolas.geoffray at gmail.com
Tue Nov 8 12:51:28 PST 2011


Nice! Please apply.

On Mon, Nov 7, 2011 at 9:14 PM, Will Dietz <wdietz2 at illinois.edu> wrote:

> Inlined below.
>
> The masking logic is already used in LUSHR, FWIW.
>
> ~Will
>
> >From 029662fa7bd23532d8a5be59793efab715217356 Mon Sep 17 00:00:00 2001
> From: Will Dietz <w at wdtz.org>
> Date: Sun, 6 Nov 2011 23:26:17 -0600
> Subject: [PATCH] Fix LSHL to mask the shift operand.
>
> Simple test case illustrating failure:
>
> 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);
>    }
> }
>

Could you add this test to the tests/ directory? Just do simple comparisons
between what is expected and what you get. If they don't match, throw an
exception.


> Should produce (java Hotspot 1.6.0_27)
> 1
> 1024
> 4294967296
> 1
> 1
> 18014398509481984
>
> Before this patch j3 produces:
> 1
> 1024
> 4294967296
> 4294967296
> 4294967296
> 4294967296
>
> This patch aligns j3 with java's behavior.
> Additionally, this causes j3 to pass Mauve's Long tests.
>

Very nice!


> ---
>  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 4c5e8cd..93b9c3c 100644
> --- a/lib/J3/Compiler/JavaJITOpcodes.cpp
> +++ b/lib/J3/Compiler/JavaJITOpcodes.cpp
> @@ -1185,6 +1185,8 @@ void JavaJIT::compileOpcodes(Reader& reader,
> uint32 codeLength) {
>
>       case LSHL : {
>         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::CreateShl(val1, val2, "", currentBlock),
> --
> 1.7.5.1
>
> _______________________________________________
> vmkit-commits mailing list
> vmkit-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/vmkit-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/vmkit-commits/attachments/20111108/8deb4717/attachment.html>


More information about the vmkit-commits mailing list