This is an archive of the discontinued LLVM Phabricator instance.

[InstSimplify] fix/improve folding with an SNaN operand
ClosedPublic

Authored by spatel on Feb 7 2023, 8:27 AM.

Details

Summary

There are 2 issues here:

  1. In the default LLVM FP environment (regular FP math instructions), SNaN is some flavor of "don't care" which we will nail down in D143074, so this is just a quality-of-implementation improvement for default FP.
  2. In the constrained FP environment (constrained intrinsics), SNaN must not propagate through a math operation; it has to be quieted according to IEEE-754 spec. That is independent of exception handling mode, so the current behavior is a miscompile.

Diff Detail

Event Timeline

spatel created this revision.Feb 7 2023, 8:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 7 2023, 8:27 AM
spatel requested review of this revision.Feb 7 2023, 8:27 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 7 2023, 8:27 AM
arsenm added inline comments.Feb 7 2023, 9:02 AM
llvm/lib/Analysis/InstructionSimplify.cpp
5337

Probably should add / expose a makeQuiet if this is going to spread more places

spatel marked an inline comment as done.Feb 7 2023, 10:16 AM
spatel added inline comments.
llvm/lib/Analysis/InstructionSimplify.cpp
5337

Yes, that was just laziness - will update.

spatel updated this revision to Diff 495589.Feb 7 2023, 10:18 AM
spatel marked an inline comment as done.

Patch updated:
Added a "makeQuiet" wrapper to APFloat. If that part + AMDGPU diff looks ok, I can make it a pre-commit. It doesn't change any functionality for this patch.

spatel edited the summary of this revision. (Show Details)Feb 14 2023, 7:00 AM

Ping.

AFAIK, there is no opposition to the view that the current behavior is a miscompile for strict FP. This is independent of any documentation/behavioral changes for default FP that may result from D143074.

jyknight added inline comments.Feb 14 2023, 9:46 AM
llvm/lib/Analysis/InstructionSimplify.cpp
5320

Why is this a TODO? Is it more complex than just another call to makeQuiet?

spatel added inline comments.Feb 14 2023, 10:56 AM
llvm/lib/Analysis/InstructionSimplify.cpp
5320

I don't think so. It was just to have a minimal patch as a first step (the APFloat change wasn't in this patch in the first draft either).

I can add vector tests and make that a follow-up patch, or I can squash it all together if that's preferred.

jyknight accepted this revision.Feb 14 2023, 11:02 AM
jyknight added inline comments.
llvm/lib/Analysis/InstructionSimplify.cpp
5320

If you're sending a follow-up to fix this, too, then SGTM.

This revision is now accepted and ready to land.Feb 14 2023, 11:02 AM
This revision was landed with ongoing or failed builds.Feb 14 2023, 2:51 PM
This revision was automatically updated to reflect the committed changes.