[llvm] [InstCombine] Fold fmod to frem if we know it does not set errno. (PR #107912)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 11 03:38:04 PDT 2024
================
@@ -2796,6 +2796,25 @@ Value *LibCallSimplifier::optimizeSqrt(CallInst *CI, IRBuilderBase &B) {
return copyFlags(*CI, FabsCall);
}
+Value *LibCallSimplifier::optimizeFMod(CallInst *CI, IRBuilderBase &B) {
+ SimplifyQuery SQ(DL, TLI, DT, AC, CI, true, true, DC);
+
+ // fmod(x,y) can set errno if y == 0 or x == +/-inf.
+ KnownFPClass Known0 = computeKnownFPClass(CI->getOperand(0), fcInf,
+ /*Depth=*/0, SQ);
+ if (Known0.isKnownNeverInfinity()) {
+ KnownFPClass Known1 = computeKnownFPClass(CI->getOperand(1), fcZero,
+ /*Depth=*/0, SQ);
+ if (Known1.isKnownNeverZero()) {
----------------
arsenm wrote:
This is wrong if DAZ is enabled, this needs to account of the denormal mode. Can you add a negative test with "denormal-fp-math"="preserve-sign,preserve-sign" and/or ="dynamic,dynamic"? This should be checking isKnownNeverLogicalZero
https://github.com/llvm/llvm-project/pull/107912
More information about the llvm-commits
mailing list