This patch marks the generated predicate functions as Pure, so that the back-end can optimize redundant calls to these functions when inlining and high level of optimization are requested.
This is a performance enhancement, no change in behavior. Tested on x86_64-pc-linux-gnu, committed on trunk 2015-10-16 Ed Schonberg <schonb...@adacore.com> * sem_ch13.adb (Build_Predicate_Functions): If expression for predicate is side-effect free, indicate that the predicate function is pure, to allow for optimization of redundant predicate checks.
Index: sem_ch13.adb =================================================================== --- sem_ch13.adb (revision 228874) +++ sem_ch13.adb (working copy) @@ -8702,6 +8702,16 @@ Insert_Before_And_Analyze (N, FDecl); Insert_After_And_Analyze (N, FBody); + + -- Static predicate functions are always side-effect free, and + -- in most cases dynamic predicate functions are as well. Mark + -- them as such whenever possible, so redundant predicate checks + -- can be optimized. + + if Expander_Active then + Set_Is_Pure (SId, Side_Effect_Free (Expr)); + Set_Is_Inlined (SId); + end if; end; -- Test for raise expressions present and if so build M version