[LLVMdev] Why can't comparisons with negative zero be simplified?
Robison, Arch
arch.robison at intel.com
Mon Jul 6 14:13:49 PDT 2015
In InstCombineCompares.cpp, routine InstCombiner::FoldFCmp_IntToFP_Cst, there are these lines:
// Comparisons with zero are a special case where we know we won't lose
// information.
bool IsCmpZero = RHS.isPosZero();
// If the conversion would lose info, don't hack on this.
if ((int)InputSize > MantissaWidth && !IsCmpZero)
return nullptr;
Why check for positive zero instead of checking for any kind of zero? My reading of IEEE 754-2008 is that floating-point comparison operations cannot distinguish a negative zero from a positive zero. Further supporting this is that fact that http://llvm.org/docs/LangRef.html describes the difference between "ordered" and "unordered" as pertaining to QNAN operands,
with no mention of negative zero.
I tried fixing the issue, but then the following test in cast-int-fcmp-eq-0.ll fails:
; CHECK-LABEL: @i32_cast_cmp_oeq_int_n0_uitofp(
; CHECK: uitofp
; CHECK: fcmp oeq
define i1 @i32_cast_cmp_oeq_int_n0_uitofp(i32 %i) {
%f = uitofp i32 %i to float
%cmp = fcmp oeq float %f, -0.0
ret i1 %cmp
}
Is this test really justified, or is it just reinforcing an oversight?
- Arch D. Robison
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150706/d575d72e/attachment.html>
More information about the llvm-dev
mailing list