public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ubizjak at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/36503] x86 can use x >> -y for x >> 32-y
Date: Thu, 12 Jun 2008 10:44:00 -0000	[thread overview]
Message-ID: <20080612104355.5117.qmail@sourceware.org> (raw)
In-Reply-To: <bug-36503-10175@http.gcc.gnu.org/bugzilla/>



------- Comment #3 from ubizjak at gmail dot com  2008-06-12 10:43 -------
(In reply to comment #2)
> We have the SHIFT_COUNT_TRUNCATED macro for this (though I'm not sure if
> that says negative values are ok).

They are, but there is a comment in the documentation:

-- Macro: SHIFT_COUNT_TRUNCATED
   ...

     However, on some machines, such as the 80386 and the 680x0,
     truncation only applies to shift operations and not the (real or
     pretended) bit-field operations.  Define `SHIFT_COUNT_TRUNCATED'
     to be zero on such machines.  Instead, add patterns to the `md'
     file that include the implied truncation of the shift instructions.

I don't know which "real or pretended" bit-field operations are referred here,
since bt insn also truncate its bit-offset operand. OTOH, {SI,HI,QI}mode shifts
all truncate to 0x1f, not to GET_MODE_SIZE(mode) - 1.

I have a patch:

Index: config/i386/i386.c
===================================================================
--- config/i386/i386.c  (revision 136692)
+++ config/i386/i386.c  (working copy)
@@ -24681,6 +24681,22 @@
   emit_insn (fn (dest, tmp2, tmp3));
 }


+/* Target hook for target_shift_trucnation_mask.  */
+static unsigned HOST_WIDE_INT
+ix86_shift_truncation_mask (enum machine_mode mode)
+{
+  if (TARGET_64BIT
+      && mode == DImode)
+    return 0x3f;
+
+  if (mode == SImode
+      || mode == HImode
+      || mode == QImode)
+    return 0x1f;
+
+  return 0;
+}
+
 /* Target hook for scalar_mode_supported_p.  */
 static bool
 ix86_scalar_mode_supported_p (enum machine_mode mode)
@@ -26039,6 +26055,9 @@
 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
 #define TARGET_GIMPLIFY_VA_ARG_EXPR ix86_gimplify_va_arg

+#undef TARGET_SHIFT_TRUNCATION_MASK
+#define TARGET_SHIFT_TRUNCATION_MASK ix86_shift_truncation_mask
+
 #undef TARGET_SCALAR_MODE_SUPPORTED_P
 #define TARGET_SCALAR_MODE_SUPPORTED_P ix86_scalar_mode_supported_p

But it does nothing for this optimization. I guess middle-end should be kicked
to handle this optimization.

BTW: Why does ffmpeg need inline asm for this optimization? Following code
snipped also produces expected code:

int shift32 (int i, int n)
{
  return i >> (-n);
}


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36503


  parent reply	other threads:[~2008-06-12 10:44 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-11 22:53 [Bug target/36503] New: " astrange at ithinksw dot com
2008-06-11 22:53 ` [Bug target/36503] " astrange at ithinksw dot com
2008-06-12  0:05 ` pinskia at gcc dot gnu dot org
2008-06-12  9:25 ` rguenth at gcc dot gnu dot org
2008-06-12 10:44 ` ubizjak at gmail dot com [this message]
2008-06-12 16:49 ` astrange at ithinksw dot com
2009-11-07  9:22 ` bonzini at gnu dot org
2009-11-09  7:38 ` ubizjak at gmail dot com
     [not found] <bug-36503-4@http.gcc.gnu.org/bugzilla/>
2010-10-21  4:39 ` astrange at ithinksw dot com
2010-10-22  7:37 ` ubizjak at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080612104355.5117.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).