From: Sangeetha Elumalai <sangeetha.elumalai@timesys.com>
Date: Tue, 14 Oct 2025 10:06:43 +0530

diff --git a/lib/Transforms/Utils/SimplifyLibCalls.cpp b/lib/Transforms/Utils/SimplifyLibCalls.cpp
index d3a80d12f..3ec6bff82 100644
--- a/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -2198,9 +2198,18 @@ Value *LibCallSimplifier::replacePowWithExp(CallInst *Pow, IRBuilderBase &B) {
 
     Value *Log = nullptr;
     if (Ty->isFloatTy())
+#ifdef _GLIBCXX_USE_C99_MATH_TR1
       Log = ConstantFP::get(Ty, std::log2(BaseF->convertToFloat()));
+#else
+      Log = ConstantFP::get(Ty, log2(BaseF->convertToFloat()));
+#endif
+
     else if (Ty->isDoubleTy())
+#ifdef _GLIBCXX_USE_C99_MATH_TR1
       Log = ConstantFP::get(Ty, std::log2(BaseF->convertToDouble()));
+#else
+      Log = ConstantFP::get(Ty, log2(BaseF->convertToDouble()));
+#endif
 
     if (Log) {
       Value *FMul = B.CreateFMul(Log, Expo, "mul");
diff --git a/tools/llvm-exegesis/lib/SchedClassResolution.cpp b/tools/llvm-exegesis/lib/SchedClassResolution.cpp
index 0690c2122..6b6169180 100644
--- a/tools/llvm-exegesis/lib/SchedClassResolution.cpp
+++ b/tools/llvm-exegesis/lib/SchedClassResolution.cpp
@@ -105,9 +105,15 @@ getNonRedundantWriteProcRes(const MCSchedClassDesc &SCDesc,
         continue;
       }
       // The ProcResGroup contributes `RemainingCycles` cycles of its own.
+#ifdef _GLIBCXX_USE_C99_MATH_TR1
       Result.push_back({WPR->ProcResourceIdx,
                         static_cast<uint16_t>(std::round(RemainingCycles)),
                         WPR->AcquireAtCycle});
+#else
+      Result.push_back({WPR->ProcResourceIdx,
+                        static_cast<uint16_t>(round(RemainingCycles)),
+                        WPR->AcquireAtCycle});
+#endif
       // Spread the remaining cycles over all subunits.
       for (const auto *SubResIdx = ProcResDesc->SubUnitsIdxBegin;
            SubResIdx != ProcResDesc->SubUnitsIdxBegin + ProcResDesc->NumUnits;
diff --git a/lib/Support/BalancedPartitioning.cpp b/lib/Support/BalancedPartitioning.cpp
index 19977c57c..7ed788ca1 100644
--- a/lib/Support/BalancedPartitioning.cpp
+++ b/lib/Support/BalancedPartitioning.cpp
@@ -73,7 +73,11 @@ BalancedPartitioning::BalancedPartitioning(
   // Pre-computing log2 values
   Log2Cache[0] = 0.0;
   for (unsigned I = 1; I < LOG_CACHE_SIZE; I++)
+#ifdef _GLIBCXX_USE_C99_MATH_TR1
     Log2Cache[I] = std::log2(I);
+#else
+    Log2Cache[I] = log2(I);
+#endif
 }
 
 void BalancedPartitioning::run(std::vector<BPFunctionNode> &Nodes) const {
@@ -330,5 +334,9 @@ float BalancedPartitioning::logCost(unsigned X, unsigned Y) const {
 }
 
 float BalancedPartitioning::log2Cached(unsigned i) const {
+#ifdef _GLIBCXX_USE_C99_MATH_TR1
   return (i < LOG_CACHE_SIZE) ? Log2Cache[i] : std::log2(i);
+#else
+  return (i < LOG_CACHE_SIZE) ? Log2Cache[i] : log2(i);
+#endif
 }
