Opened 3 years ago

Last modified 3 years ago

#13339 new bug

Arbitrarily large expressions built out of cheap primops are not floated out

Reported by: rwbarton Owned by:
Priority: normal Milestone:
Component: Compiler Version: 8.1
Keywords: Cc: carter.schonwald@…
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:


While investigating #13338 I was tripped up by the fact that GHC won't float out even a large expression like the product in

\i# -> magic# (x# *# 2# *# 2# *# 2# *# 2# *# 2# *# 2# *# 2# *# 2# -# i#)

The test involved here is exprIsCheap. The fact that *# is a cheap primop makes exprIsCheap think the whole expression is cheap; but clearly there must come some point where it would be better to float out the expression.

Perhaps exprIsCheap should work more like exprIsDupable, and take the size of the expression into account. See related comments on primOpIsCheap, though this ticket is about saving runtime work, not code size.

Change History (4)

comment:1 Changed 3 years ago by rwbarton


comment:2 Changed 3 years ago by rwbarton

Type of failure: None/UnknownRuntime performance bug

comment:3 Changed 3 years ago by carter

Cc: carter.schonwald@… added

comment:4 Changed 3 years ago by simonpj

Yes, taking the size into account would be good. Floating this this out requires boxing it, and doing an eval/unbox inside the loop. When is that cheaper than a dozen in-register additions? I'm not sure.

Note: See TracTickets for help on using tickets.