[llvm] 1d92b68 - DAG: Correct chain management for frexp libcalls
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 10 18:39:20 PDT 2023
Author: Matt Arsenault
Date: 2023-07-10T21:39:15-04:00
New Revision: 1d92b68ead0c57a8218c95acd39a2737016ea0ad
URL: https://github.com/llvm/llvm-project/commit/1d92b68ead0c57a8218c95acd39a2737016ea0ad
DIFF: https://github.com/llvm/llvm-project/commit/1d92b68ead0c57a8218c95acd39a2737016ea0ad.diff
LOG: DAG: Correct chain management for frexp libcalls
We need to replace the other uses of the call chain with the new load
chain.
Fixes not preserving the return def with unused x86_fp80
results. Regression reported here:
https://reviews.llvm.org/rGb15bf305ca3e9ce63aaef7247d32fb3a75174531#1224999
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
llvm/test/CodeGen/X86/llvm.frexp.f80.ll
llvm/test/CodeGen/X86/llvm.frexp.ll
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
index 7f57646f73fef4..dc92655cf00d1d 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
@@ -2123,16 +2123,18 @@ void SelectionDAGLegalize::ExpandFrexpLibCall(
RTLIB::Libcall LC = RTLIB::getFREXP(VT);
auto [Call, Chain] = ExpandLibCall(LC, Node, std::move(Args), false);
- Results.push_back(Call);
-
// FIXME: Get type of int for libcall declaration and cast
int FrameIdx = cast<FrameIndexSDNode>(StackSlot)->getIndex();
auto PtrInfo =
MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FrameIdx);
- SDValue LoadExp =
- DAG.getLoad(ExpVT, dl, Chain, StackSlot, PtrInfo);
+ SDValue LoadExp = DAG.getLoad(ExpVT, dl, Chain, StackSlot, PtrInfo);
+ SDValue OutputChain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other,
+ LoadExp.getValue(1), DAG.getRoot());
+ DAG.setRoot(OutputChain);
+
+ Results.push_back(Call);
Results.push_back(LoadExp);
}
diff --git a/llvm/test/CodeGen/X86/llvm.frexp.f80.ll b/llvm/test/CodeGen/X86/llvm.frexp.f80.ll
index c294823b29036b..92d8c53c8182e3 100644
--- a/llvm/test/CodeGen/X86/llvm.frexp.f80.ll
+++ b/llvm/test/CodeGen/X86/llvm.frexp.f80.ll
@@ -37,6 +37,25 @@ define x86_fp80 @test_frexp_f80_i32_only_use_fract(x86_fp80 %a) {
ret x86_fp80 %result.0
}
+define x86_fp80 @test_frexp_f80_i32_only_use_fract_math(x86_fp80 %a) {
+; X64-LABEL: test_frexp_f80_i32_only_use_fract_math:
+; X64: # %bb.0:
+; X64-NEXT: subq $24, %rsp
+; X64-NEXT: .cfi_def_cfa_offset 32
+; X64-NEXT: fldt {{[0-9]+}}(%rsp)
+; X64-NEXT: fstpt (%rsp)
+; X64-NEXT: leaq {{[0-9]+}}(%rsp), %rdi
+; X64-NEXT: callq frexpl at PLT
+; X64-NEXT: fadd %st, %st(0)
+; X64-NEXT: addq $24, %rsp
+; X64-NEXT: .cfi_def_cfa_offset 8
+; X64-NEXT: retq
+ %result = call { x86_fp80, i32 } @llvm.frexp.f80.i32(x86_fp80 %a)
+ %result.0 = extractvalue { x86_fp80, i32 } %result, 0
+ %add = fadd x86_fp80 %result.0,%result.0
+ ret x86_fp80 %add
+}
+
define i32 @test_frexp_f80_i32_only_use_exp(x86_fp80 %a) {
; X64-LABEL: test_frexp_f80_i32_only_use_exp:
; X64: # %bb.0:
@@ -46,6 +65,7 @@ define i32 @test_frexp_f80_i32_only_use_exp(x86_fp80 %a) {
; X64-NEXT: fstpt (%rsp)
; X64-NEXT: leaq {{[0-9]+}}(%rsp), %rdi
; X64-NEXT: callq frexpl at PLT
+; X64-NEXT: fstp %st(0)
; X64-NEXT: movl {{[0-9]+}}(%rsp), %eax
; X64-NEXT: addq $24, %rsp
; X64-NEXT: .cfi_def_cfa_offset 8
diff --git a/llvm/test/CodeGen/X86/llvm.frexp.ll b/llvm/test/CodeGen/X86/llvm.frexp.ll
index 46613f9b9048c4..bd0a1dce6946c6 100644
--- a/llvm/test/CodeGen/X86/llvm.frexp.ll
+++ b/llvm/test/CodeGen/X86/llvm.frexp.ll
@@ -875,6 +875,7 @@ define i32 @test_frexp_f64_i32_only_use_exp(double %a) {
; WIN32-NEXT: movl %eax, {{[0-9]+}}(%esp)
; WIN32-NEXT: fstpl (%esp)
; WIN32-NEXT: calll _frexp
+; WIN32-NEXT: fstp %st(0)
; WIN32-NEXT: movl {{[0-9]+}}(%esp), %eax
; WIN32-NEXT: addl $16, %esp
; WIN32-NEXT: retl
More information about the llvm-commits
mailing list