Optimized Cmm containing useless blocks

While looking at some generated Cmm I saw things like this c1Cm: goto c1Cq; c1Cq: i.e. useless basic blocks that haven't been optimized away. Is this to be expected? -- Johan

On a related note, doesn't Cmm support fall-through branches? Heap checks
use two branches instead of one branch and one fall-through case:
c1Cq:
Hp = Hp + 152;
if (Hp > I64[BaseReg + 856]) goto c1Cs; else goto c1Cr;
c1Cs:
I64[BaseReg + 904] = 152;
goto c1Cp;
c1Cp:
R1 = PicBaseReg + a_r1za_closure;
call (I64[BaseReg - 8])(R1) args: 8, res: 0, upd: 8;
c1Cr:
On Sat, Mar 8, 2014 at 9:21 AM, Johan Tibell
While looking at some generated Cmm I saw things like this
c1Cm: goto c1Cq; c1Cq:
i.e. useless basic blocks that haven't been optimized away. Is this to be expected?
-- Johan

Seems like something that should be delegated to a peep hole optimizer.
What you describe make it possible to reorder the basic blocks at a later
stage.
Alexander
On Mar 8, 2014 9:24 AM, "Johan Tibell"
On a related note, doesn't Cmm support fall-through branches? Heap checks use two branches instead of one branch and one fall-through case:
c1Cq: Hp = Hp + 152; if (Hp > I64[BaseReg + 856]) goto c1Cs; else goto c1Cr; c1Cs: I64[BaseReg + 904] = 152; goto c1Cp; c1Cp: R1 = PicBaseReg + a_r1za_closure; call (I64[BaseReg - 8])(R1) args: 8, res: 0, upd: 8; c1Cr:
On Sat, Mar 8, 2014 at 9:21 AM, Johan Tibell
wrote: While looking at some generated Cmm I saw things like this
c1Cm: goto c1Cq; c1Cq:
i.e. useless basic blocks that haven't been optimized away. Is this to be expected?
-- Johan
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs

useless basic blocks that haven't been optimized away. Is this to be expected? I believe this should not happen but it's hard to say without looking at a complete dump. Could you post full Cmm dump + a minimial working example that generates that?
On a related note, doesn't Cmm support fall-through branches? Cmm program is represented as a graph with each node (a block of code) having explicit list of successors. Having fall-throughs in Cmm would require storing blocks linearily with a guarantee that their order will not change. Note that fall-throughs are present in the generated assembly.
Janek

On Sun, Mar 9, 2014 at 10:22 PM, Jan Stolarek
useless basic blocks that haven't been optimized away. Is this to be expected? I believe this should not happen but it's hard to say without looking at a complete dump. Could you post full Cmm dump + a minimial working example that generates that?
On a related note, doesn't Cmm support fall-through branches? Cmm program is represented as a graph with each node (a block of code) having explicit list of successors. Having fall-throughs in Cmm would require storing blocks linearily with a guarantee that their order will not change. Note that fall-throughs are present in the generated assembly.
This was me being stupid. GHC happily prints optimized Cmm even if no optimization was done due to a missing flag (cause GHC defaults to -O0).

If I may add to this, then I'm curious why there is something like: I64[BaseReg + 784] = I64[BaseReg + 784]; presented in Cmm optimized code. Since I don't know Cmm enough I've verified if the semantics is really C like by looking into generated asm and indeed it looks so. This costs 5 isns of sparc asm btw. If someone is interested to duplicate this, then use sparc or ppc 32 bit registerised target and Haskell code: module Main where import Data.Int main = print ( ( 2 ^ 6 ) :: Int64 ) Karel On 03/ 8/14 09:21 AM, Johan Tibell wrote:
While looking at some generated Cmm I saw things like this
c1Cm: goto c1Cq; c1Cq:
i.e. useless basic blocks that haven't been optimized away. Is this to be expected?
-- Johan
_______________________________________________ ghc-devs mailing list ghc-devs@haskell.org http://www.haskell.org/mailman/listinfo/ghc-devs

