mirror of
https://github.com/intel/llvm.git
synced 2026-01-24 17:01:00 +08:00
[Analysis] Ensure use of strict fp exceptions in ConstantFolding (#136139)
To perform constant folding in math operations, the implementation of the ConstantFolding Analysis relies on the use of the math functions from the host's libm. In particular, it relies on checking the value of errno and IEEE exceptions to determine when an operation is safe to be constant-folded. On some platforms, such as BSD or Darwin, math library functions don't set errno, so the ConstantFolding check depends only on the value of IEEE exceptions. As the FP exception behaviour is set to `ignore` by default, the compiler can perform optimisations that would get in the way of such checks being performed correctly. This patch sets the FP exception behaviour to `strict` when compiling the `ConstantFolding.cpp` source file, ensuring the value of IEEE exceptions can be reliably used by its implementation.
This commit is contained in:
committed by
GitHub
parent
1f69d6354a
commit
8506980d30
@@ -23,6 +23,17 @@ if (DEFINED LLVM_HAVE_TF_AOT OR LLVM_HAVE_TFLITE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# The implementation of ConstantFolding.cpp relies on the use of math functions
|
||||
# from the host. In particular, it relies on the detection of floating point
|
||||
# exceptions originating from such math functions to prevent invalid cases
|
||||
# from being constant folded. Therefore, we must ensure that fp exceptions are
|
||||
# handled correctly.
|
||||
if (MSVC)
|
||||
set_source_files_properties(ConstantFolding.cpp PROPERTIES COMPILE_OPTIONS "/fp:except")
|
||||
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
||||
set_source_files_properties(ConstantFolding.cpp PROPERTIES COMPILE_OPTIONS "-ffp-exception-behavior=strict")
|
||||
endif()
|
||||
|
||||
add_llvm_component_library(LLVMAnalysis
|
||||
AliasAnalysis.cpp
|
||||
AliasAnalysisEvaluator.cpp
|
||||
|
||||
Reference in New Issue
Block a user