The old Bell Labs non portable C Compiler (early Unix compiler) had a
very good heuristic method for finding foldable constants (It is
described in Ctour document from 70s - someone posted url to it here a
while ago but I did not save it). Idea is to sort expressions by
operand complexity for communative and associative operators. Int
constant is less complex than real, etc. Then apply constant folding
after sorting. Then re-sort and re-fold until no progress or for a
few times. The sorting was most complex (on left) to least complex
order which has the added advantage that simple register assignment
algorithms do quite well on expressions with left operands more
complex.