public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/16795] New: PowerPC - Divide sequences by negative power of two could be more efficient
@ 2004-07-28 17:00 gcc-bugzilla at gcc dot gnu dot org
  2004-07-28 17:36 ` [Bug target/16795] " bangerth at dealii dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gcc-bugzilla at gcc dot gnu dot org @ 2004-07-28 17:00 UTC (permalink / raw)
  To: gcc-bugs

Description:
A non-optimal code sequence is illustraded.  Dividing by a negative power of two could be more efficiently done.  Duplicate using gcc 3.5 and command line:

gcc -O3 -m64 -c test.c

Testcase:
int x;

void foo1() {

  x /= -0x2;

}

void foo2() {

  x /= -0x4;

}

Assembly:
Code generated for "foo1" looks like this:

.foo:
	ld 9,.LC0@toc(2)
	lwz 5,0(9)
	srwi 11,5,31
	add 4,5,11
	srawi 3,4,1
	neg 0,3
	stw 0,0(9)
	blr

A better alternative would be this:

.foo:
	ld 9,.LC0@toc(2)
	lwz 5,0(9)
	srawi 0,5,1
	addze 3,0
	neg 0,3
	stw 0,0(9)
	blr

Code generated for "foo2" looks like this:

.foo:
	ld 9,.LC0@toc(2)
	lwz 5,0(9)
	srawi 6,5,31
	srwi 11,6,30
	add 4,5,11
	srawi 3,4,2
	neg 0,3
	stw 0,0(9)
	blr

More optimal sequence would be:

.foo:
	ld 9,.LC0@toc(2)
	lwz 5,0(9)
	srawi 0,5,2
	addze 3,0
	neg 0,3
	stw 0,0(9)
	blr



-- 
           Summary: PowerPC - Divide sequences by negative power of two
                    could be more efficient
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P1
         Component: other
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: steinmtz at us dot ibm dot com
                CC: gcc-bugs at gcc dot gnu dot org,steinmtz at us dot ibm
                    dot com
 GCC build triplet: powerpc64-linux
  GCC host triplet: powerpc64-linux
GCC target triplet: powerpc64-linux


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


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

* [Bug target/16795] PowerPC - Divide sequences by negative power of two could be more efficient
  2004-07-28 17:00 [Bug other/16795] New: PowerPC - Divide sequences by negative power of two could be more efficient gcc-bugzilla at gcc dot gnu dot org
@ 2004-07-28 17:36 ` bangerth at dealii dot org
  2004-09-12  3:40 ` dje at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: bangerth at dealii dot org @ 2004-07-28 17:36 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|other                       |target


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


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

* [Bug target/16795] PowerPC - Divide sequences by negative power of two could be more efficient
  2004-07-28 17:00 [Bug other/16795] New: PowerPC - Divide sequences by negative power of two could be more efficient gcc-bugzilla at gcc dot gnu dot org
  2004-07-28 17:36 ` [Bug target/16795] " bangerth at dealii dot org
@ 2004-09-12  3:40 ` dje at gcc dot gnu dot org
  2004-09-12  5:37 ` [Bug middle-end/16795] " pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: dje at gcc dot gnu dot org @ 2004-09-12  3:40 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dje at gcc dot gnu dot org  2004-09-12 03:40 -------
For positive power of 2 constants, expand_divmod checks if divide is cheap, but
for negative power of 2 constants, it does not.  The following patch negates the
cheap divide by power of 2 of the absolute value and then negates the result.

*************** expand_divmod (int rem_flag, enum tree_c
*** 3764,3770 ****
                        if (remainder)
                          return gen_lowpart (mode, remainder);
                      }
!                   quotient = expand_sdiv_pow2 (compute_mode, op0, abs_d);
  
                    /* We have computed OP0 / abs(OP1).  If OP1 is negative,
                       negate the quotient.  */
--- 3764,3782 ----
                        if (remainder)
                          return gen_lowpart (mode, remainder);
                      }
! 
!                   if (sdiv_pow2_cheap[compute_mode]
!                       && ((sdiv_optab->handlers[compute_mode].insn_code
!                            != CODE_FOR_nothing)
!                           || (sdivmod_optab->handlers[compute_mode].insn_code
!                               != CODE_FOR_nothing)))
!                     quotient = expand_divmod (0, TRUNC_DIV_EXPR,
!                                               compute_mode, op0,
!                                               gen_int_mode (abs_d,
!                                                             compute_mode),
!                                               NULL_RTX, 0);
!                   else
!                     quotient = expand_sdiv_pow2 (compute_mode, op0, abs_d);


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2004-09-12 03:40:14
               date|                            |


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


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

* [Bug middle-end/16795] PowerPC - Divide sequences by negative power of two could be more efficient
  2004-07-28 17:00 [Bug other/16795] New: PowerPC - Divide sequences by negative power of two could be more efficient gcc-bugzilla at gcc dot gnu dot org
  2004-07-28 17:36 ` [Bug target/16795] " bangerth at dealii dot org
  2004-09-12  3:40 ` dje at gcc dot gnu dot org
@ 2004-09-12  5:37 ` pinskia at gcc dot gnu dot org
  2004-09-12 20:05 ` cvs-commit at gcc dot gnu dot org
  2004-09-12 20:40 ` dje at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-09-12  5:37 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-09-12 05:37 -------
Patch posted here: <http://gcc.gnu.org/ml/gcc-patches/2004-09/msg01137.html>.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch


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


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

* [Bug middle-end/16795] PowerPC - Divide sequences by negative power of two could be more efficient
  2004-07-28 17:00 [Bug other/16795] New: PowerPC - Divide sequences by negative power of two could be more efficient gcc-bugzilla at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2004-09-12  5:37 ` [Bug middle-end/16795] " pinskia at gcc dot gnu dot org
@ 2004-09-12 20:05 ` cvs-commit at gcc dot gnu dot org
  2004-09-12 20:40 ` dje at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu dot org @ 2004-09-12 20:05 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From cvs-commit at gcc dot gnu dot org  2004-09-12 20:05 -------
Subject: Bug 16795

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	dje@gcc.gnu.org	2004-09-12 20:05:32

Modified files:
	gcc            : ChangeLog expmed.c 

Log message:
	PR target/16795
	* expmed.c (expand_divmod): If cheap power of 2 divide is
	available, use it for negative constant as well.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.5410&r2=2.5411
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/expmed.c.diff?cvsroot=gcc&r1=1.195&r2=1.196



-- 


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


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

* [Bug middle-end/16795] PowerPC - Divide sequences by negative power of two could be more efficient
  2004-07-28 17:00 [Bug other/16795] New: PowerPC - Divide sequences by negative power of two could be more efficient gcc-bugzilla at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2004-09-12 20:05 ` cvs-commit at gcc dot gnu dot org
@ 2004-09-12 20:40 ` dje at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: dje at gcc dot gnu dot org @ 2004-09-12 20:40 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From dje at gcc dot gnu dot org  2004-09-12 20:40 -------
Patch committed

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.0.0


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


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

end of thread, other threads:[~2004-09-12 20:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-28 17:00 [Bug other/16795] New: PowerPC - Divide sequences by negative power of two could be more efficient gcc-bugzilla at gcc dot gnu dot org
2004-07-28 17:36 ` [Bug target/16795] " bangerth at dealii dot org
2004-09-12  3:40 ` dje at gcc dot gnu dot org
2004-09-12  5:37 ` [Bug middle-end/16795] " pinskia at gcc dot gnu dot org
2004-09-12 20:05 ` cvs-commit at gcc dot gnu dot org
2004-09-12 20:40 ` dje 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).