Problems with tbaa in llvm 4.0

Hi all,

I do a little work on the GHC haskell compiler. One of the things I
do is compile current GHC git HEAD against the next release of LLVM
to find issues and adapt the GHC code as early as possible.

A recent modification to LLVM is now rejecting GHC generated LLVM
IR that was previously accepted. I discussed this on IRC with
sanjoyd who explained what had changed and gave me some hints about
trying to fix it. Basically the issue (as I understood it) was that
no statements should reference the root tbaa node directly.

With that in mind, I came up with a fix to GHC llvm codegen so the
the tbaa metadata is now:

    !0 = !{!"root", null}
    !1 = !{!"top", !0}
    !2 = !{!"stack", !1}
    !3 = !{!"heap", !1}
    !4 = !{!"rx", !3}
    !5 = !{!"base", !1}

However, with this fix I get basically the same set of error messages
A couple of the errors are:

    Access type node must be a valid scalar type
      %ln59 = load i64, i64* %ln58, !tbaa !6
    !6 = !{!2, !2, i64 0}
    !2 = !{!"top", !3}

    Access type node must be a valid scalar type
      %ln5d = load i64, i64* %ln5c, !tbaa !4
    !4 = !{!5, !5, i64 0}
    !5 = !{!"base", !2}

    Access type node must be a valid scalar type
      %ln5i = load i64, i64* %ln5h, !tbaa !0
    !0 = !{!1, !1, i64 0}
    !1 = !{!"stack", !2}

I would appreciate any clues that might help me solve this.

Cheers,
Erik

[+Sanjoy]

Hi Erik,

(I've already replied on IRC, but echoing that here for others)

Hal Finkel wrote:

[+Sanjoy]

Hi all,

I do a little work on the GHC haskell compiler. One of the things I
do is compile current GHC git HEAD against the next release of LLVM
to find issues and adapt the GHC code as early as possible.

A recent modification to LLVM is now rejecting GHC generated LLVM
IR that was previously accepted. I discussed this on IRC with
sanjoyd who explained what had changed and gave me some hints about
trying to fix it. Basically the issue (as I understood it) was that
no statements should reference the root tbaa node directly.

With that in mind, I came up with a fix to GHC llvm codegen so the
the tbaa metadata is now:

!0 = !{!"root", null}

You need to change !0 to !{!"root"}. Root nodes must have a single operand.

-- Sanjoy

Sanjoy Das wrote:

Hi Erik,

(I've already replied on IRC, but echoing that here for others)

>> !0 = !{!"root", null}

You need to change !0 to !{!"root"}. Root nodes must have a single operand.

Thanks for your help Sanjoy, I really appreciate it.

I've tweaked GHC llvm codegen so that it generates acceptable IR code and GHC
now builds and passes all the tests.

For anyone interested, my Makefile which builds latest LLVM and builds
GHC against that is at:

    https://github.com/erikd/ghc-llvm-next

Cheers,
Erik