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