[llvm-dev] Floating point ordered and unordered comparisons

朴素 via llvm-dev llvm-dev at lists.llvm.org
Mon Jan 4 04:38:31 PST 2021


Hi All,


I have some questions about Floating point ordered and unordered comparisons,
I did some searching and found link below
http://lists.llvm.org/pipermail/llvm-dev/2013-July/063571.html


But I still don't quite understand Floating point ordered and unordered
comparisons. For example, the following code
```
bool cmp1(float a) {
  if (a > 0.0)
   return true;
  else
   return false;
}


bool cmp2(float a) {
  if (!(a <= 0.0))
   return true;
  else
   return false;
}
```
The generated ir code is similar to the following:
```
define zeroext i1 @_Z4cmp1f(float %a) {
entry:
  %cmp = fcmp ogt float %a, 0.000000e+00
  ret i1 %cmp
}


define zeroext i1 @_Z4cmp2f(float %a) {
entry:
  %cmp = fcmp ugt float %a, 0.000000e+00
  ret i1 %cmp
}
```
If the parameter passed is NaN in this example, the result of cmp1 is false and
the result of cmp2 is true. In this case, the result is completely opposite. 
When will we get 'fcmp ugt' and when will we get 'fcmp ugt' ? When comparing
ordered and unorder can be converted ? Such as converting an ordered less than
"setolt" into unordered greater than "setuge" operation. 


Thanks in advance,
Lijia He
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20210104/573e028d/attachment.html>


More information about the llvm-dev mailing list