Re: [GHC] #1603: a miscompilation of (`rem` 0x40000000)::Int with -O -fvia-C

2008-07-29 Thread GHC
#1603: a miscompilation of (`rem` 0x4000)::Int with -O -fvia-C
--+-
 Reporter:  Isaac Dupree  |  Owner: 
 Type:  bug   | Status:  closed 
 Priority:  normal|  Milestone:  6.10 branch
Component:  None  |Version:  6.8.1  
 Severity:  normal| Resolution:  fixed  
 Keywords:| Difficulty:  Unknown
 Testcase:  numeric/1603  |   Architecture:  Multiple   
   Os:  Multiple  |  
--+-
Changes (by simonmar):

  * status:  new => closed
  * resolution:  => fixed

Comment:

 on second thoughts, having the bug open doesn't really achieve anything.

-- 
Ticket URL: 
GHC 
The Glasgow Haskell Compiler___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: [GHC] #1603: a miscompilation of (`rem` 0x40000000)::Int with -O -fvia-C

2008-07-29 Thread GHC
#1603: a miscompilation of (`rem` 0x4000)::Int with -O -fvia-C
--+-
 Reporter:  Isaac Dupree  |  Owner: 
 Type:  bug   | Status:  new
 Priority:  normal|  Milestone:  6.10 branch
Component:  None  |Version:  6.8.1  
 Severity:  normal| Resolution: 
 Keywords:| Difficulty:  Unknown
 Testcase:  numeric/1603  |   Architecture:  Multiple   
   Os:  Multiple  |  
--+-
Changes (by simonmar):

  * milestone:  6.10.1 => 6.10 branch

Comment:

 FYI, gcc 4.2.3 and later has the fix.  Only one of my machines has this
 (Fedora 9), so I don't think we can close the bug just yet.

-- 
Ticket URL: 
GHC 
The Glasgow Haskell Compiler___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: [GHC] #1603: a miscompilation of (`rem` 0x40000000)::Int with -O -fvia-C

2008-07-09 Thread GHC
#1603: a miscompilation of (`rem` 0x4000)::Int with -O -fvia-C
--+-
 Reporter:  Isaac Dupree  |  Owner:  
 Type:  bug   | Status:  new 
 Priority:  normal|  Milestone:  6.10.1  
Component:  None  |Version:  6.8.1   
 Severity:  normal| Resolution:  
 Keywords:| Difficulty:  Unknown 
 Testcase:  numeric/1603  |   Architecture:  Multiple
   Os:  Multiple  |  
--+-
Changes (by igloo):

  * milestone:  Not GHC => 6.10.1

Comment:

 gcc looks fixed now:
 {{{
 $ cat q.c

 #include 

 int f(unsigned int x)
 {
 printf("%x %d\n", x, (int)x);
 return ((int)x) % 4;
 }

 int main(int argc, char *argv[])
 {
 printf("%d\n", f((unsigned int)(-1)));
 return 0;
 }
 $ gcc-4.1 q.c -Wall -o q && ./q
  -1
 3
 $ gcc-4.2 q.c -Wall -o q && ./q
  -1
 -1
 $ gcc-4.2 --version
 gcc-4.2 (GCC) 4.2.4 20080512 (prerelease) (Debian 4.2.3-6)
 Copyright (C) 2007 Free Software Foundation, Inc.
 This is free software; see the source for copying conditions.  There is NO
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
 PURPOSE.
 }}}
 We should confirm the test passes with ghc and stop skipping it.

-- 
Ticket URL: 
GHC 
The Glasgow Haskell Compiler___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: [GHC] #1603: a miscompilation of (`rem` 0x40000000)::Int with -O -fvia-C

2007-11-08 Thread GHC
#1603: a miscompilation of (`rem` 0x4000)::Int with -O -fvia-C
--+-
 Reporter:  Isaac Dupree  |  Owner:
 Type:  bug   | Status:  new   
 Priority:  normal|  Milestone:  6.8 branch
