public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/14224] GCC generates pessimizes code for integer division
       [not found] <bug-14224-4@http.gcc.gnu.org/bugzilla/>
@ 2021-06-08  8:41 ` pinskia at gcc dot gnu.org
  2021-06-08  8:59 ` jakub at gcc dot gnu.org
  1 sibling, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-08  8:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14224

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Uroš Bizjak from comment #2)
> I suggest to mark this bug as invalid, because it is not possible for gcc to
> know maximum value of (x*y).

Invalid then.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/14224] GCC generates pessimizes code for integer division
       [not found] <bug-14224-4@http.gcc.gnu.org/bugzilla/>
  2021-06-08  8:41 ` [Bug target/14224] GCC generates pessimizes code for integer division pinskia at gcc dot gnu.org
@ 2021-06-08  8:59 ` jakub at gcc dot gnu.org
  1 sibling, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-06-08  8:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=14224

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Well, during expansion VRP can be queried (SSA_NAME_RANGE_INFO or ranger if it
is extended to be queryable during expansion) and in some cases (not in the #c0
testcase though) we can know the range.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/14224] GCC generates pessimizes code for integer division
  2004-02-20 11:38 [Bug c/14224] New: GCC generates bad assembly " terpstra at ito dot tu-darmstadt dot de
                   ` (2 preceding siblings ...)
  2004-04-05 14:58 ` terpstra at ito dot tu-darmstadt dot de
@ 2004-06-03  3:56 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-06-03  3:56 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-06-03 03:56 -------
*** Bug 14255 has been marked as a duplicate of this bug. ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bernie at develer dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14224


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/14224] GCC generates pessimizes code for integer division
  2004-02-20 11:38 [Bug c/14224] New: GCC generates bad assembly " terpstra at ito dot tu-darmstadt dot de
  2004-02-20 16:23 ` [Bug target/14224] GCC generates pessimizes code " pinskia at gcc dot gnu dot org
  2004-04-05 13:31 ` uros at kss-loka dot si
@ 2004-04-05 14:58 ` terpstra at ito dot tu-darmstadt dot de
  2004-06-03  3:56 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 6+ messages in thread
From: terpstra at ito dot tu-darmstadt dot de @ 2004-04-05 14:58 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From terpstra at ito dot tu-darmstadt dot de  2004-04-05 14:57 -------
(In reply to comment #2)
> Problem here is, that maximum quotient should always be 2^32-1, as it should fit
> in 32bit EAX register. Consider the case, when dividend is 0x0000 0001 0000 0000
> and divisor is 0x0000 0001. The result won't fit in 32 bits, and division will
> produce #DE exception.
> 
> For your case, divisor is 0xC000 0001. And with your assembly, if x*y is equal
> or more than 0xC000 0001 0000 0000 (= 13835058059577131008), #DE exception will
> be generated.

You're quite right; I hadn't considered this.

> I suggest to mark this bug as invalid, because it is not possible for gcc to
> know maximum value of (x*y).

It's really a shame there's no way to inform gcc about the size.
For modulus arithmetic, x and y are known to be less than m.
Therefore, x*y%m and x*y/m must both fit in the registers.
                                                                                
However, I have a couple points to make still.
                                                                                
Firstly, the modulus will always fit inside EDX, regardless of the size of
the product. I'm not an assembler expert, but isn't it possible to turn off
the arithmetic exceptions prior to running DIV? As long as the code is only
interested in the modulus, this would be much faster.
                                                                                
At least in the case of finite mathematics (cryptography, coding theory,
etc) only the modulus really matters and computing it is often also the
critical section of the code.
                                                                                
Even if the code is interested in both the quotient and the modulus, it
seems that a quick comparison of the high 32bit part of EDX:EAX with the
modulus could determine whether or not a DIV would suffice. If it doesn't
then umoddi could be a fallback.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14224


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/14224] GCC generates pessimizes code for integer division
  2004-02-20 11:38 [Bug c/14224] New: GCC generates bad assembly " terpstra at ito dot tu-darmstadt dot de
  2004-02-20 16:23 ` [Bug target/14224] GCC generates pessimizes code " pinskia at gcc dot gnu dot org
@ 2004-04-05 13:31 ` uros at kss-loka dot si
  2004-04-05 14:58 ` terpstra at ito dot tu-darmstadt dot de
  2004-06-03  3:56 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 6+ messages in thread
From: uros at kss-loka dot si @ 2004-04-05 13:31 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From uros at kss-loka dot si  2004-04-05 13:31 -------
Problem here is, that maximum quotient should always be 2^32-1, as it should fit
in 32bit EAX register. Consider the case, when dividend is 0x0000 0001 0000 0000
and divisor is 0x0000 0001. The result won't fit in 32 bits, and division will
produce #DE exception.

For your case, divisor is 0xC000 0001. And with your assembly, if x*y is equal
or more than 0xC000 0001 0000 0000 (= 13835058059577131008), #DE exception will
be generated.

I suggest to mark this bug as invalid, because it is not possible for gcc to
know maximum value of (x*y).

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14224


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug target/14224] GCC generates pessimizes code for integer division
  2004-02-20 11:38 [Bug c/14224] New: GCC generates bad assembly " terpstra at ito dot tu-darmstadt dot de
@ 2004-02-20 16:23 ` pinskia at gcc dot gnu dot org
  2004-04-05 13:31 ` uros at kss-loka dot si
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-02-20 16:23 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-02-20 16:23 -------
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
             Status|UNCONFIRMED                 |NEW
          Component|c                           |target
     Ever Confirmed|                            |1
           Keywords|                            |pessimizes-code
      Known to fail|                            |3.5.0
   Last reconfirmed|0000-00-00 00:00:00         |2004-02-20 16:23:16
               date|                            |
            Summary|GCC generates bad assembly  |GCC generates pessimizes
                   |for integer division        |code for integer division


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14224


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-06-08  8:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-14224-4@http.gcc.gnu.org/bugzilla/>
2021-06-08  8:41 ` [Bug target/14224] GCC generates pessimizes code for integer division pinskia at gcc dot gnu.org
2021-06-08  8:59 ` jakub at gcc dot gnu.org
2004-02-20 11:38 [Bug c/14224] New: GCC generates bad assembly " terpstra at ito dot tu-darmstadt dot de
2004-02-20 16:23 ` [Bug target/14224] GCC generates pessimizes code " pinskia at gcc dot gnu dot org
2004-04-05 13:31 ` uros at kss-loka dot si
2004-04-05 14:58 ` terpstra at ito dot tu-darmstadt dot de
2004-06-03  3:56 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).