From 3985d8f4428d5b7bd372f111174b15ca9c084156 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Wed, 3 Sep 2025 10:54:26 -0700 Subject: [PATCH 1/2] [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 -bool shouldReverseIterate() { -#if LLVM_ENABLE_REVERSE_ITERATION - return detail::IsPointerLike::value; -#else - return false; -#endif +template constexpr bool shouldReverseIterate() { + if constexpr (LLVM_ENABLE_REVERSE_ITERATION) + return detail::IsPointerLike::value; + else + return false; } } // namespace llvm From 41a94f2ecbaebffc16fab7e98549e3b26eeb4676 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Thu, 4 Sep 2025 09:09:18 -0700 Subject: [PATCH 2/2] Address a comment. --- llvm/include/llvm/Support/ReverseIteration.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/Support/ReverseIteration.h b/llvm/include/llvm/Support/ReverseIteration.h index 456d423600d6e..1a42ff3368dcb 100644 --- a/llvm/include/llvm/Support/ReverseIteration.h +++ b/llvm/include/llvm/Support/ReverseIteration.h @@ -7,10 +7,11 @@ namespace llvm { template constexpr bool shouldReverseIterate() { - if constexpr (LLVM_ENABLE_REVERSE_ITERATION) - return detail::IsPointerLike::value; - else - return false; +#if LLVM_ENABLE_REVERSE_ITERATION + return detail::IsPointerLike::value; +#else + return false; +#endif } } // namespace llvm