[PATCH] D139785: [InstCombine] preserve signbit semantics of NAN with fold to fabs

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 11 07:13:30 PST 2022


spatel created this revision.
spatel added reviewers: nlopes, jyknight, jcranmer, arsenm, RalfJung.
Herald added subscribers: hiraditya, mcrosier.
Herald added a project: All.
spatel requested review of this revision.
Herald added subscribers: llvm-commits, wdng.
Herald added a project: LLVM.

As discussed in (issue #59279)[https://github.com/llvm/llvm-project/issues/59279], we want fneg/fabs to conform to the IEEE-754 spec for signbit operations. Those functions produce a deterministic signbit even for NAN values where the signbit is meaningless, so we gate this transform with "nnan" in addition to "nsz":
(X > 0.0) ? X : -X --> fabs(X)

The code change is a one-liner, but we have lots of tests diffs because there are many variations of the basic pattern.


https://reviews.llvm.org/D139785

Files:
  llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
  llvm/test/Transforms/InstCombine/fabs.ll
  llvm/test/Transforms/InstCombine/fneg-fabs.ll
  llvm/test/Transforms/InstCombine/fneg.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139785.481907.patch
Type: text/x-patch
Size: 9738 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221211/1cd00910/attachment.bin>


More information about the llvm-commits mailing list