User account creation filtered due to spam.

Bug 33555 - x86 missed opportunity for sbb
Summary: x86 missed opportunity for sbb
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.3.0
: P3 enhancement
Target Milestone: 4.4.0
Assignee: Uroš Bizjak
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: missed-optimization, patch
: 41677 (view as bug list)
Depends on:
Blocks: 4.4pending
  Show dependency treegraph
 
Reported: 2007-09-25 18:17 UTC by Alexander Strange
Modified: 2009-10-11 20:18 UTC (History)
3 users (show)

See Also:
Host: i386-apple-darwin8.10.1
Target: i386-apple-darwin8.10.1
Build: i386-apple-darwin8.10.1
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Patch to implement missed optimization. (631 bytes, patch)
2008-02-18 09:58 UTC, Uroš Bizjak
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Strange 2007-09-25 18:17:44 UTC
> /usr/local/gcc43/bin/gcc -v
Using built-in specs.
Target: i386-apple-darwin8.10.1
Configured with: ../gcc/configure --prefix=/usr/local/gcc43 --with-arch=nocona --with-tune=nocona --with-gmp=/sw --with-system-zlib --enable-languages=c,c++,objc,obj-c++
Thread model: posix
gcc version 4.3.0 20070925 (experimental) (GCC) 

> /usr/local/gcc43/bin/gcc -Os -fno-pic -S sbb.c -fomit-frame-pointer
        .text
.globl _cmpb_sbb
_cmpb_sbb:
        subl    $12, %esp
        movl    16(%esp), %eax
        movl    20(%esp), %ecx
        xorl    %edx, %edx
        cmpl    24(%esp), %ecx
        setb   %dl
        negl    %edx
        andl    %ecx, %edx
        subl    %edx, %eax
        addl    $12, %esp
        ret
        .subsections_via_symbols

Source:
unsigned cmpb_sbb(unsigned a, unsigned b, unsigned c)
{
	unsigned mask = -(b < c);
	
	a -= b & mask;
	return a;
}

"setb, negl" is the same as 0 - (0 + eflags.CF), so it can be replaced with "sbb %edx, %edx".
This is useful for if-conversion, since it's the same as "if (b < c) a -= b;"
Comment 1 Uroš Bizjak 2008-02-18 09:58:08 UTC
Created attachment 15183 [details]
Patch to implement missed optimization.

2008-02-18  Uros Bizjak  <ubizjak@gmail.com>

	PR target/33555
	* config/i386/i386.md (*x86_movsicc_0_m1_se): New insn pattern.
	(*x86_movdicc_0_m1_se): Ditto.

testsuite/ChangeLog:

2008-02-18  Uros Bizjak  <ubizjak@gmail.com>

	PR target/33555
	* gcc.target/i386/pr33555.c: New test.
Comment 2 uros 2008-02-19 07:24:11 UTC
Subject: Bug 33555

Author: uros
Date: Tue Feb 19 07:23:30 2008
New Revision: 132414

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=132414
Log:
        PR target/33555
        * config/i386/i386.md (*x86_movsicc_0_m1_se): New insn pattern.
        (*x86_movdicc_0_m1_se): Ditto.

testsuite/ChangeLog:

        PR target/33555
        * gcc.target/i386/pr33555.c: New test.


Added:
    trunk/gcc/testsuite/gcc.target/i386/pr33555.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.md
    trunk/gcc/testsuite/ChangeLog

Comment 3 Uroš Bizjak 2008-02-19 07:41:33 UTC
Fixed.
Comment 4 Uroš Bizjak 2009-10-11 20:18:14 UTC
*** Bug 41677 has been marked as a duplicate of this bug. ***