New user self-registration is disabled due to spam. Please email eigen-core-team @ lists.tuxfamily.org if you need an account.
Before reporting a bug, please make sure that your Eigen version is up-to-date!
Bug 617 - g++ -O3 too much optimization under g++ 4.7.2/MinGW?
Summary: g++ -O3 too much optimization under g++ 4.7.2/MinGW?
Status: RESOLVED DUPLICATE of bug 556
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - matrix products (show other bugs)
Version: 3.1
Hardware: x86 - 32-bit Other UNIX-like
: Normal Unknown
Assignee: Nobody
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-19 12:12 UTC by bear.from.peru
Modified: 2013-06-21 22:12 UTC (History)
1 user (show)



Attachments

Description bear.from.peru 2013-06-19 12:12:46 UTC
Thankyou for Eigen - it makes matrix manipulations so much easier!

Compiling the following code:

#include "Eigen/Core"
#include "Eigen/Dense"
#include <iostream>
#include <stdexcept>

namespace
{
  Eigen::MatrixXd SelfAdjointInverse(const Eigen::MatrixXd& original)
  {
    Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> es(original);
    if ( Eigen::Success != es.info() )
      {
        throw std::runtime_error("Eigenvalue decomposition failed");
      }
    else if ( 1e-6 > es.eigenvalues()[0] ) // arbitrary precision check, eigenvalues are in increasing order
      {
        throw std::runtime_error("Eigenvalue decomposition suspect");
      }
    return es.eigenvectors() * es.eigenvalues().cwiseInverse().asDiagonal() * es.eigenvectors().transpose();
  }
}
int main(int argc, char** argv)
{
  Eigen::MatrixXd original(2,2);
  original << 1.0048237789108891, 0.0010578737852708596, 0.0010578737852708605, 1.0330767846918523;
  Eigen::MatrixXd result = SelfAdjointInverse(original);
  std::cout << result;
}

With g++ -O3 eigen_crash.cpp -o eigen_crash on my MinGw installation and executing it results in a "stopped working" window.

Configuration details:

MINGW32_NT-6.0 hostname 1.0.18(0.48/3/2) 2012-11-21 22:34 i686 Msys

Eigen 3.1.3 from http://eigen.tuxfamily.org from https://bitbucket.org/eigen/eigen/get/3.1.3.tar.gz

$ g++ -v
Using built-in specs.
COLLECT_GCC=C:\MinGW\bin\g++.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.7.2/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.7.2/configure --enable-languages=c,c++,ada,fortran,objc,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry --enable-libstdcxx-debug --disable-build-poststage1-with-cxx --enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.7.2 (GCC)

The code only fails with -O3 on that particular configuration. -O2 and -g both work happily. 

Work-around - replace the return statement with the following and there seems to be no problem:
    Eigen::MatrixXd temp = es.eigenvectors() * es.eigenvalues().cwiseInverse().asDiagonal();
    return temp * es.eigenvectors().transpose();

I have tried the other (earlier) versions of gcc available to me, and on all of these the original code works perfectly happily with -O3:

keith@kmp-vb-ubuntu32:/mnt/m/aardwork/trunk/thirdparty/eigen$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.6/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --enable-targets=all --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)

 g++ -v
Using built-in specs.
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.3 --enable-ssp --disable-libssp --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap --with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --program-suffix=-4.3 --enable-linux-futex --without-system-libunwind --with-cpu=generic --build=x86_64-suse-linux
Thread model: posix
gcc version 4.3.2 [gcc-4_3-branch revision 141291] (SUSE Linux)

 g++ -v
Using built-in specs.
Target: i586-suse-linux
Configured with: ../configure --enable-threads=posix --prefix=/usr --with-local-prefix=/usr/local --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib --libexecdir=/usr/lib --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.1.2 --enable-ssp --disable-libssp --disable-libgcj --with-slibdir=/lib --with-system-zlib --enable-shared --enable-__cxa_atexit --enable-libstdcxx-allocator=new --program-suffix=-4.1 --enable-version-specific-runtime-libs --without-system-libunwind --with-cpu=generic --host=i586-suse-linux
Thread model: posix
gcc version 4.1.2 20061115 (prerelease) (SUSE Linux)

g++ -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5.1' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1)
Comment 1 Gael Guennebaud 2013-06-21 22:11:10 UTC
Sounds like a duplicate of 556

*** This bug has been marked as a duplicate of bug 556 ***
Comment 2 Gael Guennebaud 2013-06-21 22:12:43 UTC
should be reported to mingw team.

Note You need to log in before you can comment on or make changes to this bug.