Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,866
    • Issues 4,866
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 461
    • Merge requests 461
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #14754
Closed
Open
Created Feb 03, 2018 by Bodigrim@BodigrimDeveloper

-O1 changes result at runtime

I found a program, which works as expected in GHC 8.4.1-alpha1 with -O0, but freezes with -O1.

module Main where

import Debug.Trace

main :: IO ()
main = print (alg 3 1)

alg :: Word -> Word -> Word
alg a b
  | traceShow (a, b) False = undefined
  | c < b = alg b c
  | c > b = alg c b
  | otherwise = c
  where
    c = a - b
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.4.0.20180118
$ ghc -O0 alg.hs
[1 of 1] Compiling Main             ( alg.hs, alg.o )
Linking alg ...
$ ./alg
(3,1)
(2,1)
1
$ ghc -O1 alg.hs
[1 of 1] Compiling Main             ( alg.hs, alg.o ) [Optimisation flags changed]
Linking alg ...
$ ./alg 2>&1 | head
(3,1)
(1,2)
(2,18446744073709551615)
(18446744073709551615,3)
^C

For some reason an optimised program chooses a wrong case at the very first invocation of alg.

Edited Mar 10, 2019 by Ben Gamari
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking