changeset 2380:3a2c8d0a600d jdk8u222-b02

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
author sgehwolf
date Mon, 29 Apr 2019 14:23:21 +0200
parents 9d00e3f144e0
children e4f636834af7
files common/autoconf/flags.m4 common/autoconf/generated-configure.sh common/autoconf/spec.gmk.in
diffstat 3 files changed, 181 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/common/autoconf/flags.m4	Wed May 01 06:16:32 2019 +0100
+++ b/common/autoconf/flags.m4	Mon Apr 29 14:23:21 2019 +0200
@@ -450,6 +450,7 @@
   # Later we will also have CFLAGS and LDFLAGS for the hotspot subrepo build.
   #
 
+  FDLIBM_CFLAGS=""
   # Setup compiler/platform specific flags to CFLAGS_JDK,
   # CXXFLAGS_JDK and CCXXFLAGS_JDK (common to C and CXX?)
   if test "x$TOOLCHAIN_TYPE" = xgcc; then
@@ -474,6 +475,37 @@
         ;;
     esac
     TOOLCHAIN_CHECK_COMPILER_VERSION(6, FLAGS_SETUP_GCC6_COMPILER_FLAGS)
+
+    # Check that the compiler supports -ffp-contract=off flag
+    # Set FDLIBM_CFLAGS to -ffp-contract=off if it does.
+    # For GCC < 4.6, on x86, x86_64 and ppc check for
+    # -mno-fused-madd and -fno-strict-aliasing. If they exist,
+    # use them as a substitute for -ffp-contract=off.
+    #
+    # These flags are required for GCC-based builds of
+    # fdlibm with optimization without losing precision.
+    # Notably, -ffp-contract=off needs to be added for GCC >= 4.6,
+    #          -mno-fused-madd -fno-strict-aliasing for GCC < 4.6
+    COMPILER_FP_CONTRACT_OFF_FLAG="-ffp-contract=off"
+    FLAGS_CXX_COMPILER_CHECK_ARGUMENTS([[$]COMPILER_FP_CONTRACT_OFF_FLAG -Werror],
+                                       [], [COMPILER_FP_CONTRACT_OFF_FLAG=""])
+    if test "x$COMPILER_FP_CONTRACT_OFF_FLAG" = x; then
+      if test "$OPENJDK_TARGET_CPU_ARCH" = "x86" ||
+         test "$OPENJDK_TARGET_CPU_ARCH" = "x86_64" ||
+         test "$OPENJDK_TARGET_CPU_ARCH" = "ppc"; then
+        M_NO_FUSED_ADD_FLAG="-mno-fused-madd"
+        FLAGS_CXX_COMPILER_CHECK_ARGUMENTS([[$]M_NO_FUSED_ADD_FLAG -Werror],
+                                           [], [M_NO_FUSED_ADD_FLAG=""])
+        NO_STRICT_ALIASING_FLAG="-fno-strict-aliasing"
+        FLAGS_CXX_COMPILER_CHECK_ARGUMENTS([[$]NO_STRICT_ALIASING_FLAG -Werror],
+                                           [], [NO_STRICT_ALIASING_FLAG=""])
+        if test "x$M_NO_FUSED_ADD_FLAG" != "x" && test "x$NO_STRICT_ALIASING_FLAG" != "x"; then
+          FDLIBM_CFLAGS="$M_NO_FUSED_ADD_FLAG $NO_STRICT_ALIASING_FLAG"
+        fi
+      fi
+    else
+      FDLIBM_CFLAGS="$COMPILER_FP_CONTRACT_OFF_FLAG"
+    fi
   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
     CCXXFLAGS_JDK="$CCXXFLAGS $CCXXFLAGS_JDK -DTRACING -DMACRO_MEMSYS_OPS -DBREAKPTS"
     if test "x$OPENJDK_TARGET_CPU_ARCH" = xx86; then
@@ -505,6 +537,7 @@
           -D_STATIC_CPPLIB -D_DISABLE_DEPRECATE_STATIC_CPPLIB"
     fi
   fi
+  AC_SUBST(FDLIBM_CFLAGS)
 
   ###############################################################################
 
--- a/common/autoconf/generated-configure.sh	Wed May 01 06:16:32 2019 +0100
+++ b/common/autoconf/generated-configure.sh	Mon Apr 29 14:23:21 2019 +0200
@@ -686,6 +686,7 @@
 CFLAGS_JDKEXE
 CFLAGS_JDKLIB
 MACOSX_VERSION_MIN
+FDLIBM_CFLAGS
 NO_LIFETIME_DSE_CFLAG
 NO_DELETE_NULL_POINTER_CHECKS_CFLAG
 LEGACY_EXTRA_LDFLAGS
@@ -3908,7 +3909,7 @@
 
 
 #
-# Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -4375,7 +4376,7 @@
 #CUSTOM_AUTOCONF_INCLUDE
 
 # Do not change or remove the following line, it is needed for consistency checks:
-DATE_WHEN_GENERATED=1553405262
+DATE_WHEN_GENERATED=1556533111
 
 ###############################################################################
 #
@@ -41545,6 +41546,7 @@
   # Later we will also have CFLAGS and LDFLAGS for the hotspot subrepo build.
   #
 
