Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8031743

C2: loadI2L_immI broken for negative memory values

XMLWordPrintable

    • b68
    • generic
    • generic
    • Verified

        instruct loadI2L_immI(iRegL dst, memory mem, immI mask, iRegI tmp) %{
          match(Set dst (ConvI2L (AndI (LoadI mem) mask)));

        From inspection, it appears that this rule (on all platforms) only works if the result of the AndI
        doesn't need to be sign-extended (>= 0). My first attempt at a test program didn't work. For
        some reason when using an array, C2 only takes a fast path if the value is positive:

            static long foo(int[] x) {
                return x[0] & 0xfffffffe;
            }

        However, using a field instead doesn't have that problem.

        % cat a.java
        public class a {
            static int x;
            static long foo() {
                return x & 0xfffffffe;
            }

            public static void main(String[] args) {
                x = -1;
                long l = 0;
                for (int i = 0; i < 100000; ++i) {
                    l = foo();
                }
                System.out.println(l);
            }
        }
        % ./bin/java -Xint a
        -2
        % ./bin/java -XX:-TieredCompilation -server a
        4294967294

              iveresov Igor Veresov
              dlong Dean Long
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: