Bug 44588 - Very inefficient 8bit mod/div
Summary: Very inefficient 8bit mod/div
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords:
Depends on:
Blocks:
 
Reported: 2010-06-19 00:49 UTC by H.J. Lu
Modified: 2010-07-07 21:42 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
A patch (915 bytes, patch)
2010-06-19 00:52 UTC, H.J. Lu
Details | Diff
An updated patch (1.63 KB, patch)
2010-06-19 19:03 UTC, H.J. Lu
Details | Diff
Another update (1.66 KB, patch)
2010-06-20 01:59 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2010-06-19 00:49:48 UTC
On x86, I got

[hjl@gnu-6 divb]$ cat umod-2.c 
extern unsigned char z;

unsigned char
foo (unsigned char x, unsigned char y)
{
  z = x/y;
   return x % y;
}
[hjl@gnu-6 divb]$ gcc -S -O3 umod-2.c
[hjl@gnu-6 divb]$ cat umod-2.s
	.file	"umod-2.c"
	.text
	.p2align 4,,15
.globl foo
	.type	foo, @function
foo:
.LFB0:
	.cfi_startproc
	movzbl	%dil, %edi
	movzbl	%sil, %ecx
	xorl	%edx, %edx
	movl	%edi, %eax
	divb	%sil
	movb	%al, z(%rip)
	movl	%edi, %eax
	divw	%cx
	movl	%edx, %eax
	ret
Comment 1 H.J. Lu 2010-06-19 00:52:29 UTC
Created attachment 20941 [details]
A patch

With this patch, I got

foo:
.LFB0:
	.cfi_startproc
	movl	%edi, %eax
	divb	%sil
	movb	%al, z(%rip)
	movsbl	%ah, %eax
	ret
Comment 2 H.J. Lu 2010-06-19 19:03:50 UTC
Created attachment 20943 [details]
An updated patch

8bit divide is AX / r/m8. Here is the updated patch.
Now it generates:

foo:
.LFB0:
	.cfi_startproc
	movzbl	%dil, %eax
	divb	%sil
	movzbl	%al, %edx
	movzbl	%ah, %eax
	movb	%dl, z(%rip)
	ret
Comment 3 H.J. Lu 2010-06-20 01:59:15 UTC
Created attachment 20944 [details]
Another update

This patch removes EFLAGS clobber for sign extend.
Comment 4 H.J. Lu 2010-06-22 17:30:29 UTC
The patch is posted at

http://gcc.gnu.org/ml/gcc-patches/2010-06/msg02200.html
Comment 5 hjl@gcc.gnu.org 2010-06-24 18:20:44 UTC
Subject: Bug 44588

Author: hjl
Date: Thu Jun 24 18:20:28 2010
New Revision: 161329

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=161329
Log:
Implement 8bit divmod patterns.

gcc/

2010-06-24  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/44588
	* config/i386/i386.md (extract_code): New.
	(<u>divmodqi4): Likewise.
	(divmodhiqi3): Likewise.
	(udivmodhiqi3): Likewise.
	(<u>divqi3): Remvoved.

gcc/testsuite/

2010-06-24  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/44588
	* gcc.target/i386/mod-1.c: New.
	* gcc.target/i386/umod-1.c: Likewise.
	* gcc.target/i386/umod-2.c: Likewise.
	* gcc.target/i386/umod-3.c: Likewise.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.md
    trunk/gcc/testsuite/ChangeLog

Comment 6 hjl@gcc.gnu.org 2010-06-24 18:21:45 UTC
Subject: Bug 44588

Author: hjl
Date: Thu Jun 24 18:21:21 2010
New Revision: 161330

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=161330
Log:
Add missing testcases for PR 44588.

Added:
    trunk/gcc/testsuite/gcc.target/i386/mod-1.c
    trunk/gcc/testsuite/gcc.target/i386/umod-1.c
    trunk/gcc/testsuite/gcc.target/i386/umod-2.c
    trunk/gcc/testsuite/gcc.target/i386/umod-3.c

Comment 7 hjl@gcc.gnu.org 2010-07-07 21:11:48 UTC
Subject: Bug 44588

Author: hjl
Date: Wed Jul  7 21:11:25 2010
New Revision: 161933

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=161933
Log:
Backport 8bit div/mod improvements.

gcc/

2010-07-07  H.J. Lu  <hongjiu.lu@intel.com>

	Backport from mainline
	2010-07-04  H.J. Lu  <hongjiu.lu@intel.com>

	PR rtl-optimization/44695
	* config/i386/i386.md (extract_code): Removed.
	(<u>divmodqi4): Likewise.
	(divmodqi4): New.
	(udivmodqi4): Likewise.
	(divmodhiqi3): Change div/mod to HImode and extend operand 2 to
	HImode.
	(udivmodhiqi3): Likewise.

	2010-06-24  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/44588
	* config/i386/i386.md (extract_code): New.
	(<u>divmodqi4): Likewise.
	(divmodhiqi3): Likewise.
	(udivmodhiqi3): Likewise.
	(<u>divqi3): Remvoved.

gcc/testsuite/

2010-07-07  H.J. Lu  <hongjiu.lu@intel.com>

	Backport from mainline
	2010-07-04  H.J. Lu  <hongjiu.lu@intel.com>

	PR rtl-optimization/44695
	* gcc.dg/torture/pr44695.c: New.

	2010-06-24  H.J. Lu  <hongjiu.lu@intel.com>

	PR target/44588
	* gcc.target/i386/mod-1.c: New.
	* gcc.target/i386/umod-1.c: Likewise.
	* gcc.target/i386/umod-2.c: Likewise.
	* gcc.target/i386/umod-3.c: Likewise.

Modified:
    branches/ix86/gcc-4_5-branch/gcc/config/i386/i386.md

Comment 8 H.J. Lu 2010-07-07 21:42:47 UTC
Fixed.