Component:  Compiler  |Version:  6.8.1 
 Severity:  normal| Resolution:
 Keywords:| Difficulty:  Unknown   
 Testcase:  numeric/1603  |   Architecture:  Multiple  
   Os:  Multiple  |  
--+-
Changes (by simonmar):

  * testcase:  => numeric/1603
  * version:  6.6.1 => 6.8.1
  * os:  Linux => Multiple
  * architecture:  x86 => Multiple
  * milestone:  6.8.2 => 6.8 branch

Comment:

 gcc is being too clever.  It is assuming that because the first argument
 to % is the result of converting an unsigned to a signed integer, that its
 value is therefore non-negative, and uses this knowledge to optimise the
 code it generates for 'x % 0x4000'.  I believe gcc is entitled to make
 this optimisation, because arithmetic in C is only defined within the
 bounds of the types, and that includes type conversions.  Unfortunately
 the `-fwrapv` option doesn't apply to type conversions, apparently.

 I don't see an easy fix (but suggestions are welcome).  We use unsigned
 types everywhere in our back end, only converting to signed types in order
 to perform signed operations.  This strategy apparently relies on
 undefined C behaviour.

 I've added a test (will be pushed shortly).

-- 
Ticket URL: 
GHC 
The Glasgow Haskell Compiler___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


Re: [GHC] #1603: a miscompilation of (`rem` 0x40000000)::Int with -O -fvia-C

2007-11-05 Thread GHC
#1603: a miscompilation of (`rem` 0x4000)::Int with -O -fvia-C
--+-
 Reporter:  Isaac Dupree  |  Owner: 
 Type:  bug   | Status:  new
 Priority:  normal|  Milestone:  6.8.2  
Component:  Compiler  |Version:  6.6.1  
 Severity:  normal| Resolution: 
 Keywords:| Difficulty:  Unknown
 Testcase:|   Architecture:  x86
   Os:  Linux |  
--+-
Changes (by igloo):

  * milestone:  => 6.8.2

Comment:

 Thanks for the report.
 Confirmed on amd64/Linux with GHC 6.8.1.

-- 
Ticket URL: 
GHC 
The Glasgow Haskell Compiler___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs


[GHC] #1603: a miscompilation of (`rem` 0x40000000)::Int with -O -fvia-C

2007-08-08 Thread GHC
#1603: a miscompilation of (`rem` 0x4000)::Int with -O -fvia-C
---+
  Reporter:  Isaac Dupree  |  Owner:   
  Type:  bug   | Status:  new  
  Priority:  normal|  Milestone:   
 Component:  Compiler  |Version:  6.6.1
  Severity:  normal|   Keywords:   
Difficulty:  Unknown   | Os:  Linux
  Testcase:|   Architecture:  x86  
---+
eival has the wrong value in this fairly minimal testcase:

 {{{
 module Eival(eival) where
 eival :: [Int]
 eival = syn
 [-727299164,-506030719,-906763000,-1356112363,-1183678614,-970206674,-56]

 syn :: [Int] -> [Int]
 syn (d:ds) = case rem d 0x4000 of
   synD -> ((:) {-$!-} synD) {-$!-} (syn ds) --strictness/($!)s entirely
 optional
 syn [] = []
 }}}

 expected (and gotten with -O0 or -fasm (or hugs :)):
 [-727299164,-506030719,-906763000,-282370539,-109936790,-970206674,-56]
 buggy value:
 [346442660,567711105,166978824,791371285,963805034,103535150,1073741768]

 If the denominator is 0x4001 or 0x3fff, the bug does not occur.

 Verified in 6.6.1 and 6.7 on x86-32 Linux.

 Only is buggy with both -O and -fvia-C. Adding -optc-O0 or -optc-O3
 doesn't change the results.

 {{{
 ]gcc --version
 gcc (GCC) 4.1.2
 }}}

-- 
Ticket URL: 
GHC 
The Glasgow Haskell Compiler___
Glasgow-haskell-bugs mailing list
Glasgow-haskell-bugs@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs