[llvm] [Support] Use "if constexpr" in shouldReverseIterate (PR #156812)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 3 23:27:24 PDT 2025


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/156812

This patch simplifies shouldReverseIterate with "if constexpr" while
switching to "constexpr bool", allowing compile-time evaluation at
call sites.


>From 3985d8f4428d5b7bd372f111174b15ca9c084156 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 3 Sep 2025 10:54:26 -0700
Subject: [PATCH] [Support] Use "if constexpr" in shouldReverseIterate

This patch simplifies shouldReverseIterate with "if constexpr" while
switching to "constexpr bool", allowing compile-time evaluation at
call sites.
---
 llvm/include/llvm/Support/ReverseIteration.h | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/llvm/include/llvm/Support/ReverseIteration.h b/llvm/include/llvm/Support/ReverseIteration.h
index 9e9411856369e..456d423600d6e 100644
--- a/llvm/include/llvm/Support/ReverseIteration.h
+++ b/llvm/include/llvm/Support/ReverseIteration.h
@@ -6,13 +6,11 @@
 
 namespace llvm {
 
-template<class T = void *>
-bool shouldReverseIterate() {
-#if LLVM_ENABLE_REVERSE_ITERATION
-  return detail::IsPointerLike<T>::value;
-#else
-  return false;
-#endif
+template <class T = void *> constexpr bool shouldReverseIterate() {
+  if constexpr (LLVM_ENABLE_REVERSE_ITERATION)
+    return detail::IsPointerLike<T>::value;
+  else
+    return false;
 }
 
 } // namespace llvm



More information about the llvm-commits mailing list