Fri, 08 Jan 2010 09:51:24 -0800
6910484: incorrect integer optimization (loosing and op-r in a given example)
Summary: Remove AND operation only if mask is equal to shift.
Reviewed-by: never
src/share/vm/opto/divnode.cpp | file | annotate | diff | comparison | revisions | |
test/compiler/6910484/Test.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/vm/opto/divnode.cpp Fri Jan 08 09:42:31 2010 -0800 1.2 +++ b/src/share/vm/opto/divnode.cpp Fri Jan 08 09:51:24 2010 -0800 1.3 @@ -114,7 +114,8 @@ 1.4 if( andconi_t && andconi_t->is_con() ) { 1.5 jint andconi = andconi_t->get_con(); 1.6 if( andconi < 0 && is_power_of_2(-andconi) && (-andconi) >= d ) { 1.7 - dividend = dividend->in(1); 1.8 + if( (-andconi) == d ) // Remove AND if it clears bits which will be shifted 1.9 + dividend = dividend->in(1); 1.10 needs_rounding = false; 1.11 } 1.12 } 1.13 @@ -356,7 +357,8 @@ 1.14 if( andconl_t && andconl_t->is_con() ) { 1.15 jlong andconl = andconl_t->get_con(); 1.16 if( andconl < 0 && is_power_of_2_long(-andconl) && (-andconl) >= d ) { 1.17 - dividend = dividend->in(1); 1.18 + if( (-andconl) == d ) // Remove AND if it clears bits which will be shifted 1.19 + dividend = dividend->in(1); 1.20 needs_rounding = false; 1.21 } 1.22 }
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/compiler/6910484/Test.java Fri Jan 08 09:51:24 2010 -0800 2.3 @@ -0,0 +1,50 @@ 2.4 +/* 2.5 + * Copyright 2009 SAP. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 2.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 2.24 + * have any questions. 2.25 + */ 2.26 + 2.27 +/** 2.28 + * @test 2.29 + * @bug 6910484 2.30 + * @summary incorrect integer optimization (loosing and op-r in a given example) 2.31 + * 2.32 + * @run main/othervm -Xbatch Test 2.33 + */ 2.34 + 2.35 +public class Test { 2.36 + 2.37 + public static void main(String[] args) { 2.38 + long iteration = 0; 2.39 + for(int i = 0; i <11000; i++) { 2.40 + iteration++; 2.41 + int result = test(255); 2.42 + if (result != 112) { 2.43 + System.out.println("expected 112, but got " + result + " after iteration " + iteration); 2.44 + System.exit(97); 2.45 + } 2.46 + } 2.47 + } 2.48 + 2.49 + private static int test(int x) { 2.50 + return (x & -32) / 2; 2.51 + } 2.52 + 2.53 +}