When does GHC produce unlifted `let` bindings?

Simon Peyton Jones simonpj at microsoft.com
Thu Nov 2 08:43:15 UTC 2017

Re: let-bindings floating more easily, would a check for `exprIsOkForSpeculation scrut` in theory suffice to float out cases?

Yes; but instead we simply turn such cases into lets.


From: Sebastian Graf [mailto:sgraf1337 at gmail.com]
Sent: 02 November 2017 08:33
To: Simon Peyton Jones <simonpj at microsoft.com>
Cc: ghc-devs <ghc-devs at haskell.org>
Subject: Re: When does GHC produce unlifted `let` bindings?

Thanks both of you, that makes sense.

Re: let-bindings floating more easily, would a check for `exprIsOkForSpeculation scrut` in theory suffice to float out cases?

On Mon, Oct 30, 2017 at 10:56 AM, Simon Peyton Jones <simonpj at microsoft.com<mailto:simonpj at microsoft.com>> wrote:
See Note [CoreSyn let/app invariant] in CoreSyn.

Briefly, you can write
            let x::Int# = e in …
if e is “ok-for-speculation”.  See extensive comments in CoreUtils on what that means.

You could also use case, but let-bindings “float” more easily than cases, because they are not worried about preserving exception behaviour.


From: ghc-devs [mailto:ghc-devs-bounces at haskell.org<mailto:ghc-devs-bounces at haskell.org>] On Behalf Of Sebastian Graf
Sent: 29 October 2017 21:07
To: ghc-devs <ghc-devs at haskell.org<mailto:ghc-devs at haskell.org>>
Subject: When does GHC produce unlifted `let` bindings?

Hi folks,

I was debugging a Core-to-Core transform for TEST=spec-inline<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fghc%2Fghc%2Fblob%2Ffe04f3783b662c52c4a0ff36b2d62a7a575998a5%2Ftestsuite%2Ftests%2FsimplCore%2Fshould_compile%2Fspec-inline.hs&data=02%7C01%7Csimonpj%40microsoft.com%7C77699e26801a4d458b9a08d51f11085f%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636449080385955811&sdata=t%2BAXQszqKfFRYNjjLJtMHpLsS2RzwTaBFA42JuLBN4o%3D&reserved=0> and was wondering (yet again) why GHC produces unlifted `let` bindings in Core like it seems supposed to be doing<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fghc%2Fghc%2Fblob%2Ffe04f3783b662c52c4a0ff36b2d62a7a575998a5%2Ftestsuite%2Ftests%2FsimplCore%2Fshould_compile%2Fspec-inline.stderr%23L68-L76&data=02%7C01%7Csimonpj%40microsoft.com%7C77699e26801a4d458b9a08d51f11085f%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636449080385955811&sdata=pVNrzDY%2ByfK%2FVl%2Fk8B5P0HuGC6PG5kD7mHiwa0Vck9o%3D&reserved=0>.

  *   Why doesn't this use `case` instead?
  *   Is there a semantic difference?
  *   Can `case` be used with unlifted types?
  *   And if not, why can `let`?
Unlifted `let` seems much close to `case` than to `let`. Some GHC passes seem to agree.<https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fghc%2Fghc%2Fsearch%3Fl%3DHaskell%26q%3D%2522strict%2Blet%2522%26type%3D%26utf8%3D%25E2%259C%2593&data=02%7C01%7Csimonpj%40microsoft.com%7C77699e26801a4d458b9a08d51f11085f%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636449080385955811&sdata=ksdZGbGyw6%2FLEIMiJpCaHlDh4iipdkKcSCEDdTySExk%3D&reserved=0>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20171102/67dfa8d7/attachment.html>

More information about the ghc-devs mailing list