public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/31531]  New: A microoptimization of isnegative or greaterthan2millions.
@ 2007-04-10 18:05 JCPiza at gmail dot com
  2007-04-10 18:14 ` [Bug c/31531] " JCPiza at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: JCPiza at gmail dot com @ 2007-04-10 18:05 UTC (permalink / raw)
  To: gcc-bugs

/* Given X an unsigned of 32 bits, and Y a bool. Try to translate optimizing
*
* Y = X >  2147483647;   to   Y = ((signed)X) < 0;
* Y = X >= 2147483648;   to   Y = ((signed)X) < 0;
*
* [ Another optimization is to Y = (X >> 31) ]
*
* The opposite (ELSE):
*
* Y = X <= 2147483647;   to   Y = ((signed)X) >= 0;
* Y = X <  2147483648;   to   Y = ((signed)X) >= 0;
*
* [ Another optimization is to Y = ((~X) >> 31) ]
*
* 2147483647=0x7FFFFFFF   2147483648=0x80000000
*
* The unsigned comparison is become to signed comparison.
*
* by J.C. Pizarro */

# gcc version 4.1.3 20070326 (prerelease)
Full test of isnegative is PASSED.

notl    %eax
shrl    $31, %eax
xorl    $1, %eax

IS WORSE THAN

shrl $31, %eax

---------------------

xorl    %eax, %eax
cmpl    $0, 4(%esp)
sets    %al

IS WORSE THAN

movl    4(%esp), %eax
shrl    $31, %eax

------------------------------------------------------------------------------

Full info with src code and tarball is in
http://gcc.gnu.org/ml/gcc/2007-04/msg00317.html

I'm sorry, i did want to say 2 billions, not 2 millions.

J.C. Pizarro


-- 
           Summary: A microoptimization of isnegative or
                    greaterthan2millions.
           Product: gcc
           Version: 4.1.3
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: JCPiza at gmail dot com


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


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

* [Bug c/31531] A microoptimization of isnegative or greaterthan2millions.
  2007-04-10 18:05 [Bug c/31531] New: A microoptimization of isnegative or greaterthan2millions JCPiza at gmail dot com
@ 2007-04-10 18:14 ` JCPiza at gmail dot com
  2007-04-10 18:17 ` [Bug middle-end/31531] A microoptimization of isnegative of signed integer pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: JCPiza at gmail dot com @ 2007-04-10 18:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from JCPiza at gmail dot com  2007-04-10 19:14 -------
Created an attachment (id=13349)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13349&action=view)
isnegative, a wonderful test of equivalence for uoptimization


-- 


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


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

* [Bug middle-end/31531] A microoptimization of isnegative of signed integer
  2007-04-10 18:05 [Bug c/31531] New: A microoptimization of isnegative or greaterthan2millions JCPiza at gmail dot com
  2007-04-10 18:14 ` [Bug c/31531] " JCPiza at gmail dot com
@ 2007-04-10 18:17 ` pinskia at gcc dot gnu dot org
  2007-04-10 18:20 ` pinskia at gcc dot gnu dot org
  2007-04-15  5:43 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-04-10 18:17 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2007-04-10 19:17 -------
What the real issue is that we don't fold !(x >= 0) into x < 0 before
expanding.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |middle-end
           Keywords|                            |missed-optimization
            Summary|A microoptimization of      |A microoptimization of
                   |isnegative or               |isnegative of signed integer
                   |greaterthan2millions.       |


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


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

* [Bug middle-end/31531] A microoptimization of isnegative of signed integer
  2007-04-10 18:05 [Bug c/31531] New: A microoptimization of isnegative or greaterthan2millions JCPiza at gmail dot com
  2007-04-10 18:14 ` [Bug c/31531] " JCPiza at gmail dot com
  2007-04-10 18:17 ` [Bug middle-end/31531] A microoptimization of isnegative of signed integer pinskia at gcc dot gnu dot org
@ 2007-04-10 18:20 ` pinskia at gcc dot gnu dot org
  2007-04-15  5:43 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-04-10 18:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2007-04-10 19:20 -------
A quick patch like:
Index: expr.c
===================================================================
--- expr.c      (revision 123691)
+++ expr.c      (working copy)
@@ -6828,7 +6828,7 @@
   tree type;
   int unsignedp;
   enum machine_mode mode;
-  enum tree_code code = TREE_CODE (exp);
+  enum tree_code code;
   optab this_optab;
   rtx subtarget, original_target;
   int ignore;
@@ -6840,6 +6840,9 @@
                                                                  type)   \
                                 : (expr))

+  if (TREE_CODE (exp) != COND_EXPR && !GIMPLE_TUPLE_P (exp))
+    exp = fold (exp);
+  code = TREE_CODE(exp);
   if (GIMPLE_STMT_P (exp))
     {
       type = void_type_node;



Makes all functions emit the same code.


-- 


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


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

* [Bug middle-end/31531] A microoptimization of isnegative of signed integer
  2007-04-10 18:05 [Bug c/31531] New: A microoptimization of isnegative or greaterthan2millions JCPiza at gmail dot com
                   ` (2 preceding siblings ...)
  2007-04-10 18:20 ` pinskia at gcc dot gnu dot org
@ 2007-04-15  5:43 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-04-15  5:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2007-04-15 06:43 -------
There are a couple of ways of fixing this bug, folding while going out of ssa. 
Doing a tree combined which is PR 15459.  Or the patch which I attached.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  BugsThisDependsOn|                            |15459
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2007-04-15 06:43:24
               date|                            |


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


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

end of thread, other threads:[~2007-04-15  5:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-10 18:05 [Bug c/31531] New: A microoptimization of isnegative or greaterthan2millions JCPiza at gmail dot com
2007-04-10 18:14 ` [Bug c/31531] " JCPiza at gmail dot com
2007-04-10 18:17 ` [Bug middle-end/31531] A microoptimization of isnegative of signed integer pinskia at gcc dot gnu dot org
2007-04-10 18:20 ` pinskia at gcc dot gnu dot org
2007-04-15  5:43 ` pinskia at gcc dot gnu dot org

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