This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR optimization/1823: -ftrapv issue in expand_divmod


On Wed, 3 Sep 2003, Richard Henderson wrote:
> On Tue, Sep 02, 2003 at 02:01:25PM -0600, Roger Sayle wrote:
> > 	* 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.
>
> I don't think this is correct.  Trapv should only apply to
> signed multiplication, whereas this division transformation
> should be using unsigned multiplication.
>
> Can you figure out which of these assumptions is false?

The later. Trapv does only apply to signed multiplication [the
code that decides whether to use smulv_optab or smul_optab in
expand_mult uses the logic "! unsignedp && trapv && ...".]

However, the optimization itself does use signed multiplication.
The division resulting from the subtraction of two pointers is
itself signed (the result may be negative), and the implementation
of this transformation explicitly requests the use of a signed
multiplication (expand_divmod, line 3823 of expmed.c):

> t1 = expand_shift (RSHIFT_EXPR, compute_mode, op0,
>                    build_int_2 (pre_shift, 0), NULL_RTX, unsignedp);
> quotient = expand_mult (compute_mode, t1,
>                         gen_int_mode (ml, compute_mode),
>                         NULL_RTX, 0);

Notice that although the expand_shift uses the unsignedp from the
division, the multiplication always passes zero as the unsignedp
argument to expand_mult.

I don't have a copy of Torbjorn Granlund and Peter L. Montgomery,
"Division by Invariant Integers using Multiplication", SIGPLAN 1994,
so it isn't clear whether its possible to implement EXACT_DIV_EXPR
using unsigned multiplication for some denominators.  The use of a
signed multiplication however has been very well tested.

Roger
--


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]