From 024d1a051eac0931cea81e028c25ecbbc10691c9 Mon Sep 17 00:00:00 2001 From: Alexey Kopytov Date: Sun, 28 Aug 2016 16:04:54 +0300 Subject: [PATCH] Bug #82760: Do not use -fno-expensive-optimizations just to avoid fused madd instructions -fno-expensive-optimizations is used on some architectures with the only purpose of avoiding fused multiple-add instructions usage by the compiler. That's too restrictive. Use -ffp-contract=off instead. This also removes some IA64-specific --replace_result directives that are unnecessary with this change and reasonably recent GCC versions (it's just that neither -mno-fused-madd nor -ffp-contract=off were supported by GCC on IA64 at the time those directives were added). --- cmake/build_configurations/compiler_options.cmake | 12 ++++++------ cmake/floating_point.cmake | 10 +++++----- mysql-test/suite/innodb_gis/t/1.test | 6 ------ mysql-test/suite/innodb_gis/t/gis.test | 6 ------ mysql-test/t/gis.test | 6 ------ 5 files changed, 11 insertions(+), 29 deletions(-) diff --git a/cmake/build_configurations/compiler_options.cmake b/cmake/build_configurations/compiler_options.cmake index 29d8f28..a1ebe2a 100644 --- a/cmake/build_configurations/compiler_options.cmake +++ b/cmake/build_configurations/compiler_options.cmake @@ -34,9 +34,9 @@ IF(UNIX) IF(WITH_VALGRIND) SET(COMMON_C_FLAGS "-fno-inline ${COMMON_C_FLAGS}") ENDIF() - # Disable optimizations that change floating point results - IF(HAVE_C_FLOATING_POINT_OPTIMIZATION_PROBLEMS) - SET(COMMON_C_FLAGS "${COMMON_C_FLAGS} -fno-expensive-optimizations") + # Disable floating point expression contractions to avoid result differences + IF(HAVE_C_FLOATING_POINT_FUSED_MADD) + SET(COMMON_C_FLAGS "${COMMON_C_FLAGS} -ffp-contract=off") ENDIF() SET(CMAKE_C_FLAGS_DEBUG "${COMMON_C_FLAGS}") SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 ${COMMON_C_FLAGS}") @@ -53,9 +53,9 @@ IF(UNIX) IF(WITH_VALGRIND) SET(COMMON_CXX_FLAGS "-fno-inline ${COMMON_CXX_FLAGS}") ENDIF() - # Disable optimizations that change floating point results - IF(HAVE_CXX_FLOATING_POINT_OPTIMIZATION_PROBLEMS) - SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} -fno-expensive-optimizations") + # Disable floating point expression contractions to avoid result differences + IF(HAVE_CXX_FLOATING_POINT_FUSED_MADD) + SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} -ffp-contract=off") ENDIF() SET(CMAKE_CXX_FLAGS_DEBUG "${COMMON_CXX_FLAGS}") SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 ${COMMON_CXX_FLAGS}") diff --git a/cmake/floating_point.cmake b/cmake/floating_point.cmake index 6db63ad..c5ec816 100644 --- a/cmake/floating_point.cmake +++ b/cmake/floating_point.cmake @@ -32,8 +32,8 @@ SET(code " /* s should now be either 5e 74 d1 45 17 5d 14 40 or 40 14 5d 17 45 d1 74 5e, depending on endianness. If the floating point - operations are over optimized, the least significant byte is 5d instead - of 5e. + operations are optimizaed with fused multiply-add instructions, the least + significant byte is 5d instead of 5e. */ return (*(unsigned char*)(&s) == 0x5e || *((unsigned char*)(&s) + 7) == 0x5e); @@ -42,15 +42,15 @@ SET(code " SET(SAVE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") SET(CMAKE_REQUIRED_FLAGS - "${CMAKE_REQUIRED_FLAGS} -O3 -fexpensive-optimizations" + "${CMAKE_REQUIRED_FLAGS} -O3" ) IF(CMAKE_COMPILER_IS_GNUCC) - CHECK_C_SOURCE_RUNS("${code}" HAVE_C_FLOATING_POINT_OPTIMIZATION_PROBLEMS) + CHECK_C_SOURCE_RUNS("${code}" HAVE_C_FLOATING_POINT_FUSED_MADD) ENDIF() IF(CMAKE_COMPILER_IS_GNUCXX) - CHECK_CXX_SOURCE_RUNS("${code}" HAVE_CXX_FLOATING_POINT_OPTIMIZATION_PROBLEMS) + CHECK_CXX_SOURCE_RUNS("${code}" HAVE_CXX_FLOATING_POINT_FUSED_MADD) ENDIF() SET(CMAKE_REQUIRED_FLAGS "${SAVE_CMAKE_REQUIRED_FLAGS}") diff --git a/mysql-test/suite/innodb_gis/t/1.test b/mysql-test/suite/innodb_gis/t/1.test index 297f1f7..d5a3b1d 100644 --- a/mysql-test/suite/innodb_gis/t/1.test +++ b/mysql-test/suite/innodb_gis/t/1.test @@ -371,15 +371,9 @@ insert into t1 values ('85984',ST_GeomFromText('MULTIPOLYGON(((-115.006363 36.248666,-115.263639 36.247466,-115.263839 36.252766,-115.261439 36.252666,-115.261439 36.247366,-115.247239 36.247066)))')); -# Expected result is 115.31877315203187, but IA64 returns 115.31877315203188 -# due to fused multiply-add instructions. ---replace_result 115.31877315203188 115.31877315203187 select object_id, ST_geometrytype(geo), ST_ISSIMPLE(GEO), ST_ASTEXT(ST_centroid(geo)) from t1 where object_id=85998; -# Expected result is 36.3310176346905, but IA64 returns 36.3310176346904 -# due to fused multiply-add instructions. ---replace_result 36.3310176346904 36.3310176346905 -114.87787186923326 -114.87787186923313 36.33101763469053 36.33101763469059 36.33101763469043 36.33101763469059 select object_id, ST_geometrytype(geo), ST_ISSIMPLE(GEO), ST_ASTEXT(ST_centroid(geo)) from t1 where object_id=85984; diff --git a/mysql-test/suite/innodb_gis/t/gis.test b/mysql-test/suite/innodb_gis/t/gis.test index 3c582a3..e7f88ba 100644 --- a/mysql-test/suite/innodb_gis/t/gis.test +++ b/mysql-test/suite/innodb_gis/t/gis.test @@ -365,15 +365,9 @@ insert into t1 values ('85984',ST_GeomFromText('MULTIPOLYGON(((-115.006363 36.248666,-115.263639 36.247466,-115.263839 36.252766,-115.261439 36.252666,-115.261439 36.247366,-115.247239 36.247066)))')); -# Expected result is 115.31877315203187, but IA64 returns 115.31877315203188 -# due to fused multiply-add instructions. ---replace_result 115.31877315203188 115.31877315203187 select object_id, ST_geometrytype(geo), ST_ISSIMPLE(GEO), ST_ASTEXT(ST_centroid(geo)) from t1 where object_id=85998; -# Expected result is 36.3310176346905, but IA64 returns 36.3310176346904 -# due to fused multiply-add instructions. ---replace_result 36.3310176346904 36.3310176346905 -114.87787186923326 -114.87787186923313 36.33101763469053 36.33101763469059 36.33101763469043 36.33101763469059 select object_id, ST_geometrytype(geo), ST_ISSIMPLE(GEO), ST_ASTEXT(ST_centroid(geo)) from t1 where object_id=85984; diff --git a/mysql-test/t/gis.test b/mysql-test/t/gis.test index faf53d4..530a9f1 100644 --- a/mysql-test/t/gis.test +++ b/mysql-test/t/gis.test @@ -362,15 +362,9 @@ insert into t1 values ('85984',ST_GeomFromText('MULTIPOLYGON(((-115.006363 36.248666,-115.263639 36.247466,-115.263839 36.252766,-115.261439 36.252666,-115.261439 36.247366,-115.247239 36.247066)))')); -# Expected result is 115.31877315203187, but IA64 returns 115.31877315203188 -# due to fused multiply-add instructions. ---replace_result 115.31877315203188 115.31877315203187 select object_id, ST_geometrytype(geo), ST_ISSIMPLE(GEO), ST_ASTEXT(ST_centroid(geo)) from t1 where object_id=85998; -# Expected result is 36.3310176346905, but IA64 returns 36.3310176346904 -# due to fused multiply-add instructions. ---replace_result 36.3310176346904 36.3310176346905 -114.87787186923326 -114.87787186923313 36.33101763469053 36.33101763469059 36.33101763469043 36.33101763469059 select object_id, ST_geometrytype(geo), ST_ISSIMPLE(GEO), ST_ASTEXT(ST_centroid(geo)) from t1 where object_id=85984;