On Wed, Apr 29, 2015 at 11:50 AM, Eric Botcazou <ebotca...@adacore.com> wrote: > Historically the pragma Inline_Always of GNAT had been implemented in the FE > because the RTL inliner and then the Tree inliner weren't invoked at -O0 or > powerful enough to inline some constructs. But this approach had drawbacks, > especially wrt debug info. These restrictions were gradually lifted and now > the pragma is entirely piggybacked on the Tree inliner. > > This went mostly OK, except for a few cases where intrisinc operations that > used to be reasonably handled at -O0 now generate awful code, the typical > example being a modulus or division instrinsic by a power-of-2 generating a > fully-fledged modulus or division instruction instead of a simple shift. > > Therefore the attached patch implements anonymous constant propagation in the > inliner to fix the code quality regression. > > Tested on x86_64-suse-linux, OK for the mainline?
Hmm, special-casing this in the inliner looks odd to me. ISTR the inliner already propagates constant parameters to immediate uses, so I guess you run into the casting case you handle specially. But then if any constant propagation is ok at -O0 why not perform full-fledged constant propagation (with !DECL_IGNORED_P vars as a propagation barrier) as a regular SSA pass? That is, if you'd had a Inline_Always function like int foo (int i) { return (i + 1) / i; } you'd not get the desired result as the i + 1 stmt wouldn't be folded and thus the (i + 1) / i stmt wouldn't either. That said - why does RTL optimization not save you here anyway? After all, it is responsible for turning divisions into shifts. Soo - if you use the existing CCP pass and make surely_varying_stmt_p return true for defs of !DECL_IGNORED_P stmts at -O0 (strictly needed to make setting vars in gdb possible) and somehow arrange for ccp to run at -O0... It might help other obscure cases with inline-asms to behave consistently with -O0 vs. -On as well. Richard. > 2015-04-29 Eric Botcazou <ebotca...@adacore.com> > > * tree-inline.c (remap_gimple_op_r): Do anonymous constant > propagation. > (copy_bb): Fold conversions of constants immediately. > > > 2015-04-29 Eric Botcazou <ebotca...@adacore.com> > > * gnat.dg/inline12.adb: New test. > > > -- > Eric Botcazou