public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/46647] New: Can't inline memset with -1
@ 2010-11-24 20:57 hjl.tools at gmail dot com
  2010-11-24 21:01 ` [Bug middle-end/46647] " hjl.tools at gmail dot com
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: hjl.tools at gmail dot com @ 2010-11-24 20:57 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Can't inline memset with -1
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: hjl.tools@gmail.com
                CC: ubizjak@gmail.com


[hjl@gnu-16 gcc]$ cat /tmp/x.i 
char a[4];
int
func1 (void)
{
  __builtin_memset (a,-1,sizeof (a));
  return 0;
}

int
func2 (void)
{
  __builtin_memset (a,123,sizeof (a));
  return 0;
}
[hjl@gnu-16 gcc]$ ./xgcc -B./ -S /tmp/x.i -O2 -m32
[hjl@gnu-16 gcc]$ cat x.s
    .file    "x.i"
    .text
    .p2align 4,,15
    .globl    func1
    .type    func1, @function
func1:
.LFB0:
    .cfi_startproc
    subl    $28, %esp
    .cfi_def_cfa_offset 32
    movl    $4, 8(%esp)
    movl    $-1, 4(%esp)
    movl    $a, (%esp)
    call    memset
    xorl    %eax, %eax
    addl    $28, %esp
    .cfi_def_cfa_offset 4
    ret
    .cfi_endproc
.LFE0:
    .size    func1, .-func1
    .p2align 4,,15
    .globl    func2
    .type    func2, @function
func2:
.LFB1:
    .cfi_startproc
    movl    $2071690107, a
    xorl    %eax, %eax
    ret
    .cfi_endproc
.LFE1:
    .size    func2, .-func2
    .comm    a,4,1
    .ident    "GCC: (GNU) 4.6.0 20101124 (experimental) [trunk revision
167121]"
    .section    .note.GNU-stack,"",@progbits
[hjl@gnu-16 gcc]$ 

Why can't we inline  __builtin_memset (a,123,sizeof (a))?


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

* [Bug target/46647] Can't inline memset with -1
  2010-11-24 20:57 [Bug target/46647] New: Can't inline memset with -1 hjl.tools at gmail dot com
  2010-11-24 21:01 ` [Bug middle-end/46647] " hjl.tools at gmail dot com
@ 2010-11-24 21:01 ` hjl.tools at gmail dot com
  2010-11-24 21:43 ` [Bug middle-end/46647] " hjl.tools at gmail dot com
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: hjl.tools at gmail dot com @ 2010-11-24 21:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from H.J. Lu <hjl.tools at gmail dot com> 2010-11-24 20:47:25 UTC ---
We can inline 0x7fffffff and fail 0x8fffffff.


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

* [Bug middle-end/46647] Can't inline memset with -1
  2010-11-24 20:57 [Bug target/46647] New: Can't inline memset with -1 hjl.tools at gmail dot com
@ 2010-11-24 21:01 ` hjl.tools at gmail dot com
  2010-11-24 21:01 ` [Bug target/46647] " hjl.tools at gmail dot com
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: hjl.tools at gmail dot com @ 2010-11-24 21:01 UTC (permalink / raw)
  To: gcc-bugs

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

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu.org
          Component|target                      |middle-end

--- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> 2010-11-24 20:57:03 UTC ---
It is target independent.


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

* [Bug middle-end/46647] Can't inline memset with -1
  2010-11-24 20:57 [Bug target/46647] New: Can't inline memset with -1 hjl.tools at gmail dot com
  2010-11-24 21:01 ` [Bug middle-end/46647] " hjl.tools at gmail dot com
  2010-11-24 21:01 ` [Bug target/46647] " hjl.tools at gmail dot com
@ 2010-11-24 21:43 ` hjl.tools at gmail dot com
  2010-11-24 21:53 ` jakub at gcc dot gnu.org
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: hjl.tools at gmail dot com @ 2010-11-24 21:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from H.J. Lu <hjl.tools at gmail dot com> 2010-11-24 21:08:10 UTC ---
fold_builtin_memset fails to handle 0x[8-f]fffffff.


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

