[llvm] [InstCombine] Convert @log to @llvm.log if the input is known positive. (PR #111428)

David Green via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 8 07:01:34 PDT 2024


================
@@ -2589,10 +2584,26 @@ Value *LibCallSimplifier::optimizeLog(CallInst *Log, IRBuilderBase &B) {
       PowLb = LibFunc_powl;
       break;
     default:
-      return Ret;
+      return nullptr;
+    }
+
+    // Convert libcall to intrinsic if the value is known > 0.
+    bool IsKnownNoErrno = Log->hasNoNaNs() && Log->hasNoInfs();
+    if (!IsKnownNoErrno) {
+      SimplifyQuery SQ(DL, TLI, DT, AC, Log, true, true, DC);
+      KnownFPClass Known = computeKnownFPClass(
+          Log->getOperand(0), KnownFPClass::OrderedLessThanZeroMask,
+          /*Depth=*/0, SQ);
+      IsKnownNoErrno =
+          Known.isKnownNeverZero() && Known.cannotBeOrderedLessThanZero();
----------------
davemgreen wrote:

I had given denormals a test with log and in the routine I was using they had not been treated as zero (unlike fmod where they were). I've changed this over though.

https://github.com/llvm/llvm-project/pull/111428


More information about the llvm-commits mailing list