Constant folding for repeated integer operation of unknown value
While looking at 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.
Trac metadata
Trac field | Value |
---|---|
Version | 8.0.1 |
Type | FeatureRequest |
TypeOfFailure | OtherFailure |
Priority | low |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |