Opened 3 years ago

#13334 new feature request

Constant folding for repeated integer operation of unknown value

Reported by: bgamari Owned by:
Priority: low Milestone:
Component: Compiler Version: 8.0.1
Keywords: Cc:
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 looking at Phab:D3197 I noticed that currently there is nothing to turn an expression of the form n+n+...+n into n*m. It seems like some rules like,

forall x. x +# x = 2*x
forall n x. n*x + x = (n+1) * x
forall n x. x + n*x = (n+1) * x

Might fix this. Of course, it's quite possible that a string of additions is sometimes faster than a multiplication, but it seems to me that we should (for integer types) perform the rewrite to multiplication and then teach the code generator to lower to addition if it deems it advantageous.

Naturally, this also applies to other integer operators as well. Regardless, I doubt that this is hurting anyone too badly.

Change History (0)

Note: See TracTickets for help on using tickets.