[llvm] [SDAG] Honor signed arguments in floating point libcalls (PR #109134)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 18 06:02:33 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-selectiondag
Author: Timothy Pearson (tpearson-ssc)
<details>
<summary>Changes</summary>
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
---
Full diff: https://github.com/llvm/llvm-project/pull/109134.diff
1 Files Affected:
- (modified) llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp (+20-1)
``````````diff
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);
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/109134
More information about the llvm-commits
mailing list