Guard eigen_fill_helper on trivially copyable scalars

Summary

  • Gate eigen_fill_helper on std::is_trivially_copyable<Scalar> so that non-trivially-copyable scalar types (e.g. AutoDiffScalar) fall back to Eigen's own coefficient-wise assignment loop instead of std::fill_n
  • GCC's libstdc++ fill_n pessimizes non-trivially-copyable types by not hoisting the fill value out of the loop, generating extra move instructions per iteration
  • This is consistent with eigen_memset_helper which already gates on std::is_trivially_copyable
  • Trivial scalar types (double, float, int, std::complex<double>, etc.) are unaffected and continue to use the optimized std::fill_n path

Test plan

  • All autodiff, autodiff_scalar, nullary, basicstuff, and zerosized tests pass with GCC 13
  • Benchmarked setConstant on Matrix<AutoDiffScalar<Matrix<double,12,1>>, Dynamic, 1> — eliminates the regression vs pre-c01ff453 baseline

Closes #2956 (closed)

Merge request reports

Loading