Patchwork Disable loop2_invariant for -Os

login
register
mail settings
Submitter Zhenqiang Chen
Date June 27, 2012, 8:40 a.m.
Message ID <000a01cd5440$8c137d20$a43a7760$@chen@arm.com>
Download mbox | patch
Permalink /patch/167567/
State New
Headers show

Comments

Zhenqiang Chen - June 27, 2012, 8:40 a.m.
Hi,

In general, invariant motion itself can not reduce code size. But it will
change the liverange of the invariant, which might lead to more spilling.
The patch disables loop2_invariant when optimizing for size.

I measured the code size benefit for four targets based on CSiBE benchmark:

ARM: 0.33%
MIPS: 1.15%
PPC: 0.24%
X86: 0.45%

Is it OK for trunk?

Thanks!
-Zhenqiang

ChangeLog:
2012-06-27  Zhenqiang Chen <zhenqiang.chen@arm.com>

	* loop-init.c (gate_rtl_move_loop_invariants): Disable
loop2_invariant
	when optimizing function for size.

Patch

diff --git a/gcc/loop-init.c b/gcc/loop-init.c
index 03f8f61..5d8cf73 100644
--- a/gcc/loop-init.c
+++ b/gcc/loop-init.c
@@ -273,6 +273,12 @@  struct rtl_opt_pass pass_rtl_loop_done =
 static bool
 gate_rtl_move_loop_invariants (void)
 {
+  /* In general, invariant motion can not reduce code size. But it will
+     change the liverange of the invariant, which increases the register
+     pressure and might lead to more spilling.  */
+  if (optimize_function_for_size_p (cfun))
+    return false;
+
   return flag_move_loop_invariants;
 }