Bug 18045 - [4.0 Regression] signed integer remainder for power of 2 broken
Summary: [4.0 Regression] signed integer remainder for power of 2 broken
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.0.0
: P2 critical
Target Milestone: 4.0.0
Assignee: Eric Botcazou
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2004-10-18 12:06 UTC by Eric Botcazou
Modified: 2004-10-18 22:47 UTC (History)
2 users (show)

See Also:
Host: i486-*-*
Target: i486-*-*
Build: i486-*-*
Known to work: 3.4.0
Known to fail: 4.0.0
Last reconfirmed: 2004-10-18 12:56:35


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Botcazou 2004-10-18 12:06:30 UTC
The following testcase:

extern void abort(void);

long long smod16(long long x)
{
  return x % 16;
}

int main(void)
{
  if (smod16 (0xFFFFFFFF) != 0xF)
    abort ();

  return 0;
}

distilled from ada/uintp.adb:UI_From_Dint is miscompiled on i486 because of

2004-06-27  Roger Sayle  <roger@eyesopen.com>

	* expmed.c (expand_smod_pow2): New function to expand signed
	remainder by a constant power of 2, such as "x % 16".
	(expand_divmod): Call new expand_smod_pow2 when appropriate.
	Minor corrections to comments, e.g. splitting long lines.


The second part of expand_smod_pow2 cannot handle modes whose size is greater
than that of HOST_WIDE_INT.
Comment 1 Andrew Pinski 2004-10-18 12:56:34 UTC
Confirmed (-march=i486 will show the bug on i686-*).
Comment 2 Eric Botcazou 2004-10-18 13:44:57 UTC
Thanks for confirming (I think -mtune=i486 is sufficient).  Patch in testing.
Comment 3 GCC Commits 2004-10-18 22:45:08 UTC
Subject: Bug 18045

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	ebotcazou@gcc.gnu.org	2004-10-18 22:45:01

Modified files:
	gcc            : ChangeLog expmed.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: smod-1.c 

Log message:
	PR middle-end/18045
	* expmed.c (expand_smod_pow2): Handle modes whose size
	is greater than that of HOST_WIDE_INT.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.5940&r2=2.5941
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/expmed.c.diff?cvsroot=gcc&r1=1.198&r2=1.199
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4472&r2=1.4473
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/smod-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 4 Eric Botcazou 2004-10-18 22:47:45 UTC
See http://gcc.gnu.org/ml/gcc-patches/2004-10/msg01571.html