X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fir%2Firopt.c;h=093b1f3f4b32f0bcdb75d4ae00a387d0c73e5cc0;hb=f9138cf5219d2b9f69949dcc1fd7258304f83ced;hp=ad79fce7250255dde564a3a2deecee85fa4a0c9e;hpb=055909393f5f1ae98f9f2a33e0fa39326d9d7393;p=libfirm diff --git a/ir/ir/iropt.c b/ir/ir/iropt.c index ad79fce72..093b1f3f4 100644 --- a/ir/ir/iropt.c +++ b/ir/ir/iropt.c @@ -1,25 +1,32 @@ /* - * Project: libFIRM - * File name: ir/ir/iropt.c - * Purpose: iropt --- optimizations intertwined with IR construction. - * Author: Christian Schaefer - * Modified by: Goetz Lindenmaier, Michael Beck - * Created: - * CVS-ID: $Id$ - * Copyright: (c) 1998-2006 Universität Karlsruhe - * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE. + * Copyright (C) 1995-2007 University of Karlsruhe. All right reserved. + * + * This file is part of libFirm. + * + * This file may be distributed and/or modified under the terms of the + * GNU General Public License version 2 as published by the Free Software + * Foundation and appearing in the file LICENSE.GPL included in the + * packaging of this file. + * + * Licensees holding valid libFirm Professional Edition licenses may use + * this file in accordance with the libFirm Commercial License. + * Agreement provided with the Software. + * + * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE + * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE. */ +/** + * @file + * @brief iropt --- optimizations intertwined with IR construction. + * @author Christian Schaefer, Goetz Lindenmaier, Michael Beck + * @version $Id$ + */ #ifdef HAVE_CONFIG_H # include "config.h" #endif -#ifdef HAVE_ALLOCA_H -#include -#endif -#ifdef HAVE_MALLOC_H -#include -#endif #ifdef HAVE_STRING_H #include #endif @@ -43,6 +50,7 @@ #include "opt_polymorphy.h" #include "opt_confirms.h" #include "irtools.h" +#include "xmalloc.h" /* Make types visible to allow most efficient access */ #include "entity_t.h" @@ -3659,9 +3667,17 @@ ir_node *identify_remember(pset *value_table, ir_node *n) { if (is_op_commutative(get_irn_op(n))) { ir_node *l = get_binop_left(n); ir_node *r = get_binop_right(n); - - /* for commutative operators perform a OP b == b OP a */ - if (l > r) { + int l_idx = get_irn_idx(l); + int r_idx = get_irn_idx(r); + + /* For commutative operators perform a OP b == b OP a but keep + constants on the RIGHT side. This helps greatly in some optimizations. + Moreover we use the idx number to make the form deterministic. */ + if (is_irn_constlike(l)) + l_idx = -l_idx; + if (is_irn_constlike(r)) + r_idx = -r_idx; + if (l_idx < r_idx) { set_binop_left(n, r); set_binop_right(n, l); } @@ -3669,7 +3685,7 @@ ir_node *identify_remember(pset *value_table, ir_node *n) { } /* lookup or insert in hash table with given hash key. */ - o = pset_insert (value_table, n, ir_node_hash (n)); + o = pset_insert(value_table, n, ir_node_hash(n)); if (o != n) { DBG_OPT_CSE(n, o);