public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/22199] New: Unnecessary casts for comparison
@ 2005-06-27 15:04 tkoenig at gcc dot gnu dot org
  2005-06-27 15:18 ` [Bug tree-optimization/22199] " pinskia at gcc dot gnu dot org
  2005-09-24 16:22 ` [Bug tree-optimization/22199] fold does not optimize (int)ABS_EXPR<(long long)(int_var)> pinskia at gcc dot gnu dot org
  0 siblings, 2 replies; 6+ messages in thread
From: tkoenig at gcc dot gnu dot org @ 2005-06-27 15:04 UTC (permalink / raw)
  To: gcc-bugs

$ cat labs.c
extern long int labs (long int __x) __attribute__ ((__const__));

int main()
{
    int a,b;
    foo(&a, &b);
    if (labs(a) > b)
        return 1;
    else
        return 0;
}

is translated with

$ gcc -O3 -fdump-tree-optimized -S labs.c

into

<bb 0>:
  foo (&a, &b);
  return (int) (ABS_EXPR <(long int) a> > (long int) b);

The casts aren't necessary in this case.

-- 
           Summary: Unnecessary casts for comparison
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: tkoenig at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug tree-optimization/22199] Unnecessary casts for comparison
  2005-06-27 15:04 [Bug tree-optimization/22199] New: Unnecessary casts for comparison tkoenig at gcc dot gnu dot org
@ 2005-06-27 15:18 ` pinskia at gcc dot gnu dot org
  2005-09-24 16:22 ` [Bug tree-optimization/22199] fold does not optimize (int)ABS_EXPR<(long long)(int_var)> pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-06-27 15:18 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-06-27 15:17 -------
A better example as on 32bit targets long and int are the same size which removes the casts:
extern long long int llabs (long long int __x) __attribute__ ((__const__));

int main()
{
    int a,b;
    foo(&a, &b);
    if (llabs(a) > b)
        return 1;
    else
        return 0;
}

Or just as good:
extern int abs (int __x) __attribute__ ((__const__));


void foo(short *, short*);

int main()
{
    short a,b;
    foo(&a, &b);
    if (abs(a) > b)
        return 1;
    else
        return 0;
}

Though only the first one will have different asm and will be better optimized.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2005-06-27 15:17:41
               date|                            |


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


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

* [Bug tree-optimization/22199] fold does not optimize (int)ABS_EXPR<(long long)(int_var)>
  2005-06-27 15:04 [Bug tree-optimization/22199] New: Unnecessary casts for comparison tkoenig at gcc dot gnu dot org
  2005-06-27 15:18 ` [Bug tree-optimization/22199] " pinskia at gcc dot gnu dot org
@ 2005-09-24 16:22 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-24 16:22 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-09-24 16:22 -------
Changing the summary to be more reflect what this bug is about.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
OtherBugsDependingO|                            |19987
              nThis|                            |
   Last reconfirmed|2005-06-27 15:17:41         |2005-09-24 16:22:48
               date|                            |
            Summary|Unnecessary casts for       |fold does not optimize
                   |comparison                  |(int)ABS_EXPR<(long
                   |                            |long)(int_var)>


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


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

* [Bug tree-optimization/22199] fold does not optimize (int)ABS_EXPR<(long long)(int_var)>
       [not found] <bug-22199-4@http.gcc.gnu.org/bugzilla/>
  2021-06-03  3:35 ` pinskia at gcc dot gnu.org
@ 2021-06-03  3:37 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-03  3:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=22199

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |9.0

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed with r9-1281 by the way.

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

* [Bug tree-optimization/22199] fold does not optimize (int)ABS_EXPR<(long long)(int_var)>
       [not found] <bug-22199-4@http.gcc.gnu.org/bugzilla/>
@ 2021-06-03  3:35 ` pinskia at gcc dot gnu.org
  2021-06-03  3:37 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-03  3:35 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=22199

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
There is ABSU now.
Which we use now:
  a.0_1 = a;
  _2 = ABSU_EXPR <a.0_1>;
  _3 = (long int) _2;
  b.1_4 = b;

So fixed.

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

* [Bug tree-optimization/22199] fold does not optimize (int)ABS_EXPR<(long long)(int_var)>
       [not found] <bug-22199-10391@http.gcc.gnu.org/bugzilla/>
@ 2005-12-24 20:15 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-12-24 20:15 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2005-12-24 20:15 -------
Hmm, actually this is not really valid to do except when -fwrapv is supplied as
(int)ABS_EXPR<(long long) 0x80000000 > is defined to be 0 but ABS_EXPR<
(int)0x80000000> is undefined.


-- 


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


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

end of thread, other threads:[~2021-06-03  3:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-27 15:04 [Bug tree-optimization/22199] New: Unnecessary casts for comparison tkoenig at gcc dot gnu dot org
2005-06-27 15:18 ` [Bug tree-optimization/22199] " pinskia at gcc dot gnu dot org
2005-09-24 16:22 ` [Bug tree-optimization/22199] fold does not optimize (int)ABS_EXPR<(long long)(int_var)> pinskia at gcc dot gnu dot org
     [not found] <bug-22199-10391@http.gcc.gnu.org/bugzilla/>
2005-12-24 20:15 ` pinskia at gcc dot gnu dot org
     [not found] <bug-22199-4@http.gcc.gnu.org/bugzilla/>
2021-06-03  3:35 ` pinskia at gcc dot gnu.org
2021-06-03  3:37 ` pinskia at gcc dot gnu.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).