Opened 6 years ago

Last modified 3 years ago

#8871 new bug

No-op assignment I64[BaseReg + 784] = I64[BaseReg + 784]; is generated into optimized Cmm

Reported by: kgardas Owned by:
Priority: normal Milestone:
Component: Compiler (CodeGen) Version: 7.9
Keywords: CodeGen Cc: jstolarek, simonmar
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


Hello, on SPARC and I also guess on PPC it's possible to get following line in optimized Cmm code:

I64[BaseReg + 784] = I64[BaseReg + 784];

this line is then translated by NCG wasting 5 isns on SPARC at least. Don't know PPC. I'm not sure if this is possible to duplicate this on i386 due to fewer regs. Generally speaking you need to have 32bit target with more regs available. Interesting fact is that such line is not presented in non-optimized Cmm, but is presented in optimized one. Both optimized and non-optimized Cmms attached. Both get from compiling T7507 testcase by stage1 compiler on SPARC:

/home/karel/vcs/ghc-src/ghc-sparc-reg_ncg/inplace/bin/ghc-stage1 -fforce-recomp -dcore-lint -dcmm-lint -dno-debug-output -no-user-package-db -rtsopts -fno-ghci-history -c T7507.hs  -O -ddump-opt-cmm > T7507.opt-cmm-sparc-reg-ncg

Of course non-opt Cmm is got by -ddump-cmm instead of -ddump-opt-cmm. If you need more simplified testcase, then following code is usable too:

module Main where

import Data.Int

main = print ( ( 2 ^ 6 ) :: Int64 )

Attachments (2)

T7507.opt-cmm-sparc-reg-ncg (44.2 KB) - added by kgardas 6 years ago.
T7507.cmm-sparc-reg-ncg.xz (14.5 KB) - added by kgardas 6 years ago.

Download all attachments as: .zip

Change History (9)

comment:1 Changed 6 years ago by simonpj

Are you using -O? Can you give your command line and output of -ddump-cmm?

Changed 6 years ago by kgardas

Attachment: T7507.opt-cmm-sparc-reg-ncg added

Changed 6 years ago by kgardas

Attachment: T7507.cmm-sparc-reg-ncg.xz added

comment:2 in reply to:  1 Changed 6 years ago by kgardas

Replying to simonpj:

Are you using -O? Can you give your command line and output of -ddump-cmm?

Yes, see the command-line and also see attached files. BTW, I'm able to also reproduce this on PPC 32bit as I wrote. This is by using my simplified example above:

$ grep "I64" T7507d_64-O-ppc.opt-cmm|grep Base
          I64[BaseReg + 784] = _s317::I64;
          I64[BaseReg + 784] = _s31d::I64;
          I64[BaseReg + 784] = 1 :: W64;
          I64[BaseReg + 784] = I64[BaseReg + 784];
          I64[Hp - 4] = I64[BaseReg + 784];
          I64[Sp - 8] = I64[BaseReg + 784];

you see the line in the middle of grep...

comment:3 Changed 6 years ago by kgardas

Also for your reference this is slightly out-dated HEAD (master branch) where the last patch is:

commit 018676c7f883886b388652c913c99a10d2591b0b
Author: Herbert Valerio Riedel <>
Date:   Sun Feb 23 22:00:57 2014 +0100

    Use U+2018 instead of U+201B quote mark in compiler messages
    This matches GCC's choice of Unicode quotation marks (i.e. U+2018 and U+2019)
    and therefore looks more familiar on the console. This addresses #2507.
    Signed-off-by: Herbert Valerio Riedel <>

comment:4 Changed 6 years ago by simonpj

Cc: jstolarek simonmar added

comment:5 Changed 6 years ago by simonmar

Yes, this is just a missing optimisation. I didn't implement it because I hadn't seen any code that needed it, until now.

comment:6 Changed 5 years ago by thomie

Component: CompilerCompiler (CodeGen)
Type of failure: OtherRuntime performance bug

comment:7 Changed 3 years ago by simonpj

Keywords: CodeGen added
Note: See TracTickets for help on using tickets.