public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch] Performance patch for MIPS conditional move in expr.c
@ 2012-11-14 19:02 Steve Ellcey 
  2012-11-14 19:15 ` Andrew Pinski
  2012-11-15  1:51 ` Richard Henderson
  0 siblings, 2 replies; 14+ messages in thread
From: Steve Ellcey  @ 2012-11-14 19:02 UTC (permalink / raw)
  To: gcc-patches; +Cc: rguenther


Back in August of 2011, Richard Biener made a change affecting COND_EXPRs
(r178408).  As a result of that change the GCC MIPS compiler that used
to promote HImode variables to SImode and then put out SImode variables
and assignments for the conditional move (MIPS doesn't support HImode
conditional moves) started putting out HImode variables and assignments and
the resulting code is slower then it was.

The code that used to look like this:

(insn 23 22 24 3 (set (reg/v:SI 231 [ a2+-2 ]) (zero_extend:SI (subreg:HI (reg:SI 320) 2))) x.c:11 -1 (nil))
(insn 27 26 28 3 (set (reg/v:SI 233 [ a2+-2 ]) (zero_extend:SI (subreg:HI (reg:SI 323) 2))) x.c:12 -1 (nil))
IF ()
	(insn 30 241 31 4 (set (reg:SI 324) (reg/v:SI 231 [ a2+-2 ])) -1 (nil))
ELSE
	(insn 34 242 35 5 (set (reg:SI 324) (reg/v:SI 233 [ a2+-2 ])) -1 (nil))
(insn 36 243 37 6 (set (reg/v:SI 234 [ a2+-2 ]) (reg:SI 324)) -1 (nil))



started outputting HI assignments instead:



(insn 23 22 24 3 (set (reg/v:SI 231 [ a2+-2 ]) (zero_extend:SI (subreg:HI (reg:SI 320) 2))) x.c:11 -1 (nil))
(insn 27 26 28 3 (set (reg/v:SI 233 [ a2+-2 ]) (zero_extend:SI (subreg:HI (reg:SI 323) 2))) x.c:12 -1 (nil))
IF ()
	(insn 30 241 31 4 (set (reg:HI 324) (subreg/s/u:HI (reg/v:SI 231 [ a2+-2 ]) 2)) -1 (nil))
ELSE
	(insn 34 242 35 5 (set (reg:HI 324) (subreg/s/u:HI (reg/v:SI 233 [ a2+-2 ]) 2)) -1 (nil))
(insn 36 243 37 6 (set (reg/v:SI 234 [ a2+-2 ]) (zero_extend:SI (reg:HI 324))) -1 (nil))

This resulted in an extra 'andi REG,REG,0xffff' instruction to implement the
final zero_extend instruction and that slowed the code down.  This patch
restores the previous behaviour by modifying expand_cond_expr_using_cmove
so that when we need to promote the mode in order to do a conditional move
we use that promoted mode in the temp that we are creating for the conditional
move.

Tested on mips-mti-elf with no regressions.

OK for checkin?

Steve Ellcey
sellcey@mips.com


2012-11-14  Steve Ellcey  <sellcey@mips.com>

	* expr.c (expand_cond_expr_using_cmove): Use promoted mode for temp.


diff --git a/gcc/expr.c b/gcc/expr.c
index cbf3a40..b1b83d0 100644
--- a/gcc/expr.c
+++ b/gcc/expr.c
@@ -7840,15 +7840,17 @@ expand_cond_expr_using_cmove (tree treeop0 ATTRIBUTE_UNUSED,
   int unsignedp = TYPE_UNSIGNED (type);
   enum machine_mode mode = TYPE_MODE (type);
 
-  temp = assign_temp (type, 0, 1);
-
   /* If we cannot do a conditional move on the mode, try doing it
      with the promoted mode. */
   if (!can_conditionally_move_p (mode))
-    mode = promote_mode (type, mode, &unsignedp);
-
-  if (!can_conditionally_move_p (mode))
-    return NULL_RTX;
+    {
+      mode = promote_mode (type, mode, &unsignedp);
+      if (!can_conditionally_move_p (mode))
+	return NULL_RTX;
+      temp = assign_temp (type, 0, 0); /* Use promoted mode for temp.  */
+    }
+  else
+    temp = assign_temp (type, 0, 1);
 
   start_sequence ();
   expand_operands (treeop1, treeop2,

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2013-03-07 16:01 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-14 19:02 [patch] Performance patch for MIPS conditional move in expr.c Steve Ellcey 
2012-11-14 19:15 ` Andrew Pinski
2012-11-14 19:27   ` Steve Ellcey
2012-11-14 20:01     ` Andrew Pinski
2012-11-14 21:46       ` Steve Ellcey
2012-11-14 21:51         ` Andrew Pinski
2012-11-14 22:22           ` Andrew Pinski
2012-11-15 20:59             ` Richard Sandiford
2012-11-15 21:24               ` Andrew Pinski
2012-11-15 21:39                 ` Andrew Pinski
2013-01-07 21:39                   ` Steve Ellcey
2013-03-07 15:12             ` Jakub Jelinek
2013-03-07 16:01               ` Andrew Pinski
2012-11-15  1:51 ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).