[PATCH] D41136: [EarlyCSE] recognize commuted and swapped variants of min/max as equivalent (PR35642)

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 14 12:49:15 PST 2017


spatel added a comment.

In https://reviews.llvm.org/D41136#955627, @hfinkel wrote:

>   // If the predicate is an "or-equal"  (FP) predicate, then signed zeroes may
>   // return inconsistent results between implementations.
>   //   (0.0 <= -0.0) ? 0.0 : -0.0 // Returns 0.0
>   //   minNum(0.0, -0.0)          // May return -0.0 or 0.0 (IEEE 754-2008 5.3.1)
>   // Therefore we behave conservatively and only proceed if at least one of the
>   // operands is known to not be zero, or if we don't care about signed zeroes.
>   switch (Pred) {
>   default: break;
>   case CmpInst::FCMP_OGE: case CmpInst::FCMP_OLE:
>   case CmpInst::FCMP_UGE: case CmpInst::FCMP_ULE:
>     if (!FMF.noSignedZeros() && !isKnownNonZero(CmpLHS) &&
>         !isKnownNonZero(CmpRHS))
>       return {SPF_UNKNOWN, SPNB_NA, false};
>   }
>   
>
> It seems like there are cases missing here (e.g., this does not apply only to the GE/LE predicates)? Based on your example, it seems like we have the same problem with the GT/LT predicates.


Yep - that's the quick fix; add the other preds. A better solution might be to distinguish signed zero behavior in the same way that we're doing for NAN. But let me try the easy patch first and see if anything breaks. :)


Repository:
  rL LLVM

https://reviews.llvm.org/D41136





More information about the llvm-commits mailing list