Mon, 29 Apr 2019 14:23:21 +0200
8210416: [linux] Poor StrictMath performance due to non-optimized compilation
Summary: Compile fdlibm with -O3 and relevant C flags on gcc arches.
Reviewed-by: mbaesken, andrew
1.1 --- a/common/autoconf/flags.m4 Wed May 01 06:16:32 2019 +0100 1.2 +++ b/common/autoconf/flags.m4 Mon Apr 29 14:23:21 2019 +0200 1.3 @@ -450,6 +450,7 @@ 1.4 # Later we will also have CFLAGS and LDFLAGS for the hotspot subrepo build. 1.5 # 1.6 1.7 + FDLIBM_CFLAGS="" 1.8 # Setup compiler/platform specific flags to CFLAGS_JDK, 1.9 # CXXFLAGS_JDK and CCXXFLAGS_JDK (common to C and CXX?) 1.10 if test "x$TOOLCHAIN_TYPE" = xgcc; then 1.11 @@ -474,6 +475,37 @@ 1.12 ;; 1.13 esac 1.14 TOOLCHAIN_CHECK_COMPILER_VERSION(6, FLAGS_SETUP_GCC6_COMPILER_FLAGS) 1.15 + 1.16 + # Check that the compiler supports -ffp-contract=off flag 1.17 + # Set FDLIBM_CFLAGS to -ffp-contract=off if it does. 1.18 + # For GCC < 4.6, on x86, x86_64 and ppc check for 1.19 + # -mno-fused-madd and -fno-strict-aliasing. If they exist, 1.20 + # use them as a substitute for -ffp-contract=off. 1.21 + # 1.22 + # These flags are required for GCC-based builds of 1.23 + # fdlibm with optimization without losing precision. 1.24 + # Notably, -ffp-contract=off needs to be added for GCC >= 4.6, 1.25 + # -mno-fused-madd -fno-strict-aliasing for GCC < 4.6 1.26 + COMPILER_FP_CONTRACT_OFF_FLAG="-ffp-contract=off" 1.27 + FLAGS_CXX_COMPILER_CHECK_ARGUMENTS([[$]COMPILER_FP_CONTRACT_OFF_FLAG -Werror], 1.28 + [], [COMPILER_FP_CONTRACT_OFF_FLAG=""]) 1.29 + if test "x$COMPILER_FP_CONTRACT_OFF_FLAG" = x; then 1.30 + if test "$OPENJDK_TARGET_CPU_ARCH" = "x86" || 1.31 + test "$OPENJDK_TARGET_CPU_ARCH" = "x86_64" || 1.32 + test "$OPENJDK_TARGET_CPU_ARCH" = "ppc"; then 1.33 + M_NO_FUSED_ADD_FLAG="-mno-fused-madd" 1.34 + FLAGS_CXX_COMPILER_CHECK_ARGUMENTS([[$]M_NO_FUSED_ADD_FLAG -Werror], 1.35 + [], [M_NO_FUSED_ADD_FLAG=""]) 1.36 + NO_STRICT_ALIASING_FLAG="-fno-strict-aliasing" 1.37 + FLAGS_CXX_COMPILER_CHECK_ARGUMENTS([[$]NO_STRICT_ALIASING_FLAG -Werror], 1.38 + [], [NO_STRICT_ALIASING_FLAG=""]) 1.39 + if test "x$M_NO_FUSED_ADD_FLAG" != "x" && test "x$NO_STRICT_ALIASING_FLAG" != "x"; then 1.40 + FDLIBM_CFLAGS="$M_NO_FUSED_ADD_FLAG $NO_STRICT_ALIASING_FLAG" 1.41 + fi 1.42 + fi 1.43 + else 1.44 + FDLIBM_CFLAGS="$COMPILER_FP_CONTRACT_OFF_FLAG" 1.45 + fi 1.46 elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then 1.47 CCXXFLAGS_JDK="$CCXXFLAGS $CCXXFLAGS_JDK -DTRACING -DMACRO_MEMSYS_OPS -DBREAKPTS" 1.48 if test "x$OPENJDK_TARGET_CPU_ARCH" = xx86; then 1.49 @@ -505,6 +537,7 @@ 1.50 -D_STATIC_CPPLIB -D_DISABLE_DEPRECATE_STATIC_CPPLIB" 1.51 fi 1.52 fi 1.53 + AC_SUBST(FDLIBM_CFLAGS) 1.54 1.55 ############################################################################### 1.56
2.1 --- a/common/autoconf/generated-configure.sh Wed May 01 06:16:32 2019 +0100 2.2 +++ b/common/autoconf/generated-configure.sh Mon Apr 29 14:23:21 2019 +0200 2.3 @@ -686,6 +686,7 @@ 2.4 CFLAGS_JDKEXE 2.5 CFLAGS_JDKLIB 2.6 MACOSX_VERSION_MIN 2.7 +FDLIBM_CFLAGS 2.8 NO_LIFETIME_DSE_CFLAG 2.9 NO_DELETE_NULL_POINTER_CHECKS_CFLAG 2.10 LEGACY_EXTRA_LDFLAGS 2.11 @@ -3908,7 +3909,7 @@ 2.12 2.13 2.14 # 2.15 -# Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. 2.16 +# Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. 2.17 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.18 # 2.19 # This code is free software; you can redistribute it and/or modify it 2.20 @@ -4375,7 +4376,7 @@ 2.21 #CUSTOM_AUTOCONF_INCLUDE 2.22 2.23 # Do not change or remove the following line, it is needed for consistency checks: 2.24 -DATE_WHEN_GENERATED=1553405262 2.25 +DATE_WHEN_GENERATED=1556533111 2.26 2.27 ############################################################################### 2.28 # 2.29 @@ -41545,6 +41546,7 @@ 2.30 # Later we will also have CFLAGS and LDFLAGS for the hotspot subrepo build. 2.31 # 2.32 2.33 + FDLIBM_CFLAGS="" 2.34 # Setup compiler/platform specific flags to CFLAGS_JDK, 2.35 # CXXFLAGS_JDK and CCXXFLAGS_JDK (common to C and CXX?) 2.36 if test "x$TOOLCHAIN_TYPE" = xgcc; then 2.37 @@ -41786,6 +41788,148 @@ 2.38 : 2.39 fi 2.40 2.41 + 2.42 + # Check that the compiler supports -ffp-contract=off flag 2.43 + # Set FDLIBM_CFLAGS to -ffp-contract=off if it does. 2.44 + # For GCC < 4.6, on x86, x86_64 and ppc check for 2.45 + # -mno-fused-madd and -fno-strict-aliasing. If they exist, 2.46 + # use them as a substitute for -ffp-contract=off. 2.47 + # 2.48 + # These flags are required for GCC-based builds of 2.49 + # fdlibm with optimization without losing precision. 2.50 + # Notably, -ffp-contract=off needs to be added for GCC >= 4.6, 2.51 + # -mno-fused-madd -fno-strict-aliasing for GCC < 4.6 2.52 + COMPILER_FP_CONTRACT_OFF_FLAG="-ffp-contract=off" 2.53 + 2.54 + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if the C++ compiler supports \"$COMPILER_FP_CONTRACT_OFF_FLAG -Werror\"" >&5 2.55 +$as_echo_n "checking if the C++ compiler supports \"$COMPILER_FP_CONTRACT_OFF_FLAG -Werror\"... " >&6; } 2.56 + supports=yes 2.57 + 2.58 + saved_cxxflags="$CXXFLAGS" 2.59 + CXXFLAGS="$CXXFLAG $COMPILER_FP_CONTRACT_OFF_FLAG -Werror" 2.60 + ac_ext=cpp 2.61 +ac_cpp='$CXXCPP $CPPFLAGS' 2.62 +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' 2.63 +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' 2.64 +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu 2.65 + 2.66 + cat confdefs.h - <<_ACEOF >conftest.$ac_ext 2.67 +/* end confdefs.h. */ 2.68 +int i; 2.69 +_ACEOF 2.70 +if ac_fn_cxx_try_compile "$LINENO"; then : 2.71 + 2.72 +else 2.73 + supports=no 2.74 +fi 2.75 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext 2.76 + ac_ext=cpp 2.77 +ac_cpp='$CXXCPP $CPPFLAGS' 2.78 +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' 2.79 +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' 2.80 +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu 2.81 + 2.82 + CXXFLAGS="$saved_cxxflags" 2.83 + 2.84 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supports" >&5 2.85 +$as_echo "$supports" >&6; } 2.86 + if test "x$supports" = "xyes" ; then 2.87 + : 2.88 + else 2.89 + COMPILER_FP_CONTRACT_OFF_FLAG="" 2.90 + fi 2.91 + 2.92 + if test "x$COMPILER_FP_CONTRACT_OFF_FLAG" = x; then 2.93 + if test "$OPENJDK_TARGET_CPU_ARCH" = "x86" || 2.94 + test "$OPENJDK_TARGET_CPU_ARCH" = "x86_64" || 2.95 + test "$OPENJDK_TARGET_CPU_ARCH" = "ppc"; then 2.96 + M_NO_FUSED_ADD_FLAG="-mno-fused-madd" 2.97 + 2.98 + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if the C++ compiler supports \"$M_NO_FUSED_ADD_FLAG -Werror\"" >&5 2.99 +$as_echo_n "checking if the C++ compiler supports \"$M_NO_FUSED_ADD_FLAG -Werror\"... " >&6; } 2.100 + supports=yes 2.101 + 2.102 + saved_cxxflags="$CXXFLAGS" 2.103 + CXXFLAGS="$CXXFLAG $M_NO_FUSED_ADD_FLAG -Werror" 2.104 + ac_ext=cpp 2.105 +ac_cpp='$CXXCPP $CPPFLAGS' 2.106 +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' 2.107 +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' 2.108 +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu 2.109 + 2.110 + cat confdefs.h - <<_ACEOF >conftest.$ac_ext 2.111 +/* end confdefs.h. */ 2.112 +int i; 2.113 +_ACEOF 2.114 +if ac_fn_cxx_try_compile "$LINENO"; then : 2.115 + 2.116 +else 2.117 + supports=no 2.118 +fi 2.119 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext 2.120 + ac_ext=cpp 2.121 +ac_cpp='$CXXCPP $CPPFLAGS' 2.122 +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' 2.123 +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' 2.124 +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu 2.125 + 2.126 + CXXFLAGS="$saved_cxxflags" 2.127 + 2.128 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supports" >&5 2.129 +$as_echo "$supports" >&6; } 2.130 + if test "x$supports" = "xyes" ; then 2.131 + : 2.132 + else 2.133 + M_NO_FUSED_ADD_FLAG="" 2.134 + fi 2.135 + 2.136 + NO_STRICT_ALIASING_FLAG="-fno-strict-aliasing" 2.137 + 2.138 + { $as_echo "$as_me:${as_lineno-$LINENO}: checking if the C++ compiler supports \"$NO_STRICT_ALIASING_FLAG -Werror\"" >&5 2.139 +$as_echo_n "checking if the C++ compiler supports \"$NO_STRICT_ALIASING_FLAG -Werror\"... " >&6; } 2.140 + supports=yes 2.141 + 2.142 + saved_cxxflags="$CXXFLAGS" 2.143 + CXXFLAGS="$CXXFLAG $NO_STRICT_ALIASING_FLAG -Werror" 2.144 + ac_ext=cpp 2.145 +ac_cpp='$CXXCPP $CPPFLAGS' 2.146 +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' 2.147 +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' 2.148 +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu 2.149 + 2.150 + cat confdefs.h - <<_ACEOF >conftest.$ac_ext 2.151 +/* end confdefs.h. */ 2.152 +int i; 2.153 +_ACEOF 2.154 +if ac_fn_cxx_try_compile "$LINENO"; then : 2.155 + 2.156 +else 2.157 + supports=no 2.158 +fi 2.159 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext 2.160 + ac_ext=cpp 2.161 +ac_cpp='$CXXCPP $CPPFLAGS' 2.162 +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' 2.163 +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' 2.164 +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu 2.165 + 2.166 + CXXFLAGS="$saved_cxxflags" 2.167 + 2.168 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supports" >&5 2.169 +$as_echo "$supports" >&6; } 2.170 + if test "x$supports" = "xyes" ; then 2.171 + : 2.172 + else 2.173 + NO_STRICT_ALIASING_FLAG="" 2.174 + fi 2.175 + 2.176 + if test "x$M_NO_FUSED_ADD_FLAG" != "x" && test "x$NO_STRICT_ALIASING_FLAG" != "x"; then 2.177 + FDLIBM_CFLAGS="$M_NO_FUSED_ADD_FLAG $NO_STRICT_ALIASING_FLAG" 2.178 + fi 2.179 + fi 2.180 + else 2.181 + FDLIBM_CFLAGS="$COMPILER_FP_CONTRACT_OFF_FLAG" 2.182 + fi 2.183 elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then 2.184 CCXXFLAGS_JDK="$CCXXFLAGS $CCXXFLAGS_JDK -DTRACING -DMACRO_MEMSYS_OPS -DBREAKPTS" 2.185 if test "x$OPENJDK_TARGET_CPU_ARCH" = xx86; then 2.186 @@ -41818,6 +41962,7 @@ 2.187 fi 2.188 fi 2.189 2.190 + 2.191 ############################################################################### 2.192 2.193 # Adjust flags according to debug level.
3.1 --- a/common/autoconf/spec.gmk.in Wed May 01 06:16:32 2019 +0100 3.2 +++ b/common/autoconf/spec.gmk.in Mon Apr 29 14:23:21 2019 +0200 3.3 @@ -356,6 +356,7 @@ 3.4 CC:=@FIXPATH@ @CCACHE@ @CC@ 3.5 3.6 # CFLAGS used to compile the jdk native libraries (C-code) 3.7 +FDLIBM_CFLAGS:=@FDLIBM_CFLAGS@ 3.8 CFLAGS_JDKLIB:=@CFLAGS_JDKLIB@ 3.9 CXXFLAGS_JDKLIB:=@CXXFLAGS_JDKLIB@ 3.10