Bug 60863 - Incorrect codegen in ix86_expand_clear for -Os
Summary: Incorrect codegen in ix86_expand_clear for -Os
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: 5.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-16 15:43 UTC by H.J. Lu
Modified: 2014-04-17 15:21 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2014-04-16 15:43:56 UTC
ix86_expand_clear has

  /* This predicate should match that for movsi_xor and movdi_xor_rex64.  */
  if (!TARGET_USE_MOV0 || optimize_insn_for_speed_p ())
    {
      rtx clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
      tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, clob));
    }

But "xor reg,reg" has shorter encoding than "mov $0, reg".  If
"xor reg,reg" is generated for -O, shouldn't it also be generated
for -Os?
Comment 1 Uroš Bizjak 2014-04-16 17:43:26 UTC
(In reply to H.J. Lu from comment #0)
> ix86_expand_clear has
> 
>   /* This predicate should match that for movsi_xor and movdi_xor_rex64.  */
>   if (!TARGET_USE_MOV0 || optimize_insn_for_speed_p ())
>     {
>       rtx clob = gen_rtx_CLOBBER (VOIDmode, gen_rtx_REG (CCmode, FLAGS_REG));
>       tmp = gen_rtx_PARALLEL (VOIDmode, gen_rtvec (2, tmp, clob));
>     }
> 
> But "xor reg,reg" has shorter encoding than "mov $0, reg".  If
> "xor reg,reg" is generated for -O, shouldn't it also be generated
> for -Os?

This is a typo, the condition should be optimize_insn_for_size_p. Just look peepholes in i386.md after "Attempt to always use XOR for zeroing registers." comment.

The patch that fixes the condition is preapproved - please also remove outdated comment about predicates.
Comment 2 hjl@gcc.gnu.org 2014-04-17 15:20:06 UTC
Author: hjl
Date: Thu Apr 17 15:19:34 2014
New Revision: 209488

URL: http://gcc.gnu.org/viewcvs?rev=209488&root=gcc&view=rev
Log:
Generate "xor reg, reg" if optimizing for size

	PR target/60863
	* config/i386/i386.c (ix86_expand_clear): Remove outdated
	comment.  Check optimize_insn_for_size_p instead of
	optimize_insn_for_speed_p.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.c
Comment 3 H.J. Lu 2014-04-17 15:21:32 UTC
Fixed.