* [Bug middle-end/46647] Can't inline memset with -1
  2010-11-24 20:57 [Bug target/46647] New: Can't inline memset with -1 hjl.tools at gmail dot com
                   ` (2 preceding siblings ...)
  2010-11-24 21:43 ` [Bug middle-end/46647] " hjl.tools at gmail dot com
@ 2010-11-24 21:53 ` jakub at gcc dot gnu.org
  2010-11-24 22:00 ` hjl.tools at gmail dot com
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2010-11-24 21:53 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> 2010-11-24 21:36:06 UTC ---
If the testcase starts with int a[1]; instead of char a[4];, then:
--- builtins.c.jj32010-11-19 20:56:54.000000000 +0100
+++ builtins.c2010-11-24 22:23:41.000000000 +0100
@@ -8345,7 +8345,7 @@ fold_builtin_memset (location_t loc, tre
   if (integer_zerop (len))
     return omit_one_operand_loc (loc, type, dest, c);

-  if (! host_integerp (c, 1) || TREE_SIDE_EFFECTS (dest))
+  if (TREE_CODE (c) != INTEGER_CST || TREE_SIDE_EFFECTS (dest))
     return NULL_TREE;

   var = dest;
@@ -8384,7 +8384,7 @@ fold_builtin_memset (location_t loc, tre
       if (CHAR_BIT != 8 || BITS_PER_UNIT != 8 || HOST_BITS_PER_WIDE_INT > 64)
         return NULL_TREE;

-      cval = tree_low_cst (c, 1);
+      cval = TREE_INT_CST_LOW (c);
       cval &= 0xff;
       cval |= cval << 8;
       cval |= cval << 16;

should fix this.  But with char a[4]; instead this isn't something that is
optimized at the tree level at all, so similar change will be needed somewhere
on the expander side.


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

* [Bug middle-end/46647] Can't inline memset with -1
  2010-11-24 20:57 [Bug target/46647] New: Can't inline memset with -1 hjl.tools at gmail dot com
                   ` (3 preceding siblings ...)
  2010-11-24 21:53 ` jakub at gcc dot gnu.org
@ 2010-11-24 22:00 ` hjl.tools at gmail dot com
  2010-11-24 22:06 ` hjl.tools at gmail dot com
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: hjl.tools at gmail dot com @ 2010-11-24 22:00 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from H.J. Lu <hjl.tools at gmail dot com> 2010-11-24 21:43:11 UTC ---
char a[4] isn't handled by fold_builtin_memset.


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

* [Bug middle-end/46647] Can't inline memset with -1
  2010-11-24 20:57 [Bug target/46647] New: Can't inline memset with -1 hjl.tools at gmail dot com
                   ` (4 preceding siblings ...)
  2010-11-24 22:00 ` hjl.tools at gmail dot com
@ 2010-11-24 22:06 ` hjl.tools at gmail dot com
  2010-11-24 22:10 ` hjl.tools at gmail dot com
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: hjl.tools at gmail dot com @ 2010-11-24 22:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from H.J. Lu <hjl.tools at gmail dot com> 2010-11-24 21:52:46 UTC ---
The problem seems to be target_char_cast.


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

* [Bug middle-end/46647] Can't inline memset with -1
  2010-11-24 20:57 [Bug target/46647] New: Can't inline memset with -1 hjl.tools at gmail dot com
                   ` (5 preceding siblings ...)
  2010-11-24 22:06 ` hjl.tools at gmail dot com
@ 2010-11-24 22:10 ` hjl.tools at gmail dot com
  2010-11-24 22:11 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: hjl.tools at gmail dot com @ 2010-11-24 22:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from H.J. Lu <hjl.tools at gmail dot com> 2010-11-24 22:00:25 UTC ---
This seems to work:

---
diff --git a/gcc/builtins.c b/gcc/builtins.c
index c9e8e68..840ec29 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -630,11 +630,10 @@ target_char_cast (tree cst, char *p)
 {
   unsigned HOST_WIDE_INT val, hostval;

-  if (!host_integerp (cst, 1)
-      || CHAR_TYPE_SIZE > HOST_BITS_PER_WIDE_INT)
+  if (CHAR_TYPE_SIZE > HOST_BITS_PER_WIDE_INT)
     return 1;

-  val = tree_low_cst (cst, 1);
+  val = TREE_INT_CST_LOW (cst);
   if (CHAR_TYPE_SIZE < HOST_BITS_PER_WIDE_INT)
     val &= (((unsigned HOST_WIDE_INT) 1) << CHAR_TYPE_SIZE) - 1;
----


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

* [Bug middle-end/46647] Can't inline memset with -1
  2010-11-24 20:57 [Bug target/46647] New: Can't inline memset with -1 hjl.tools at gmail dot com
                   ` (6 preceding siblings ...)
  2010-11-24 22:10 ` hjl.tools at gmail dot com
@ 2010-11-24 22:11 ` jakub at gcc dot gnu.org
  2010-11-24 22:22 ` hjl.tools at gmail dot com
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2010-11-24 22:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> 2010-11-24 22:04:11 UTC ---
I'd prefer to replace the host_integerp call in that routine with
TREE_CODE (...) == INTEGER_CST check.  While currently callers check it as
well, it isn't too expensive and makes it more robust.


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

* [Bug middle-end/46647] Can't inline memset with -1
  2010-11-24 20:57 [Bug target/46647] New: Can't inline memset with -1 hjl.tools at gmail dot com
                   ` (7 preceding siblings ...)
  2010-11-24 22:11 ` jakub at gcc dot gnu.org
@ 2010-11-24 22:22 ` hjl.tools at gmail dot com
  2010-11-24 23:04 ` hjl.tools at gmail dot com
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: hjl.tools at gmail dot com @ 2010-11-24 22:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from H.J. Lu <hjl.tools at gmail dot com> 2010-11-24 22:11:03 UTC ---
(In reply to comment #8)
> I'd prefer to replace the host_integerp call in that routine with
> TREE_CODE (...) == INTEGER_CST check.  While currently callers check it as
> well, it isn't too expensive and makes it more robust.

/* Cast a target constant CST to target CHAR and if that value fits into
   host char type, return zero and put that value into variable pointed to by
   P.  */

static int
target_char_cast (tree cst, char *p)

It is supposed to be called on integer constant. Adding a check
shouldn't be too bad:

diff --git a/gcc/builtins.c b/gcc/builtins.c
index c9e8e68..a90bf2f 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -630,11 +630,11 @@ target_char_cast (tree cst, char *p)
 {
   unsigned HOST_WIDE_INT val, hostval;

-  if (!host_integerp (cst, 1)
+  if (TREE_CODE (cst) != INTEGER_CST
       || CHAR_TYPE_SIZE > HOST_BITS_PER_WIDE_INT)
     return 1;

-  val = tree_low_cst (cst, 1);
+  val = TREE_INT_CST_LOW (cst);
   if (CHAR_TYPE_SIZE < HOST_BITS_PER_WIDE_INT)
     val &= (((unsigned HOST_WIDE_INT) 1) << CHAR_TYPE_SIZE) - 1;


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

* [Bug middle-end/46647] Can't inline memset with -1
  2010-11-24 20:57 [Bug target/46647] New: Can't inline memset with -1 hjl.tools at gmail dot com
                   ` (8 preceding siblings ...)
  2010-11-24 22:22 ` hjl.tools at gmail dot com
@ 2010-11-24 23:04 ` hjl.tools at gmail dot com
  2010-11-25 14:40 ` hjl at gcc dot gnu.org
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: hjl.tools at gmail dot com @ 2010-11-24 23:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from H.J. Lu <hjl.tools at gmail dot com> 2010-11-24 22:22:17 UTC ---
Created attachment 22519
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22519
A patch

I am testing it on Linux/x86-64.


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

* [Bug middle-end/46647] Can't inline memset with -1
  2010-11-24 20:57 [Bug target/46647] New: Can't inline memset with -1 hjl.tools at gmail dot com
                   ` (9 preceding siblings ...)
  2010-11-24 23:04 ` hjl.tools at gmail dot com
@ 2010-11-25 14:40 ` hjl at gcc dot gnu.org
  2010-11-26  9:51 ` jakub at gcc dot gnu.org
  2010-11-28 14:37 ` hjl.tools at gmail dot com
  12 siblings, 0 replies; 14+ messages in thread
From: hjl at gcc dot gnu.org @ 2010-11-25 14:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from hjl at gcc dot gnu.org <hjl at gcc dot gnu.org> 2010-11-25 13:48:06 UTC ---
Author: hjl
Date: Thu Nov 25 13:47:42 2010
New Revision: 167146

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=167146
Log:
Properly cast integer constant char. 

gcc/

2010-11-25  H.J. Lu  <hongjiu.lu@intel.com>

    PR middle-end/46647
    * builtins.c (target_char_cast): Check INTEGER_CST instead of
    host_integerp.  Replace tree_low_cst with TREE_INT_CST_LOW.

gcc/testsuite/

2010-11-25  H.J. Lu  <hongjiu.lu@intel.com>

    PR middle-end/46647
    * gcc.target/i386/pr46647.c: New.

Added:
    trunk/gcc/testsuite/gcc.target/i386/pr46647.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/builtins.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug middle-end/46647] Can't inline memset with -1
  2010-11-24 20:57 [Bug target/46647] New: Can't inline memset with -1 hjl.tools at gmail dot com
                   ` (10 preceding siblings ...)
  2010-11-25 14:40 ` hjl at gcc dot gnu.org
@ 2010-11-26  9:51 ` jakub at gcc dot gnu.org
  2010-11-28 14:37 ` hjl.tools at gmail dot com
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu.org @ 2010-11-26  9:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #12 from Jakub Jelinek <jakub at gcc dot gnu.org> 2010-11-26 09:38:59 UTC ---
Author: jakub
Date: Fri Nov 26 09:38:54 2010
New Revision: 167170

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=167170
Log:
    PR middle-end/46647
    * builtins.c (fold_builtin_memset): Check c is INTEGER_CST instead
    of host_integerp check.  Use TREE_INT_CST_LOW instead of tree_low_cst.

    * gcc.dg/pr46647.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr46647.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/builtins.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug middle-end/46647] Can't inline memset with -1
  2010-11-24 20:57 [Bug target/46647] New: Can't inline memset with -1 hjl.tools at gmail dot com
                   ` (11 preceding siblings ...)
  2010-11-26  9:51 ` jakub at gcc dot gnu.org
