Skip to content

Commit b6f04e9

Browse files
committed
Bug #24571672 DO NOT USE -FNO-EXPENSIVE-OPTIMIZATIONS JUST TO AVOID
FUSED MADD INSTRUCTIONS The fix for bug #23046775 introduced the -fno-expensive-optimizations compiler flag on some platforms. This patch lifts that restriction and instead explicitly turns off fused multiply-add instructions by setting -ffp-contract=off. This patch is a contribution from Alexey Kopytov.
1 parent 09b9845 commit b6f04e9

File tree

5 files changed

+11
-29
lines changed

5 files changed

+11
-29
lines changed

cmake/build_configurations/compiler_options.cmake

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ IF(UNIX)
3434
IF(WITH_VALGRIND)
3535
SET(COMMON_C_FLAGS "-fno-inline ${COMMON_C_FLAGS}")
3636
ENDIF()
37-
# Disable optimizations that change floating point results
38-
IF(HAVE_C_FLOATING_POINT_OPTIMIZATION_PROBLEMS)
39-
SET(COMMON_C_FLAGS "${COMMON_C_FLAGS} -fno-expensive-optimizations")
37+
# Disable floating point expression contractions to avoid result differences
38+
IF(HAVE_C_FLOATING_POINT_FUSED_MADD)
39+
SET(COMMON_C_FLAGS "${COMMON_C_FLAGS} -ffp-contract=off")
4040
ENDIF()
4141
SET(CMAKE_C_FLAGS_DEBUG "${COMMON_C_FLAGS}")
4242
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 ${COMMON_C_FLAGS}")
@@ -53,9 +53,9 @@ IF(UNIX)
5353
IF(WITH_VALGRIND)
5454
SET(COMMON_CXX_FLAGS "-fno-inline ${COMMON_CXX_FLAGS}")
5555
ENDIF()
56-
# Disable optimizations that change floating point results
57-
IF(HAVE_CXX_FLOATING_POINT_OPTIMIZATION_PROBLEMS)
58-
SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} -fno-expensive-optimizations")
56+
# Disable floating point expression contractions to avoid result differences
57+
IF(HAVE_CXX_FLOATING_POINT_FUSED_MADD)
58+
SET(COMMON_CXX_FLAGS "${COMMON_CXX_FLAGS} -ffp-contract=off")
5959
ENDIF()
6060
SET(CMAKE_CXX_FLAGS_DEBUG "${COMMON_CXX_FLAGS}")
6161
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 ${COMMON_CXX_FLAGS}")

