[llvm] [SDAG] Honor signed arguments in floating point libcalls (PR #109134)
Timothy Pearson via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 18 06:00:36 PDT 2024
https://github.com/tpearson-ssc created https://github.com/llvm/llvm-project/pull/109134
In ExpandFPLibCall, an assumption is made that all floating point libcalls that take integer arguments use unsigned integers. In the case of ldexp and frexp, this assumption is incorrect, leading to miscompilation and subsequent target-dependent incorrect operation.
Indicate that ldexp and frexp utilize signed arguments in ExpandFPLibCall.
Fixes #108904
>From 18777f4f967a71e87e6f777449566adc76f9fed8 Mon Sep 17 00:00:00 2001
From: Timothy Pearson <tpearson at solidsilicon.com>
Date: Wed, 18 Sep 2024 07:49:58 -0500
Subject: [PATCH] [SDAG] Honor signed arguments in floating point libcalls
In ExpandFPLibCall, an assumption is made that all floating point libcalls
that take integer arguments use unsigned integers. In the case of ldexp
and frexp, this assumption is incorrect, leading to miscompilation and
subsequent target-dependent incorrect operation.
Indicate that ldexp and frexp utilize signed arguments in ExpandFPLibCall.
Fixes #108904
Signed-off-by: Timothy Pearson <tpearson at solidsilicon.com>
---
llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp | 21 ++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
index f5fbc01cd95e96..b6c1b340909cf7 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -2205,7 +2205,26 @@ void SelectionDAGLegalize::ExpandFPLibCall(SDNode* Node,
Results.push_back(Tmp.first);
Results.push_back(Tmp.second);
} else {
- SDValue Tmp = ExpandLibCall(LC, Node, false).first;
+ bool isSignedArgument;
+ switch (LC) {
+ case RTLIB::LDEXP_F32:
+ case RTLIB::LDEXP_F64:
+ case RTLIB::LDEXP_F80:
+ case RTLIB::LDEXP_F128:
+ case RTLIB::LDEXP_PPCF128:
+ isSignedArgument = true;
+ break;
+ case RTLIB::FREXP_F32:
+ case RTLIB::FREXP_F64:
+ case RTLIB::FREXP_F80:
+ case RTLIB::FREXP_F128:
+ case RTLIB::FREXP_PPCF128:
+ isSignedArgument = true;
+ break;
+ default:
+ isSignedArgument = false;
+ }
+ SDValue Tmp = ExpandLibCall(LC, Node, isSignedArgument).first;
Results.push_back(Tmp);
}
}
More information about the llvm-commits
mailing list