Kranc icon indicating copy to clipboard operation
Kranc copied to clipboard

Add constant propagation stage

Open eschnett opened this issue 13 years ago • 3 comments

When code is auto-generated (e.g. in EinsteinExact), then there are often shorthands with special values, e.g. 0 or 1. Kranc should realise this and simplify expressions accordingly. For example:

a -> 0, b -> x + a

should be simplified to only

b -> x

eschnett avatar Sep 06 '12 03:09 eschnett

We would have to carefully add logic to make sure that the resulting program is equivalent. Isn't this something that we can rely on the compiler to do?

ianhinder avatar Sep 06 '12 10:09 ianhinder

We can rely on the compiler in the same way as we can rely on its CSE and its vectorisation: in principle yes, but who knows.

It surely seems strange to define many variables with values such as 0, 1, or -1, and then multiply or add these later.

eschnett avatar Sep 06 '12 13:09 eschnett

Indeed it is strange to do that. It is EinsteinExact which is behaving strangely, so maybe this logic should be in there? Or maybe we decide it is common to automatically generate the input to Kranc, and it is useful for Kranc to perform this sort of optimisation analysis. In any case, I don't think this is a high priority.

ianhinder avatar Sep 06 '12 14:09 ianhinder