Chris@42: dnl @synopsis AX_CC_MAXOPT Chris@42: dnl @summary turn on optimization flags for the C compiler Chris@42: dnl @category C Chris@42: dnl Chris@42: dnl Try to turn on "good" C optimization flags for various compilers Chris@42: dnl and architectures, for some definition of "good". (In our case, Chris@42: dnl good for FFTW and hopefully for other scientific codes. Modify Chris@42: dnl as needed.) Chris@42: dnl Chris@42: dnl The user can override the flags by setting the CFLAGS environment Chris@42: dnl variable. Chris@42: dnl Chris@42: dnl Note also that the flags assume that ANSI C aliasing rules are Chris@42: dnl followed by the code (e.g. for gcc's -fstrict-aliasing), and that Chris@42: dnl floating-point computations can be re-ordered as needed. Chris@42: dnl Chris@42: dnl Requires macros: AX_CHECK_COMPILER_FLAGS, AX_COMPILER_VENDOR, Chris@42: dnl Chris@42: dnl @version 2011-06-22 Chris@42: dnl @license GPLWithACException Chris@42: dnl @author Steven G. Johnson and Matteo Frigo. Chris@42: AC_DEFUN([AX_CC_MAXOPT], Chris@42: [ Chris@42: AC_REQUIRE([AC_PROG_CC]) Chris@42: AC_REQUIRE([AX_COMPILER_VENDOR]) Chris@42: AC_REQUIRE([AC_CANONICAL_HOST]) Chris@42: Chris@42: # Try to determine "good" native compiler flags if none specified via CFLAGS Chris@42: if test "$ac_test_CFLAGS" != "set"; then Chris@42: CFLAGS="" Chris@42: case $ax_cv_c_compiler_vendor in Chris@42: dec) CFLAGS="-newc -w0 -O5 -ansi_alias -ansi_args -fp_reorder -tune host" Chris@42: ;; Chris@42: Chris@42: sun) CFLAGS="-native -fast -xO5 -dalign" Chris@42: ;; Chris@42: Chris@42: hp) CFLAGS="+Oall +Optrs_ansi +DSnative" Chris@42: ;; Chris@42: Chris@42: ibm) xlc_opt="-qarch=auto -qtune=auto" Chris@42: AX_CHECK_COMPILER_FLAGS($xlc_opt, Chris@42: CFLAGS="-O3 -qalias=ansi -w $xlc_opt", Chris@42: [CFLAGS="-O3 -qalias=ansi -w"]) Chris@42: ;; Chris@42: Chris@42: intel) CFLAGS="-O3" Chris@42: # Intel seems to have changed the spelling of this flag recently Chris@42: icc_ansi_alias="unknown" Chris@42: for flag in -ansi-alias -ansi_alias; do Chris@42: AX_CHECK_COMPILER_FLAGS($flag, [icc_ansi_alias=$flag; break]) Chris@42: done Chris@42: if test "x$icc_ansi_alias" != xunknown; then Chris@42: CFLAGS="$CFLAGS $icc_ansi_alias" Chris@42: fi Chris@42: AX_CHECK_COMPILER_FLAGS(-malign-double, CFLAGS="$CFLAGS -malign-double") Chris@42: # We used to check for architecture flags here, e.g. -xHost etc., Chris@42: # but these flags are problematic. On icc-12.0.0, "-mavx -xHost" Chris@42: # overrides -mavx with -xHost, generating SSE2 code instead of AVX Chris@42: # code. ICC does not seem to support -mtune=host or equivalent Chris@42: # non-ABI changing flag. Chris@42: ;; Chris@42: Chris@42: clang) Chris@42: CFLAGS="-O3 -fomit-frame-pointer" Chris@42: AX_CHECK_COMPILER_FLAGS(-mtune=native, CFLAGS="$CFLAGS -mtune=native") Chris@42: AX_CHECK_COMPILER_FLAGS(-fstrict-aliasing,CFLAGS="$CFLAGS -fstrict-aliasing") Chris@42: AX_CHECK_COMPILER_FLAGS(-ffast-math, CFLAGS="$CFLAGS -ffast-math") Chris@42: ;; Chris@42: Chris@42: gnu) Chris@42: # Default optimization flags for gcc on all systems. Chris@42: # Somehow -O3 does not imply -fomit-frame-pointer on ia32 Chris@42: CFLAGS="-O3 -fomit-frame-pointer" Chris@42: Chris@42: # tune for the host by default Chris@42: AX_CHECK_COMPILER_FLAGS(-mtune=native, CFLAGS="$CFLAGS -mtune=native") Chris@42: Chris@42: # -malign-double for x86 systems Chris@42: AX_CHECK_COMPILER_FLAGS(-malign-double, CFLAGS="$CFLAGS -malign-double") Chris@42: Chris@42: # -fstrict-aliasing for gcc-2.95+ Chris@42: AX_CHECK_COMPILER_FLAGS(-fstrict-aliasing, Chris@42: CFLAGS="$CFLAGS -fstrict-aliasing") Chris@42: Chris@42: # -fno-schedule-insns is pretty much required on all risc Chris@42: # processors. Chris@42: # Chris@42: # gcc performs one pass of instruction scheduling, then a pass of Chris@42: # register allocation, then another pass of instruction Chris@42: # scheduling. The first pass reorders instructions in a way that Chris@42: # is pretty much the worst possible for the purposes of register Chris@42: # allocation. We disable the first pass. Chris@42: AX_CHECK_COMPILER_FLAGS(-fno-schedule-insns, CFLAGS="$CFLAGS -fno-schedule-insns") Chris@42: Chris@42: # note that we enable "unsafe" fp optimization with other compilers, too Chris@42: AX_CHECK_COMPILER_FLAGS(-ffast-math, CFLAGS="$CFLAGS -ffast-math") Chris@42: Chris@42: # flags to enable power ISA 2.07 instructions with gcc (always true with vsx) Chris@42: if test "$have_vsx" = "yes"; then Chris@42: AX_CHECK_COMPILER_FLAGS(-mcpu=power8, CFLAGS="$CFLAGS -mcpu=power8") Chris@42: AX_CHECK_COMPILER_FLAGS(-mpower8-fusion, CFLAGS="$CFLAGS -mpower8-fusion") Chris@42: AX_CHECK_COMPILER_FLAGS(-mpower8-vector, CFLAGS="$CFLAGS -mpower8-vector") Chris@42: AX_CHECK_COMPILER_FLAGS(-mdirect-move, CFLAGS="$CFLAGS -mdirect-move") Chris@42: fi Chris@42: ;; Chris@42: esac Chris@42: Chris@42: if test -z "$CFLAGS"; then Chris@42: echo "" Chris@42: echo "********************************************************" Chris@42: echo "* WARNING: Don't know the best CFLAGS for this system *" Chris@42: echo "* Use ./configure CFLAGS=... to specify your own flags *" Chris@42: echo "* (otherwise, a default of CFLAGS=-O3 will be used) *" Chris@42: echo "********************************************************" Chris@42: echo "" Chris@42: CFLAGS="-O3" Chris@42: fi Chris@42: Chris@42: AX_CHECK_COMPILER_FLAGS($CFLAGS, [], [ Chris@42: echo "" Chris@42: echo "********************************************************" Chris@42: echo "* WARNING: The guessed CFLAGS don't seem to work with *" Chris@42: echo "* your compiler. *" Chris@42: echo "* Use ./configure CFLAGS=... to specify your own flags *" Chris@42: echo "********************************************************" Chris@42: echo "" Chris@42: CFLAGS="" Chris@42: ]) Chris@42: Chris@42: fi Chris@42: ])