+  FDLIBM_CFLAGS=""
   # Setup compiler/platform specific flags to CFLAGS_JDK,
   # CXXFLAGS_JDK and CCXXFLAGS_JDK (common to C and CXX?)
   if test "x$TOOLCHAIN_TYPE" = xgcc; then
@@ -41786,6 +41788,148 @@
     :
   fi
 
+
+    # Check that the compiler supports -ffp-contract=off flag
+    # Set FDLIBM_CFLAGS to -ffp-contract=off if it does.
+    # For GCC < 4.6, on x86, x86_64 and ppc check for
+    # -mno-fused-madd and -fno-strict-aliasing. If they exist,
+    # use them as a substitute for -ffp-contract=off.
+    #
+    # These flags are required for GCC-based builds of
+    # fdlibm with optimization without losing precision.
+    # Notably, -ffp-contract=off needs to be added for GCC >= 4.6,
+    #          -mno-fused-madd -fno-strict-aliasing for GCC < 4.6
+    COMPILER_FP_CONTRACT_OFF_FLAG="-ffp-contract=off"
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if the C++ compiler supports \"$COMPILER_FP_CONTRACT_OFF_FLAG -Werror\"" >&5
+$as_echo_n "checking if the C++ compiler supports \"$COMPILER_FP_CONTRACT_OFF_FLAG -Werror\"... " >&6; }
+  supports=yes
+
+  saved_cxxflags="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAG $COMPILER_FP_CONTRACT_OFF_FLAG -Werror"
+  ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+
+else
+  supports=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+  CXXFLAGS="$saved_cxxflags"
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supports" >&5
+$as_echo "$supports" >&6; }
+  if test "x$supports" = "xyes" ; then
+    :
+  else
+    COMPILER_FP_CONTRACT_OFF_FLAG=""
+  fi
+
+    if test "x$COMPILER_FP_CONTRACT_OFF_FLAG" = x; then
+      if test "$OPENJDK_TARGET_CPU_ARCH" = "x86" ||
+         test "$OPENJDK_TARGET_CPU_ARCH" = "x86_64" ||
+         test "$OPENJDK_TARGET_CPU_ARCH" = "ppc"; then
+        M_NO_FUSED_ADD_FLAG="-mno-fused-madd"
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if the C++ compiler supports \"$M_NO_FUSED_ADD_FLAG -Werror\"" >&5
+$as_echo_n "checking if the C++ compiler supports \"$M_NO_FUSED_ADD_FLAG -Werror\"... " >&6; }
+  supports=yes
+
+  saved_cxxflags="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAG $M_NO_FUSED_ADD_FLAG -Werror"
+  ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+
+else
+  supports=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+  CXXFLAGS="$saved_cxxflags"
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supports" >&5
+$as_echo "$supports" >&6; }
+  if test "x$supports" = "xyes" ; then
+    :
+  else
+    M_NO_FUSED_ADD_FLAG=""
+  fi
+
+        NO_STRICT_ALIASING_FLAG="-fno-strict-aliasing"
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking if the C++ compiler supports \"$NO_STRICT_ALIASING_FLAG -Werror\"" >&5
+$as_echo_n "checking if the C++ compiler supports \"$NO_STRICT_ALIASING_FLAG -Werror\"... " >&6; }
+  supports=yes
+
+  saved_cxxflags="$CXXFLAGS"
+  CXXFLAGS="$CXXFLAG $NO_STRICT_ALIASING_FLAG -Werror"
+  ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int i;
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+
+else
+  supports=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+  ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+  CXXFLAGS="$saved_cxxflags"
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $supports" >&5
+$as_echo "$supports" >&6; }
+  if test "x$supports" = "xyes" ; then
+    :
+  else
+    NO_STRICT_ALIASING_FLAG=""
+  fi
+
+        if test "x$M_NO_FUSED_ADD_FLAG" != "x" && test "x$NO_STRICT_ALIASING_FLAG" != "x"; then
+          FDLIBM_CFLAGS="$M_NO_FUSED_ADD_FLAG $NO_STRICT_ALIASING_FLAG"
+        fi
+      fi
+    else
+      FDLIBM_CFLAGS="$COMPILER_FP_CONTRACT_OFF_FLAG"
+    fi
   elif test "x$TOOLCHAIN_TYPE" = xsolstudio; then
     CCXXFLAGS_JDK="$CCXXFLAGS $CCXXFLAGS_JDK -DTRACING -DMACRO_MEMSYS_OPS -DBREAKPTS"
     if test "x$OPENJDK_TARGET_CPU_ARCH" = xx86; then
@@ -41818,6 +41962,7 @@
     fi
   fi
 
+
   ###############################################################################
 
   # Adjust flags according to debug level.
--- a/common/autoconf/spec.gmk.in	Wed May 01 06:16:32 2019 +0100
+++ b/common/autoconf/spec.gmk.in	Mon Apr 29 14:23:21 2019 +0200
@@ -356,6 +356,7 @@
 CC:=@FIXPATH@ @CCACHE@ @CC@
 
 # CFLAGS used to compile the jdk native libraries (C-code)
+FDLIBM_CFLAGS:=@FDLIBM_CFLAGS@
 CFLAGS_JDKLIB:=@CFLAGS_JDKLIB@
 CXXFLAGS_JDKLIB:=@CXXFLAGS_JDKLIB@