[all-commits] [llvm/llvm-project] 112aac: [InstCombine] Fold fmod to frem if we know it does...

David Green via All-commits all-commits at lists.llvm.org
Wed Sep 18 01:38:51 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 112aac4e8961b9626bb84f36deeaa5a674f03f5a
      https://github.com/llvm/llvm-project/commit/112aac4e8961b9626bb84f36deeaa5a674f03f5a
  Author: David Green <david.green at arm.com>
  Date:   2024-09-18 (Wed, 18 Sep 2024)

  Changed paths:
    M llvm/include/llvm/Transforms/Utils/SimplifyLibCalls.h
    M llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
    M llvm/test/Transforms/InstCombine/fmod.ll

  Log Message:
  -----------
  [InstCombine] Fold fmod to frem if we know it does not set errno. (#107912)

fmod will be folded to frem in clang under -fno-math-errno and can be constant
folded in llvm if the operands are known. It can be relatively common to have
fp code that handles special values before doing some calculation:
```
if (isnan(f))
  return handlenan;
if (isinf(f))
  return handleinf;
..
fmod(f, 2.0)
```

This patch enables the folding of fmod to frem in instcombine if the first
parameter is not inf and the second is not zero. Other combinations do not set
errno.

The same transform is performed for fmod with the nnan flag, which implies the
input is known to not be inf/zero.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list