8080190: PPC64: Fix wrong rotate instructions in the .ad file
authorsimonis
Tue, 19 May 2015 11:06:34 +0200
changeset 30758 97072ce7c6fe
parent 30757 e7a31a64425a
child 30759 0bd5569bbfe6
8080190: PPC64: Fix wrong rotate instructions in the .ad file Reviewed-by: kvn
hotspot/src/cpu/ppc/vm/ppc.ad
hotspot/test/compiler/codegen/IntRotateWithImmediate.java
--- a/hotspot/src/cpu/ppc/vm/ppc.ad	Mon May 18 19:54:49 2015 +0200
+++ b/hotspot/src/cpu/ppc/vm/ppc.ad	Tue May 19 11:06:34 2015 +0200
@@ -2173,9 +2173,8 @@
 
 // Do we need to mask the count passed to shift instructions or does
 // the cpu only look at the lower 5/6 bits anyway?
-// Off, as masks are generated in expand rules where required.
-// Constant shift counts are handled in Ideal phase.
-const bool Matcher::need_masked_shift_count = false;
+// PowerPC requires masked shift counts.
+const bool Matcher::need_masked_shift_count = true;
 
 // This affects two different things:
 //  - how Decode nodes are matched
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/compiler/codegen/IntRotateWithImmediate.java	Tue May 19 11:06:34 2015 +0200
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2015 SAP AG.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8080190
+ * @key regression
+ * @summary Test that the rotate distance used in the rotate instruction is properly masked with 0x1f
+ * @run main/othervm -Xbatch -XX:-UseOnStackReplacement IntRotateWithImmediate
+ * @author volker.simonis@gmail.com
+ */
+
+public class IntRotateWithImmediate {
+
+  // This is currently the same as Integer.rotateRight()
+  static int rotateRight(int i, int distance) {
+    // On some architectures (i.e. x86_64 and ppc64) the following computation is
+    // matched in the .ad file into a single MachNode which emmits a single rotate
+    // machine instruction. It is important that the shift amount is masked to match
+    // corresponding immediate width in the native instruction. On x86_64 the rotate
+    // left instruction ('rol') encodes an 8-bit immediate while the corresponding
+    // 'rotlwi' instruction on Power only encodes a 5-bit immediate.
+    return ((i >>> distance) | (i << -distance));
+  }
+
+  static int compute(int x) {
+    return rotateRight(x, 3);
+  }
+
+  public static void main(String args[]) {
+    int val = 4096;
+
+    int firstResult = compute(val);
+
+    for (int i = 0; i < 100000; i++) {
+      int newResult = compute(val);
+      if (firstResult != newResult) {
+        throw new InternalError(firstResult + " != " + newResult);
+      }
+    }
+    System.out.println("OK");
+  }
+
+}