From 4f23f9fc4aadb33c93451a0d62d6277907093255 Mon Sep 17 00:00:00 2001 From: never Date: Fri, 29 Jan 2010 22:51:41 -0800 Subject: [PATCH] 6916644: C2 compiler crash on x86 Reviewed-by: kvn, twisti --- src/share/vm/adlc/output_c.cpp | 29 ++++++++------- src/share/vm/adlc/output_h.cpp | 4 +-- src/share/vm/opto/machnode.hpp | 4 +-- src/share/vm/opto/matcher.cpp | 4 +-- test/compiler/6916644/Test6916644.java | 50 ++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 19 deletions(-) create mode 100644 test/compiler/6916644/Test6916644.java diff --git a/src/share/vm/adlc/output_c.cpp b/src/share/vm/adlc/output_c.cpp index e32af7ea4..1e9fd56ff 100644 --- a/src/share/vm/adlc/output_c.cpp +++ b/src/share/vm/adlc/output_c.cpp @@ -1,5 +1,5 @@ /* - * Copyright 1998-2009 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1998-2010 Sun Microsystems, Inc. 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 @@ -1496,7 +1496,7 @@ void ArchDesc::defineExpand(FILE *fp, InstructForm *node) { unsigned i; // Generate Expand function header - fprintf(fp,"MachNode *%sNode::Expand(State *state, Node_List &proj_list) {\n", node->_ident); + fprintf(fp,"MachNode *%sNode::Expand(State *state, Node_List &proj_list, Node* mem) {\n", node->_ident); fprintf(fp,"Compile* C = Compile::current();\n"); // Generate expand code if( node->expands() ) { @@ -1546,15 +1546,16 @@ void ArchDesc::defineExpand(FILE *fp, InstructForm *node) { // Build a mapping from operand index to input edges fprintf(fp," unsigned idx0 = oper_input_base();\n"); - // The order in which inputs are added to a node is very + // The order in which the memory input is added to a node is very // strange. Store nodes get a memory input before Expand is - // called and all other nodes get it afterwards so - // oper_input_base is wrong during expansion. This code adjusts - // is so that expansion will work correctly. - bool missing_memory_edge = node->_matrule->needs_ideal_memory_edge(_globalNames) && - node->is_ideal_store() == Form::none; - if (missing_memory_edge) { - fprintf(fp," idx0--; // Adjust base because memory edge hasn't been inserted yet\n"); + // called and other nodes get it afterwards or before depending on + // match order so oper_input_base is wrong during expansion. This + // code adjusts it so that expansion will work correctly. + int has_memory_edge = node->_matrule->needs_ideal_memory_edge(_globalNames); + if (has_memory_edge) { + fprintf(fp," if (mem == (Node*)1) {\n"); + fprintf(fp," idx0--; // Adjust base because memory edge hasn't been inserted yet\n"); + fprintf(fp," }\n"); } for( i = 0; i < node->num_opnds(); i++ ) { @@ -1611,9 +1612,11 @@ void ArchDesc::defineExpand(FILE *fp, InstructForm *node) { int node_mem_op = node->memory_operand(_globalNames); assert( node_mem_op != InstructForm::NO_MEMORY_OPERAND, "expand rule member needs memory but top-level inst doesn't have any" ); - if (!missing_memory_edge) { + if (has_memory_edge) { // Copy memory edge - fprintf(fp," n%d->add_req(_in[1]);\t// Add memory edge\n", cnt); + fprintf(fp," if (mem != (Node*)1) {\n"); + fprintf(fp," n%d->add_req(_in[1]);\t// Add memory edge\n", cnt); + fprintf(fp," }\n"); } } @@ -1689,7 +1692,7 @@ void ArchDesc::defineExpand(FILE *fp, InstructForm *node) { } // done iterating over a new instruction's operands // Invoke Expand() for the newly created instruction. - fprintf(fp," result = n%d->Expand( state, proj_list );\n", cnt); + fprintf(fp," result = n%d->Expand( state, proj_list, mem );\n", cnt); assert( !new_inst->expands(), "Do not have complete support for recursive expansion"); } // done iterating over new instructions fprintf(fp,"\n"); diff --git a/src/share/vm/adlc/output_h.cpp b/src/share/vm/adlc/output_h.cpp index 23f0827b2..2e27f706c 100644 --- a/src/share/vm/adlc/output_h.cpp +++ b/src/share/vm/adlc/output_h.cpp @@ -1,5 +1,5 @@ /* - * Copyright 1998-2009 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1998-2010 Sun Microsystems, Inc. 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 @@ -1754,7 +1754,7 @@ void ArchDesc::declareClasses(FILE *fp) { instr->has_temps() || instr->_matrule != NULL && instr->num_opnds() != instr->num_unique_opnds() ) { - fprintf(fp," virtual MachNode *Expand(State *state, Node_List &proj_list);\n"); + fprintf(fp," virtual MachNode *Expand(State *state, Node_List &proj_list, Node* mem);\n"); } if (instr->is_pinned(_globalNames)) { diff --git a/src/share/vm/opto/machnode.hpp b/src/share/vm/opto/machnode.hpp index 67d6965b6..128b55fdd 100644 --- a/src/share/vm/opto/machnode.hpp +++ b/src/share/vm/opto/machnode.hpp @@ -1,5 +1,5 @@ /* - * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-2010 Sun Microsystems, Inc. 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 @@ -232,7 +232,7 @@ public: // Expand method for MachNode, replaces nodes representing pseudo // instructions with a set of nodes which represent real machine // instructions and compute the same value. - virtual MachNode *Expand( State *, Node_List &proj_list ) { return this; } + virtual MachNode *Expand( State *, Node_List &proj_list, Node* mem ) { return this; } // Bottom_type call; value comes from operand0 virtual const class Type *bottom_type() const { return _opnds[0]->type(); } diff --git a/src/share/vm/opto/matcher.cpp b/src/share/vm/opto/matcher.cpp index d535df05c..c1e6e7065 100644 --- a/src/share/vm/opto/matcher.cpp +++ b/src/share/vm/opto/matcher.cpp @@ -1,5 +1,5 @@ /* - * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-2010 Sun Microsystems, Inc. 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 @@ -1580,7 +1580,7 @@ MachNode *Matcher::ReduceInst( State *s, int rule, Node *&mem ) { uint num_proj = _proj_list.size(); // Perform any 1-to-many expansions required - MachNode *ex = mach->Expand(s,_proj_list); + MachNode *ex = mach->Expand(s,_proj_list, mem); if( ex != mach ) { assert(ex->ideal_reg() == mach->ideal_reg(), "ideal types should match"); if( ex->in(1)->is_Con() ) diff --git a/test/compiler/6916644/Test6916644.java b/test/compiler/6916644/Test6916644.java new file mode 100644 index 000000000..793ccd697 --- /dev/null +++ b/test/compiler/6916644/Test6916644.java @@ -0,0 +1,50 @@ +/* + * Copyright 2010 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + * + */ + +/** + * @test + * @bug 6916644 + * @summary C2 compiler crash on x86 + * + * @run main/othervm -Xcomp -XX:CompileOnly=Test6916644.test Test6916644 + */ + +public class Test6916644 { + static int result; + static int i1; + static int i2; + + static public void test(double d) { + result = (d <= 0.0D) ? i1 : i2; + } + + public static void main(String[] args) { + for (int i = 0; i < 100000; i++) { + // use an alternating value so the test doesn't always go + // the same direction. Otherwise we won't transform it + // into a cmove. + test(i & 1); + } + } +} -- GitLab