[PATCH] D142907: LangRef: Add "dynamic" option to "denormal-fp-math"

Matt Arsenault via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 30 09:16:07 PST 2023


arsenm created this revision.
arsenm added reviewers: scanon, spatel, cameron.mcinally, andrew.w.kaylor, tra, jlebar, Anastasia, yaxunl, efriedma, jcranmer-intel, kpn, sepavloff.
Herald added subscribers: kosarev, foad, StephenFan, wenlei, jdoerfert, kerbowa, pengfei, hiraditya, jvesely.
Herald added a project: All.
arsenm requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

This is stricter than the default "ieee", and should probably be the
default. This patch leaves the default alone. I can change this in a
future patch.

      

There are non-reversible transforms I would like to perform which are
legal under IEEE denormal handling, but illegal with flushing zero
behavior. Namely, conversions between llvm.is.fpclass and fcmp with
zeroes.

      

Under "ieee" handling, it is legal to translate between
llvm.is.fpclass(x, fcZero) and fcmp x, 0.

      

Under "preserve-sign" handling, it is legal to translate between
llvm.is.fpclass(x, fcSubnormal|fcZero) and fcmp x, 0.

      

I would like to compile and distribute some math library functions in
a mode where it's callable from code with and without denormals
enabled, which requires not changing the compares with denormals or
zeroes.

      

If an IEEE function transforms an llvm.is.fpclass call into an fcmp 0,
it is no longer possible to call the function from code with denormals
enabled, or write an optimization to move the function into a denormal
flushing mode. For the original function, if x was a denormal, the
class would evaluate to false. If the function compiled with denormal
handling was converted to or called from a preserve-sign function, the
fcmp now evaluates to true.

      

This could also be of use for strictfp handling, where code may be
changing the denormal mode.

      

Alternative name could be "unknown".


https://reviews.llvm.org/D142907

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/lib/CodeGen/CodeGenModule.h
  clang/test/CodeGen/denormalfpmode-f32.c
  clang/test/CodeGen/denormalfpmode.c
  clang/test/CodeGenCUDA/Inputs/ocml-sample.cl
  clang/test/CodeGenCUDA/link-builtin-bitcode-denormal-fp-mode.cu
  clang/test/Driver/denormal-fp-math.c
  llvm/docs/LangRef.rst
  llvm/include/llvm/ADT/FloatingPointMode.h
  llvm/include/llvm/IR/Attributes.td
  llvm/include/llvm/IR/Function.h
  llvm/lib/Analysis/ConstantFolding.cpp
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
  llvm/lib/IR/Attributes.cpp
  llvm/lib/IR/Function.cpp
  llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.h
  llvm/test/CodeGen/Generic/denormal-fp-math-cl-opt.ll
  llvm/test/CodeGen/X86/sqrt-fastmath.ll
  llvm/test/Transforms/Inline/AMDGPU/inline-denormal-fp-math.ll
  llvm/test/Transforms/InstSimplify/canonicalize.ll
  llvm/test/Transforms/InstSimplify/constant-fold-fp-denormal.ll
  llvm/unittests/ADT/FloatingPointMode.cpp
  llvm/utils/TableGen/Attributes.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142907.493333.patch
Type: text/x-patch
Size: 79815 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230130/d01aa7ae/attachment-0001.bin>


More information about the cfe-commits mailing list