Constant folding flags are misleading
Two problems
-
The flag -fcore-constant-folding
claims to enable/disable constant folding. But it doesn't. The only use is here inGHC.Core.Opt.Pipeline.getCoreToDo
:const_fold = gopt Opt_CoreConstantFolding dflags ... do_simpl3 = const_fold || rules_on -- TODO: any other optimizations benefit from three-phase simplification
That
do_simpl3
switches on the big 3-stage application of the optimiser.There is no selective enable/disable for constant folding rewrites, independent of other simplifications.
-
The flag -fnum-constant-folding
is entirely un-documented. We have this commit:commit 60e4bb4d305bc1a65457ee79b1e69c11b9ed747d Author: Sylvain Henry <hsyl20@gmail.com> Date: Fri Apr 13 13:29:07 2018 -0400 Enhanced constant folding This patch uses laws of +/-/* (associativity, commutativity, distributivity) to support some constant folding into nested expressions.
But the user manual is silent; and the code is silent too. No
Note [Enhanced constant folding]
to explain what the "enhanced" rules do, or how. Alas.
Edited by Sylvain Henry