That doesn't look right. Are you using -O? If so, perhaps open a ticket explaining how to reproduce, and including the results of -ddump-cmm. (Don't use module Main, because it's irrelevant to this question, and generate a certain amount of auxiliary goop.) Thanks SImon | -----Original Message----- | From: ghc-devs [mailto:ghc-devs-bounces@haskell.org] On Behalf Of Karel | Gardas | Sent: 09 March 2014 21:40 | To: Johan Tibell | Cc: ghc-devs@haskell.org | Subject: Re: Optimized Cmm containing useless blocks | | | If I may add to this, then I'm curious why there is something like: | | I64[BaseReg + 784] = I64[BaseReg + 784]; | | presented in Cmm optimized code. Since I don't know Cmm enough I've | verified if the semantics is really C like by looking into generated asm | and indeed it looks so. This costs 5 isns of sparc asm btw. | | If someone is interested to duplicate this, then use sparc or ppc 32 bit | registerised target and Haskell code: | | module Main where | | import Data.Int | | main = print ( ( 2 ^ 6 ) :: Int64 ) | | Karel | | On 03/ 8/14 09:21 AM, Johan Tibell wrote: | > While looking at some generated Cmm I saw things like this | > | > c1Cm: | > goto c1Cq; | > c1Cq: | > | > i.e. useless basic blocks that haven't been optimized away. Is this to | > be expected? | > | > -- Johan | > | > | > | > _______________________________________________ | > ghc-devs mailing list | > ghc-devs@haskell.org | > http://www.haskell.org/mailman/listinfo/ghc-devs | | _______________________________________________ | ghc-devs mailing list | ghc-devs@haskell.org | http://www.haskell.org/mailman/listinfo/ghc-devs

This was my mess-up (see previous email). Sorry for the noise.
On Mon, Mar 10, 2014 at 9:30 AM, Simon Peyton Jones
That doesn't look right. Are you using -O?
If so, perhaps open a ticket explaining how to reproduce, and including the results of -ddump-cmm.
(Don't use module Main, because it's irrelevant to this question, and generate a certain amount of auxiliary goop.)
Thanks
SImon
| -----Original Message----- | From: ghc-devs [mailto:ghc-devs-bounces@haskell.org] On Behalf Of Karel | Gardas | Sent: 09 March 2014 21:40 | To: Johan Tibell | Cc: ghc-devs@haskell.org | Subject: Re: Optimized Cmm containing useless blocks | | | If I may add to this, then I'm curious why there is something like: | | I64[BaseReg + 784] = I64[BaseReg + 784]; | | presented in Cmm optimized code. Since I don't know Cmm enough I've | verified if the semantics is really C like by looking into generated asm | and indeed it looks so. This costs 5 isns of sparc asm btw. | | If someone is interested to duplicate this, then use sparc or ppc 32 bit | registerised target and Haskell code: | | module Main where | | import Data.Int | | main = print ( ( 2 ^ 6 ) :: Int64 ) | | Karel | | On 03/ 8/14 09:21 AM, Johan Tibell wrote: | > While looking at some generated Cmm I saw things like this | > | > c1Cm: | > goto c1Cq; | > c1Cq: | > | > i.e. useless basic blocks that haven't been optimized away. Is this to | > be expected? | > | > -- Johan | > | > | > | > _______________________________________________ | > ghc-devs mailing list | > ghc-devs@haskell.org | > http://www.haskell.org/mailman/listinfo/ghc-devs | | _______________________________________________ | ghc-devs mailing list | ghc-devs@haskell.org | http://www.haskell.org/mailman/listinfo/ghc-devs
participants (5)
-
Alexander Kjeldaas
-
Jan Stolarek
-
Johan Tibell
-
Karel Gardas
-
Simon Peyton Jones