This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] PR optimization/1823: -ftrapv issue in expand_divmod
- From: Roger Sayle <roger at eyesopen dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Falk Hueffner <falk dot hueffner at student dot uni-tuebingen dot de>
- Date: Tue, 2 Sep 2003 14:01:25 -0600 (MDT)
- Subject: [PATCH] PR optimization/1823: -ftrapv issue in expand_divmod
The following patch is Falk Hueffner's proposed solution to PR
optimization/1823. GCC occassionally implements integer division by
a compile time constant using a multiplication. This multiplication
works by overflowing the word size, leaving the correct result in the
low order bits. Unfortunately, this implementation strategy can't
safely be used with -ftrapv, as the overflowing multiplication will
call abort at run-time.
This patch fixes the problem by disabling the unsafe optimization.
I'm unsure how portable tests for -ftrapv are. Doing a grep of the
entire GCC testsuite reveals that we currently have no -ftrapv tests
at all.
The following patch has been tested on i686-pc-linux-gnu with a complete
"make bootstrap", all languages except treelang, and regression tested
with a top-level "make -k check" with no new failures. I've confirmed
that it fixes the failing example attached to the PR.
Ok for mainline?
2003-09-02 Falk Hueffner <falk.hueffner@student.uni-tuebingen.de>
Roger Sayle <roger@eyesopen.com>
PR optimization/1823
* expmed.c (expand_divmod <EXACT_DIV_EXPR>): Don't use the
overflowing multiplication method to implement exact division
by an integer constant when the user has specified -ftrapv.
Index: expmed.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/expmed.c,v
retrieving revision 1.140
diff -c -3 -p -r1.140 expmed.c
*** expmed.c 22 Aug 2003 06:45:13 -0000 1.140
--- expmed.c 2 Sep 2003 03:15:40 -0000
*************** expand_divmod (int rem_flag, enum tree_c
*** 3811,3817 ****
break;
case EXACT_DIV_EXPR:
! if (op1_is_constant && HOST_BITS_PER_WIDE_INT >= size)
{
HOST_WIDE_INT d = INTVAL (op1);
unsigned HOST_WIDE_INT ml;
--- 3811,3819 ----
break;
case EXACT_DIV_EXPR:
! if (op1_is_constant
! && HOST_BITS_PER_WIDE_INT >= size
! && ! flag_trapv)
{
HOST_WIDE_INT d = INTVAL (op1);
unsigned HOST_WIDE_INT ml;
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833