Re: [eigen] Inlining (or lack thereof) on msvc 2013

[ Thread Index | Date Index | More Archives ]


sorry for late reply.. Yes, MSVC is not very good at inlining. I did not known that it was affected by the user code length, though. Good to know.

I know that other major compilers (GCC,ICC,clang) allows to tweak the inlining thresholds to workaround such issues, however, MSVC does not seem to offer such a flexibility. So the only solution seems to add more EIGEN_STRONG_INLINE in Eigen's code as we currently do on a case by cas basis....


On Tue, Mar 15, 2016 at 4:38 PM, Simon Rutishauser <simon.rutishauser@xxxxxxxxx> wrote:

we are observing some inlining issues with MSVC from Visual Studio 2013 (Update 5).
On many occasions the compiler does not inline any of the Eigen function calls.

This seems to be somehow related to the size of the function that is using Eigen.

I have attached an example (eigen_inline.cpp) where the compiler does not inline
any of the Eigen operations (see eigen_inline.asm, search for ENDP ; compute):
        call    ?functor@?$CwiseUnaryOp@U?$scalar_multiple_op@N@internal@Eigen@@$$CBV?$Block@$$CBV?$Matrix@N$02$00$0A@$02$00@Eigen@@$01$00$0A@@3@@Eigen@@QEBAAEBU?$scalar_multiple_op@N@internal@2@XZ ; Eigen::CwiseUnaryOp<Eigen::internal::scalar_multiple_op<double>,Eigen::Block<Eigen::Matrix<double,3,1,0,3,1> const ,2,1,0> const >::functor
That of course results in a considerable performance hit.

However if we remove one single line of source code from the sample function,
or alternatively replace "inline" with "EIGEN_STRONG_INLINE" in all of Eigen,
then all calls are properly inlined (see eigen_strong_inline.asm):
        movsdx  QWORD PTR tmp2$[rsp], xmm6
        movsdx  xmm1, QWORD PTR [r9+24]
        movsdx  xmm0, QWORD PTR [r9+32]
        mulsd   xmm1, xmm4
        mulsd   xmm0, xmm3
        subsd   xmm0, xmm1

All code was compiled with:
  cl.exe -c /O2 /FA /DNDEBUG -I..\Eigen eigen_inline.cpp

Do you have any insights into this kind of behavior? A less invasive solution that does not include
patching all of Eigen would be preferable...


Mail converted by MHonArc 2.6.19+