This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Address one thing in PR32698


This patch makes us consistently canonicalize A * C +- B * C
instead of depending on the actual constant.  So for array
accesses like

p[i + 1] + p[i + 2] + p[i + 3]

we produced a mix like

(*(p + (D.1660 + 8)) + *(p + (i + 1) * 4)) + *(p + (D.1660 + 12))

now we match the original input and create

(*(p + (i + 2) * 4) + *(p + (i + 1) * 4)) + *(p + (i + 3) * 4)

it doesn't change code generation on x86_64, on i686 we use
one register less.

As this patch only changes fold it doesn't address any deficiency
selecting a proper addressing mode (which shouldn't be done
out of context and is done later by both ivopts (if in loops) and
fwprop at rtl).  It merely corrects a mistake I made at the
point I invented the function doing the canonicalization.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to
mainline.

Richard.

2007-07-09  Richard Guenther  <rguenther@suse.de>

	PR middle-end/32698
	* fold-const.c (fold_plusminus_mult_expr): Move constant
	arguments second to allow decomposing.

Index: fold-const.c
===================================================================
*** fold-const.c	(revision 126376)
--- fold-const.c	(working copy)
*************** fold_plusminus_mult_expr (enum tree_code
*** 7122,7127 ****
--- 7122,7132 ----
        arg00 = TREE_OPERAND (arg0, 0);
        arg01 = TREE_OPERAND (arg0, 1);
      }
+   else if (TREE_CODE (arg0) == INTEGER_CST)
+     {
+       arg00 = build_one_cst (type);
+       arg01 = arg0;
+     }
    else
      {
        arg00 = arg0;
*************** fold_plusminus_mult_expr (enum tree_code
*** 7132,7137 ****
--- 7137,7147 ----
        arg10 = TREE_OPERAND (arg1, 0);
        arg11 = TREE_OPERAND (arg1, 1);
      }
+   else if (TREE_CODE (arg1) == INTEGER_CST)
+     {
+       arg10 = build_one_cst (type);
+       arg11 = arg1;
+     }
    else
      {
        arg10 = arg1;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]