Ticket #5171 (new feature request)

Opened 2 years ago

Last modified 8 months ago

Misfeature of Cmm optimiser: no way to extract a branch of expression into a separate statement

Reported by: rtvd Owned by:
Priority: low Milestone: 7.6.2
Component: Compiler Version: 7.0.3
Keywords: Cmm optimisation Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description (last modified by igloo) (diff)

AFAIK, optimisations in Cmm are performed using cmmMachOpFold. However, this function is pure and does not allow detaching a branch of expression in order to make sure that it is executed only once.

Let's say we have (Op1 arg1 arg2) and we want to transform it to (Op2 arg1 (Op3 arg2 arg1)). Doing this would mean that arg1 would be computed more than once. Instead, the following should be possible:

arg1_reg <- arg1
(Op2 arg1_reg (Op3 arg2 arg1_reg))

The lack of this feature already stops one of optimisations from happening in most cases. See:

       CmmReg _ <- x -> -- We duplicate x below, hence require
        -- it is a reg.  FIXME: remove this restriction.

in CmmOpt?.hs.

There is a number of other useful optimisations which can be implemented only with this feature available.

Change History

Changed 22 months ago by igloo

  • description modified (diff)

Changed 22 months ago by igloo

  • milestone set to 7.4.1

Changed 15 months ago by igloo

  • priority changed from normal to low
  • milestone changed from 7.4.1 to 7.6.1

Changed 8 months ago by igloo

  • milestone changed from 7.6.1 to 7.6.2
Note: See TracTickets for help on using tickets.