Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

This patch uses std::clamp to simplify manual clamping in
getHeatColor.

This patch uses std::clamp to simplify manual clamping in
getHeatColor.
@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label Oct 28, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 28, 2025

@llvm/pr-subscribers-llvm-analysis

Author: Kazu Hirata (kazutakahirata)

Changes

This patch uses std::clamp to simplify manual clamping in
getHeatColor.


Full diff: https://github.com/llvm/llvm-project/pull/165394.diff

1 Files Affected:

  • (modified) llvm/lib/Analysis/HeatUtils.cpp (+1-4)
diff --git a/llvm/lib/Analysis/HeatUtils.cpp b/llvm/lib/Analysis/HeatUtils.cpp
index a1cc7071f0e22..08e9428059e7e 100644
--- a/llvm/lib/Analysis/HeatUtils.cpp
+++ b/llvm/lib/Analysis/HeatUtils.cpp
@@ -64,10 +64,7 @@ std::string llvm::getHeatColor(uint64_t Freq, uint64_t MaxFreq) {
 }
 
 std::string llvm::getHeatColor(double Percent) {
-  if (Percent > 1.0)
-    Percent = 1.0;
-  if (Percent < 0.0)
-    Percent = 0.0;
+  Percent = std::clamp(Percent, 0.0, 1.0);
   unsigned ColorID = unsigned(round(Percent * (HeatSize - 1.0)));
   return HeatPalette[ColorID];
 }

@kazutakahirata kazutakahirata merged commit b2b2c52 into llvm:main Oct 28, 2025
12 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20251027_Analysis_std_clamp branch October 28, 2025 23:16
aokblast pushed a commit to aokblast/llvm-project that referenced this pull request Oct 30, 2025
This patch uses std::clamp to simplify manual clamping in
getHeatColor.
DEBADRIBASAK pushed a commit to DEBADRIBASAK/llvm-project that referenced this pull request Nov 3, 2025
This patch uses std::clamp to simplify manual clamping in
getHeatColor.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:analysis Includes value tracking, cost tables and constant folding

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants