6956668: misbehavior of XOR operator (^) with int

Tue, 31 May 2011 10:05:36 -0700

author
kvn
date
Tue, 31 May 2011 10:05:36 -0700
changeset 2940
33e2b8f1d466
parent 2939
b2cb497dec28
child 2941
60b8287df30e

6956668: misbehavior of XOR operator (^) with int
Summary: optimize cmp_ne(xor(X,1),0) to cmp_eq(X,0) only for boolean values X.
Reviewed-by: never

src/share/vm/opto/subnode.cpp file | annotate | diff | comparison | revisions
test/compiler/6956668/Test6956668.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/opto/subnode.cpp	Fri May 27 12:47:48 2011 -0700
     1.2 +++ b/src/share/vm/opto/subnode.cpp	Tue May 31 10:05:36 2011 -0700
     1.3 @@ -1101,6 +1101,7 @@
     1.4    if( cmp2_type == TypeInt::ZERO &&
     1.5        cmp1_op == Op_XorI &&
     1.6        j_xor->in(1) != j_xor &&          // An xor of itself is dead
     1.7 +      phase->type( j_xor->in(1) ) == TypeInt::BOOL &&
     1.8        phase->type( j_xor->in(2) ) == TypeInt::ONE &&
     1.9        (_test._test == BoolTest::eq ||
    1.10         _test._test == BoolTest::ne) ) {
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/compiler/6956668/Test6956668.java	Tue May 31 10:05:36 2011 -0700
     2.3 @@ -0,0 +1,69 @@
     2.4 +/*
     2.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.23 + * or visit www.oracle.com if you need additional information or have any
    2.24 + * questions.
    2.25 + *
    2.26 + */
    2.27 +
    2.28 +/**
    2.29 + * @test
    2.30 + * @bug 6956668
    2.31 + * @summary misbehavior of XOR operator (^) with int
    2.32 + *
    2.33 + * @run main/othervm -Xbatch Test6956668
    2.34 + */
    2.35 +
    2.36 +
    2.37 +public class Test6956668 {
    2.38 +
    2.39 +   public static int bitTest() {
    2.40 +      int result = 0;
    2.41 +
    2.42 +      int testValue = 73;
    2.43 +      int bitCount = Integer.bitCount(testValue);
    2.44 +
    2.45 +      if (testValue != 0) {
    2.46 +         int gap = Long.numberOfTrailingZeros(testValue);
    2.47 +         testValue >>>= gap;
    2.48 +
    2.49 +         while (testValue != 0) {
    2.50 +            result++;
    2.51 +
    2.52 +            if ((testValue ^= 0x1) != 0) {
    2.53 +               gap = Long.numberOfTrailingZeros(testValue);
    2.54 +               testValue >>>= gap;
    2.55 +            }
    2.56 +         }
    2.57 +      }
    2.58 +
    2.59 +      if (bitCount != result) {
    2.60 +         System.out.println("ERROR: " + bitCount + " != " + result);
    2.61 +         System.exit(97);
    2.62 +      }
    2.63 +
    2.64 +      return (result);
    2.65 +   }
    2.66 +
    2.67 +   public static void main(String[] args) {
    2.68 +      for (int i = 0; i < 100000; i++) {
    2.69 +         int ct = bitTest();
    2.70 +      }
    2.71 +   }
    2.72 +}

mercurial