[clang] [clang][bytecode] Avoid a getValue() call in builtin_isinf (PR #152939)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 10 12:56:01 PDT 2025


https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/152939

Get the APFloat once and work with that, instead of calling isInf() and potentially isNegative().

>From a9644453abe231e3b5485957ea26aeb75de9ef3a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Sun, 10 Aug 2025 21:54:30 +0200
Subject: [PATCH] [clang][bytecode] Avoid a getValue() call in builtin_isinf

Get the APFloat once and work with that, instead of calling isInf() and
potentially isNegative().
---
 clang/lib/AST/ByteCode/InterpBuiltin.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
index 14f6929037ff5..ad923a52a4ce1 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp
@@ -459,12 +459,13 @@ static bool interp__builtin_isinf(InterpState &S, CodePtr OpPC,
                                   const InterpFrame *Frame, bool CheckSign,
                                   const CallExpr *Call) {
   const Floating &Arg = S.Stk.pop<Floating>();
-  bool IsInf = Arg.isInf();
+  APFloat F = Arg.getAPFloat();
+  bool IsInf = F.isInfinity();
 
   if (CheckSign)
-    pushInteger(S, IsInf ? (Arg.isNegative() ? -1 : 1) : 0, Call->getType());
+    pushInteger(S, IsInf ? (F.isNegative() ? -1 : 1) : 0, Call->getType());
   else
-    pushInteger(S, Arg.isInf(), Call->getType());
+    pushInteger(S, IsInf, Call->getType());
   return true;
 }
 



More information about the cfe-commits mailing list