Haskell GHC 9.4.4 compile error when -fllvm and -O2?

I believe this worked OK with GHC 9.2.5

$ ~/.ghcup/ghc/9.4.4/bin/ghc --make -fllvm -O2 test.hs
    Loaded package environment from /home/dunham/.ghc/x86_64-linux-9.4.4/environments/default
    [1 of 2] Compiling Main             ( test.hs, test.o )
    Cannot specify -O# and --passes=/--foo-pass, use -passes='default<O#>,other-pass'

<no location info>: error:
    `opt' failed in phase `LLVM Optimiser'. (Exit code: 1)

However

$ ~/.ghcup/ghc/9.4.4/bin/ghc --make -fllvm  test.hs
Loaded package environment from /home/dunham/.ghc/x86_64-linux-9.4.4/environments/default
[1 of 2] Compiling Main             ( test.hs, test.o )
[2 of 2] Linking test

and

/.ghcup/ghc/9.4.4/bin/ghc --make -O2 test.hs
Loaded package environment from /home/dunham/.ghc/x86_64-linux-9.4.4/environments/default
[1 of 2] Compiling Main             ( test.hs, test.o )
[2 of 2] Linking test
1 Like

I cannot reproduce this. What are the contents of test.hs? Which version of LLVM are you using? I’m using 12.0.1:

$ opt --version
LLVM (http://llvm.org/):
  LLVM version 12.0.1
  Optimized build.
  Default target: x86_64-unknown-linux-gnu
  Host CPU: znver3

It seems you are using LLVM 15 which is not supported by GHC-9.4.*.

1 Like

test.hs

import Data.Array.Base
import System.Environment
import Numeric

main = do 
        [arg] <- getArgs
        let n = (read arg) - 1 
        let init = listArray (0,n) (repeat 1.0)
        let (v:u:rest) = drop 19 $ iterate (eval_AtA_times_u n) init
        let vBv = sum [(u!i)*(v!i) |i<-[0..n]]
        let vv  = sum [(v!i)*(v!i) |i<-[0..n]]
        putStrLn $ showFFloat (Just 9) (sqrt (vBv/vv)) ""

eval_AtA_times_u n u = eval_At_times_u n v
    where v = eval_A_times_u n u

eval_A x y = 1.0/((i+j)*(i+j+1)/2+i+1)
    where i = fromIntegral x
          j = fromIntegral y

eval_A_times_u :: Int -> UArray Int Double -> UArray Int Double
eval_A_times_u n u = unsafeAccumArray (+) 0 (0,n) 
                     [(i,(eval_A i j) * u!j)|i<-[0..n], j<-[0..n]]
   
eval_At_times_u :: Int -> UArray Int Double -> UArray Int Double
eval_At_times_u n u = unsafeAccumArray (+) 0 (0,n) 
                      [(i,(eval_A j i) * u!j)|i<-[0..n], j<-[0..n]]
$ opt --version
Ubuntu LLVM version 15.0.2
  
  Optimized build.
  Default target: x86_64-pc-linux-gnu
  Host CPU: ivybridge

Ugh. Guess I’ll not use -fllvm

Yeah that seems to have been the problem.

$ llvm-config --version
13.0.1
$ ~/.ghcup/ghc/9.4.4/bin/ghc --make -fllvm -O2 test.hs
Loaded package environment from /home/dunham/.ghc/x86_64-linux-9.4.4/environments/default
[1 of 2] Compiling Main             ( test.hs, test.o )
[2 of 2] Linking test