public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug optimization/14347] New: ifconvert doesn't generate conditional store on i386
@ 2004-02-29 16:57 ak at muc dot de
  2004-02-29 17:17 ` [Bug optimization/14347] " pinskia at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: ak at muc dot de @ 2004-02-29 16:57 UTC (permalink / raw)
  To: gcc-bugs

x86 doesn't have a conditional store instruction. But it can be simulated.

e.g. in

int foo;

void f(int x) 
{
    if (x == 1) 
       foo = 2;          /* generates a jump */
} 

the jump can be avoided with

void f(int x)
{ 
    int dummy;
    int *fooptr = &dummy;
    if (x == 1) 
        fooptr = &foo;         /* will generate a CMOV and no jump */ 
     *fooptr = 2;
}
       
I think this woule be an useful optimization to have. Right place is probably
ifcvt.c, but it just needs to be somehow taught to generate dummy stack
variables and then recognize this idiom. Also the target may need to set some
flag that it doesn't support conditional stores and they need to be simulated.

It's probably better to generate a new variable for each such optimization to
avoid possible store conflict stalls.

This may help on other architectures with a missing conditional store too.

-- 
           Summary: ifconvert doesn't generate conditional store on i386
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P2
         Component: optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ak at muc dot de
                CC: gcc-bugs at gcc dot gnu dot org
GCC target triplet: i386-*, x86_64-*


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


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

* [Bug optimization/14347] ifconvert doesn't generate conditional store on i386
  2004-02-29 16:57 [Bug optimization/14347] New: ifconvert doesn't generate conditional store on i386 ak at muc dot de
@ 2004-02-29 17:17 ` pinskia at gcc dot gnu dot org
  2004-05-31  1:57 ` [Bug rtl-optimization/14347] " pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-02-29 17:17 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-02-29 17:17 -------
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |pessimizes-code
   Last reconfirmed|0000-00-00 00:00:00         |2004-02-29 17:17:42
               date|                            |


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


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

* [Bug rtl-optimization/14347] ifconvert doesn't generate conditional store on i386
  2004-02-29 16:57 [Bug optimization/14347] New: ifconvert doesn't generate conditional store on i386 ak at muc dot de
  2004-02-29 17:17 ` [Bug optimization/14347] " pinskia at gcc dot gnu dot org
@ 2004-05-31  1:57 ` pinskia at gcc dot gnu dot org
  2004-05-31 17:55 ` ak at muc dot de
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-31  1:57 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-05-30 03:48 -------
This has been fixed since 3.3.3, note that -march=pentium3 is needed to get the cmov instruction.
This is what I get in 3.3.3, 3.4.0, and 3.5.0 for the first function:
f:
        cmpl    $1, 4(%esp)
        movl    $2, %edx
        cmovne  foo, %edx
        movl    %edx, foo
        ret

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


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


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

* [Bug rtl-optimization/14347] ifconvert doesn't generate conditional store on i386
  2004-02-29 16:57 [Bug optimization/14347] New: ifconvert doesn't generate conditional store on i386 ak at muc dot de
  2004-02-29 17:17 ` [Bug optimization/14347] " pinskia at gcc dot gnu dot org
  2004-05-31  1:57 ` [Bug rtl-optimization/14347] " pinskia at gcc dot gnu dot org
@ 2004-05-31 17:55 ` ak at muc dot de
  2004-05-31 18:13 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ak at muc dot de @ 2004-05-31 17:55 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ak at muc dot de  2004-05-30 16:23 -------
Hi, Andrew. 

The example you showed is a conditional load, not a conditional store.
Conditional load has always worked.

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


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


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

* [Bug rtl-optimization/14347] ifconvert doesn't generate conditional store on i386
  2004-02-29 16:57 [Bug optimization/14347] New: ifconvert doesn't generate conditional store on i386 ak at muc dot de
                   ` (2 preceding siblings ...)
  2004-05-31 17:55 ` ak at muc dot de
@ 2004-05-31 18:13 ` pinskia at gcc dot gnu dot org
  2004-05-31 18:34 ` ak at muc dot de
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-31 18:13 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |NEW
   Target Milestone|3.3.3                       |---


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


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

* [Bug rtl-optimization/14347] ifconvert doesn't generate conditional store on i386
  2004-02-29 16:57 [Bug optimization/14347] New: ifconvert doesn't generate conditional store on i386 ak at muc dot de
                   ` (3 preceding siblings ...)
  2004-05-31 18:13 ` pinskia at gcc dot gnu dot org
@ 2004-05-31 18:34 ` ak at muc dot de
  2004-05-31 18:48 ` pinskia at gcc dot gnu dot org
  2004-05-31 22:19 ` ak at muc dot de
  6 siblings, 0 replies; 8+ messages in thread
From: ak at muc dot de @ 2004-05-31 18:34 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ak at muc dot de  2004-05-30 17:02 -------
Sorry reading this again, you're right.
it looks a bit broken though since it will always dirty the cache line,
which can be much more costly than doing the jump. Not sure if that's a 
good way. The original way I propose by doing the CMOV on the target
address would avoid this problem.

-- 


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


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

* [Bug rtl-optimization/14347] ifconvert doesn't generate conditional store on i386
  2004-02-29 16:57 [Bug optimization/14347] New: ifconvert doesn't generate conditional store on i386 ak at muc dot de
                   ` (4 preceding siblings ...)
  2004-05-31 18:34 ` ak at muc dot de
@ 2004-05-31 18:48 ` pinskia at gcc dot gnu dot org
  2004-05-31 22:19 ` ak at muc dot de
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-31 18:48 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-05-30 18:10 -------
So closing as fixed again.

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


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


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

* [Bug rtl-optimization/14347] ifconvert doesn't generate conditional store on i386
  2004-02-29 16:57 [Bug optimization/14347] New: ifconvert doesn't generate conditional store on i386 ak at muc dot de
                   ` (5 preceding siblings ...)
  2004-05-31 18:48 ` pinskia at gcc dot gnu dot org
@ 2004-05-31 22:19 ` ak at muc dot de
  6 siblings, 0 replies; 8+ messages in thread
From: ak at muc dot de @ 2004-05-31 22:19 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ak at muc dot de  2004-05-31 12:34 -------
Well, the optimization is clearly bogus since it will unncessarily
dirty cache lines, which can be extremly costly. It can also require programs 
that didn't need volatile before require to add volatile to add SMP races
(that's legal as done by the compiler, but not very nice) But I will open a
separate bug for that.

-- 


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


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

end of thread, other threads:[~2004-05-31 12:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-29 16:57 [Bug optimization/14347] New: ifconvert doesn't generate conditional store on i386 ak at muc dot de
2004-02-29 17:17 ` [Bug optimization/14347] " pinskia at gcc dot gnu dot org
2004-05-31  1:57 ` [Bug rtl-optimization/14347] " pinskia at gcc dot gnu dot org
2004-05-31 17:55 ` ak at muc dot de
2004-05-31 18:13 ` pinskia at gcc dot gnu dot org
2004-05-31 18:34 ` ak at muc dot de
2004-05-31 18:48 ` pinskia at gcc dot gnu dot org
2004-05-31 22:19 ` ak at muc dot de

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