[llvm] [SelectionDAG] powi and ldexp libcalls deal with signed int arguments (PR #213673)

Simonas Kazlauskas via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 3 06:36:14 PDT 2026


https://github.com/nagisa created https://github.com/llvm/llvm-project/pull/213673

While investigating a sign extension problem on an off-tree target that needs extension of 32-bit integer argument to 64-bit register when passed as an argument, I found that `__powisf2` was being passed zero-extended despite the argument being a signed `int`. I narrowed this down to the fact that `shouldSignExtendTypeInLibCall` was being passed `false` for `IsSigned` for the `int` argument in these libcalls.

Other libcalls (not an exhaustive review) such as the `XINT_TO_FP` family do set the `IsSigned` value here.

I would write an unit test, but I'm not familiar with any in-tree target that would help me expose this problem… None of the existing in-tree tests are otherwise affected to the best of my knowledge.

>From 263872fd5a98816f2456b2b8109aa4722a0543cc Mon Sep 17 00:00:00 2001
From: Simonas Kazlauskas <git at kazlauskas.me>
Date: Mon, 3 Aug 2026 16:20:17 +0300
Subject: [PATCH] [SelectionDAG] powi and ldexp libcalls deal with signed int
 arguments
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

While investigating a sign extension problem on an off-tree target that
needs extension of 32-bit integer argument to 64-bit register when
passed as an argument, I found that `__powisf2` was being passed
zero-extended despite the argument being a signed `int`. I narrowed this
down to the fact that `shouldSignExtendTypeInLibCall` was being passed
`false` for `IsSigned` for the `int` argument in these libcalls.

I would write an unit test, but I'm not familiar with any in-tree target
that would help me expose this problem… None of the existing in-tree
tests are otherwise affected.
---
 llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
index d0a29b5365daa..226da8ac24436 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
@@ -764,6 +764,7 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_ExpOp(SDNode *N) {
   EVT OpsVT[2] = { N->getOperand(0 + Offset).getValueType(),
                    N->getOperand(1 + Offset).getValueType() };
   CallOptions.setTypeListBeforeSoften(OpsVT, N->getValueType(0));
+  CallOptions.setIsSigned();
   std::pair<SDValue, SDValue> Tmp = TLI.makeLibCall(DAG, LC, NVT, Ops,
                                                     CallOptions, SDLoc(N),
                                                     Chain);



More information about the llvm-commits mailing list