8210416: [linux] Poor StrictMath performance due to non-optimized compilation
Summary: Compile fdlibm with -O2 -ffp-contract=off on gcc/clang arches.
Reviewed-by: aph, erikj, dholmes, darcy, ihse
--- a/make/autoconf/flags-cflags.m4 Mon Sep 17 11:49:20 2018 +0200
+++ b/make/autoconf/flags-cflags.m4 Mon Sep 17 10:53:56 2018 +0200
@@ -373,6 +373,20 @@
FLAGS_SETUP_CFLAGS_CPU_DEP([BUILD], [OPENJDK_BUILD_])
+ COMPILER_FP_CONTRACT_OFF_FLAG="-ffp-contract=off"
+ # Check that the compiler supports -ffp-contract=off flag
+ # Set FDLIBM_CFLAGS to -ffp-contract=off if it does. Empty
+ # otherwise.
+ # 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.
+ if test "x$TOOLCHAIN_TYPE" = xgcc || test "x$TOOLCHAIN_TYPE" = xclang; then
+ FLAGS_COMPILER_CHECK_ARGUMENTS(ARGUMENT: [${COMPILER_FP_CONTRACT_OFF_FLAG}],
+ IF_TRUE: [FDLIBM_CFLAGS=${COMPILER_FP_CONTRACT_OFF_FLAG}],
+ IF_FALSE: [FDLIBM_CFLAGS=""])
+ fi
+ AC_SUBST(FDLIBM_CFLAGS)
+
# Tests are only ever compiled for TARGET
CFLAGS_TESTLIB="$CFLAGS_JDKLIB"
CXXFLAGS_TESTLIB="$CXXFLAGS_JDKLIB"
--- a/make/autoconf/spec.gmk.in Mon Sep 17 11:49:20 2018 +0200
+++ b/make/autoconf/spec.gmk.in Mon Sep 17 10:53:56 2018 +0200
@@ -450,6 +450,7 @@
LIBJSIG_HASHSTYLE_LDFLAGS := @LIBJSIG_HASHSTYLE_LDFLAGS@
LIBJSIG_NOEXECSTACK_LDFLAGS := @LIBJSIG_NOEXECSTACK_LDFLAGS@
+FDLIBM_CFLAGS := @FDLIBM_CFLAGS@
JVM_CFLAGS := @JVM_CFLAGS@
JVM_LDFLAGS := @JVM_LDFLAGS@
JVM_ASFLAGS := @JVM_ASFLAGS@
--- a/make/lib/CoreLibraries.gmk Mon Sep 17 11:49:20 2018 +0200
+++ b/make/lib/CoreLibraries.gmk Mon Sep 17 10:53:56 2018 +0200
@@ -39,20 +39,15 @@
BUILD_LIBFDLIBM_OPTIMIZATION := HIGH
endif
-ifeq ($(OPENJDK_TARGET_OS), linux)
- ifeq ($(OPENJDK_TARGET_CPU), ppc64)
- BUILD_LIBFDLIBM_OPTIMIZATION := HIGH
- else ifeq ($(OPENJDK_TARGET_CPU), ppc64le)
- BUILD_LIBFDLIBM_OPTIMIZATION := HIGH
- else ifeq ($(OPENJDK_TARGET_CPU), s390x)
- BUILD_LIBFDLIBM_OPTIMIZATION := HIGH
- else ifeq ($(OPENJDK_TARGET_CPU), aarch64)
- BUILD_LIBFDLIBM_OPTIMIZATION := HIGH
- endif
+# If FDLIBM_CFLAGS is non-empty we know that we can optimize
+# fdlibm when adding those extra C flags. Currently GCC,
+# and clang only.
+ifneq ($(FDLIBM_CFLAGS), )
+ BUILD_LIBFDLIBM_OPTIMIZATION := LOW
endif
LIBFDLIBM_SRC := $(TOPDIR)/src/java.base/share/native/libfdlibm
-LIBFDLIBM_CFLAGS := -I$(LIBFDLIBM_SRC)
+LIBFDLIBM_CFLAGS := -I$(LIBFDLIBM_SRC) $(FDLIBM_CFLAGS)
ifneq ($(OPENJDK_TARGET_OS), macosx)
$(eval $(call SetupNativeCompilation, BUILD_LIBFDLIBM, \
@@ -64,10 +59,6 @@
CFLAGS := $(CFLAGS_JDKLIB) $(LIBFDLIBM_CFLAGS), \
CFLAGS_windows_debug := -DLOGGING, \
CFLAGS_aix := -qfloat=nomaf, \
- CFLAGS_linux_ppc64 := -ffp-contract=off, \
- CFLAGS_linux_ppc64le := -ffp-contract=off, \
- CFLAGS_linux_s390x := -ffp-contract=off, \
- CFLAGS_linux_aarch64 := -ffp-contract=off, \
DISABLED_WARNINGS_gcc := sign-compare misleading-indentation array-bounds, \
DISABLED_WARNINGS_microsoft := 4146 4244 4018, \
ARFLAGS := $(ARFLAGS), \