@ 2010-11-28 14:37 ` hjl.tools at gmail dot com
  12 siblings, 0 replies; 14+ messages in thread
From: hjl.tools at gmail dot com @ 2010-11-28 14:37 UTC (permalink / raw)
  To: gcc-bugs

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

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.6.0

--- Comment #13 from H.J. Lu <hjl.tools at gmail dot com> 2010-11-28 14:33:01 UTC ---
Fixed.


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

end of thread, other threads:[~2010-11-28 14:33 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-24 20:57 [Bug target/46647] New: Can't inline memset with -1 hjl.tools at gmail dot com
2010-11-24 21:01 ` [Bug middle-end/46647] " hjl.tools at gmail dot com
2010-11-24 21:01 ` [Bug target/46647] " hjl.tools at gmail dot com
2010-11-24 21:43 ` [Bug middle-end/46647] " hjl.tools at gmail dot com
2010-11-24 21:53 ` jakub at gcc dot gnu.org
2010-11-24 22:00 ` hjl.tools at gmail dot com
2010-11-24 22:06 ` hjl.tools at gmail dot com
2010-11-24 22:10 ` hjl.tools at gmail dot com
2010-11-24 22:11 ` jakub at gcc dot gnu.org
2010-11-24 22:22 ` hjl.tools at gmail dot com
2010-11-24 23:04 ` hjl.tools at gmail dot com
2010-11-25 14:40 ` hjl at gcc dot gnu.org
2010-11-26  9:51 ` jakub at gcc dot gnu.org
2010-11-28 14:37 ` hjl.tools at gmail dot com

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).