cmake/floating_point.cmake

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ SET(code "
3232
/*
3333
s should now be either 5e 74 d1 45 17 5d 14 40 or
3434
40 14 5d 17 45 d1 74 5e, depending on endianness. If the floating point
35-
operations are over optimized, the least significant byte is 5d instead
36-
of 5e.
35+
operations are optimized with fused multiply-add instructions, the least
36+
significant byte is 5d instead of 5e.
3737
*/
3838
return (*(unsigned char*)(&s) == 0x5e ||
3939
*((unsigned char*)(&s) + 7) == 0x5e);
@@ -42,15 +42,15 @@ SET(code "
4242

4343
SET(SAVE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
4444
SET(CMAKE_REQUIRED_FLAGS
45-
"${CMAKE_REQUIRED_FLAGS} -O3 -fexpensive-optimizations"
45+
"${CMAKE_REQUIRED_FLAGS} -O3"
4646
)
4747

4848
IF(CMAKE_COMPILER_IS_GNUCC)
49-
CHECK_C_SOURCE_RUNS("${code}" HAVE_C_FLOATING_POINT_OPTIMIZATION_PROBLEMS)
49+
CHECK_C_SOURCE_RUNS("${code}" HAVE_C_FLOATING_POINT_FUSED_MADD)
5050
ENDIF()
5151

5252
IF(CMAKE_COMPILER_IS_GNUCXX)
53-
CHECK_CXX_SOURCE_RUNS("${code}" HAVE_CXX_FLOATING_POINT_OPTIMIZATION_PROBLEMS)
53+
CHECK_CXX_SOURCE_RUNS("${code}" HAVE_CXX_FLOATING_POINT_FUSED_MADD)
5454
ENDIF()
5555

5656
SET(CMAKE_REQUIRED_FLAGS "${SAVE_CMAKE_REQUIRED_FLAGS}")

mysql-test/suite/innodb_gis/t/1.test

-6
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,9 @@ insert into t1 values ('85984',ST_GeomFromText('MULTIPOLYGON(((-115.006363
371371
36.248666,-115.263639 36.247466,-115.263839 36.252766,-115.261439
372372
36.252666,-115.261439 36.247366,-115.247239 36.247066)))'));
373373

374-
# Expected result is 115.31877315203187, but IA64 returns 115.31877315203188
375-
# due to fused multiply-add instructions.
376-
--replace_result 115.31877315203188 115.31877315203187
377374
select object_id, ST_geometrytype(geo), ST_ISSIMPLE(GEO), ST_ASTEXT(ST_centroid(geo)) from
378375
t1 where object_id=85998;
379376

380-
# Expected result is 36.3310176346905, but IA64 returns 36.3310176346904
381-
# due to fused multiply-add instructions.
382-
--replace_result 36.3310176346904 36.3310176346905 -114.87787186923326 -114.87787186923313 36.33101763469053 36.33101763469059 36.33101763469043 36.33101763469059
383377
select object_id, ST_geometrytype(geo), ST_ISSIMPLE(GEO), ST_ASTEXT(ST_centroid(geo)) from
384378
t1 where object_id=85984;
385379

mysql-test/suite/innodb_gis/t/gis.test

-6
Original file line numberDiff line numberDiff line change
@@ -365,15 +365,9 @@ insert into t1 values ('85984',ST_GeomFromText('MULTIPOLYGON(((-115.006363
365365
36.248666,-115.263639 36.247466,-115.263839 36.252766,-115.261439
366366
36.252666,-115.261439 36.247366,-115.247239 36.247066)))'));
367367

368-
# Expected result is 115.31877315203187, but IA64 returns 115.31877315203188
369-
# due to fused multiply-add instructions.
370-
--replace_result 115.31877315203188 115.31877315203187
371368
select object_id, ST_geometrytype(geo), ST_ISSIMPLE(GEO), ST_ASTEXT(ST_centroid(geo)) from
372369
t1 where object_id=85998;
373370

374-
# Expected result is 36.3310176346905, but IA64 returns 36.3310176346904
375-
# due to fused multiply-add instructions.
376-
--replace_result 36.3310176346904 36.3310176346905 -114.87787186923326 -114.87787186923313 36.33101763469053 36.33101763469059 36.33101763469043 36.33101763469059
377371
select object_id, ST_geometrytype(geo), ST_ISSIMPLE(GEO), ST_ASTEXT(ST_centroid(geo)) from
378372
t1 where object_id=85984;
379373

mysql-test/t/gis.test

-6
Original file line numberDiff line numberDiff line change
@@ -362,15 +362,9 @@ insert into t1 values ('85984',ST_GeomFromText('MULTIPOLYGON(((-115.006363
362362
36.248666,-115.263639 36.247466,-115.263839 36.252766,-115.261439
363363
36.252666,-115.261439 36.247366,-115.247239 36.247066)))'));
364364

365-
# Expected result is 115.31877315203187, but IA64 returns 115.31877315203188
366-
# due to fused multiply-add instructions.
367-
--replace_result 115.31877315203188 115.31877315203187
368365
select object_id, ST_geometrytype(geo), ST_ISSIMPLE(GEO), ST_ASTEXT(ST_centroid(geo)) from
369366
t1 where object_id=85998;
370367

371-
# Expected result is 36.3310176346905, but IA64 returns 36.3310176346904
372-
# due to fused multiply-add instructions.
373-
--replace_result 36.3310176346904 36.3310176346905 -114.87787186923326 -114.87787186923313 36.33101763469053 36.33101763469059 36.33101763469043 36.33101763469059
374368
select object_id, ST_geometrytype(geo), ST_ISSIMPLE(GEO), ST_ASTEXT(ST_centroid(geo)) from
375369
t1 where object_id=85984;
376370

0 commit comments

Comments
 (0)