Removing redundant type checks from Java

Hi, LLVMers,

I am a CS student in my final year, and I would like to use LLVM in my final course project. So, I just download LLVM and VMKit, and I have been playing with both. I can produce llvm bytecodes from java programs, and now my idea is to remove redundant type checks from the code. For instance, if we consider a program like this:

if (o instanceof A) {
A a = (A) o;
// do something with a
}

we see that Java will put a type test before the cast, but this test is unnecessary, as we already know that we have passed the instanceof test. So, as my project I would like to remove these redundant tests. My questions:

  1. Has this already been done by some of the VMKit optimizing passes?
  2. If not, is this feasible?
  3. Is this the right list to ask questions about VMKit?

All the best,

Alysson

Hi Alysson,

Alysson wrote:

Hi, LLVMers,

    I am a CS student in my final year, and I would like to use LLVM in my final course project. So, I just download LLVM and VMKit, and I have been playing with both. I can produce llvm bytecodes from java programs, and now my idea is to remove redundant type checks from the code. For instance, if we consider a program like this:

if (o instanceof A) {
  A a = (A) o;
  // do something with a
}

we see that Java will put a type test before the cast, but this test is unnecessary, as we already know that we have passed the instanceof test. So, as my project I would like to remove these redundant tests.

OK.

My questions:

1) Has this already been done by some of the VMKit optimizing passes?

I believe it must be done if you run the -gvn pass on the llvm bytecode. You can for example give the "-std-compile-opts" command line argument to vmjc.

2) If not, is this feasible?

If the -gvn pass does not remove it, you can write your own optimization pass on the llvm bytecode and detect the redundant checks. Then use the opt tool to load your pass and apply it to your llvm bytecode.

3) Is this the right list to ask questions about VMKit?

These kinds of questions, I believe yes :slight_smile:

Cheers,
Nicolas