[llvm] [DAGCombiner] Query nsz from function attribute and use `cannotBeOrderedNegativeFP` in `foldFPToIntToFP` (PR #186779)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Mar 22 19:05:16 PDT 2026
https://github.com/paperchalice updated https://github.com/llvm/llvm-project/pull/186779
>From ecd7dcff1811bc9451689f6a428c4bd6174fbc7f Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Mon, 23 Mar 2026 10:04:42 +0800
Subject: [PATCH] use cannotBeOrderedNegativeFP only
---
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 5 +++--
llvm/test/CodeGen/AArch64/fp-to-int-to-fp.ll | 12 ++++++++++++
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index 781001d050f3d..a21cda6ade215 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -19460,8 +19460,9 @@ static SDValue foldFPToIntToFP(SDNode *N, const SDLoc &DL, SelectionDAG &DAG,
bool IsSigned = N->getOpcode() == ISD::SINT_TO_FP;
assert(IsSigned || IsUnsigned);
- bool IsSignedZeroSafe = DAG.getTarget().Options.NoSignedZerosFPMath ||
- DAG.canIgnoreSignBitOfZero(SDValue(N, 0));
+ bool IsSignedZeroSafe =
+ DAG.cannotBeOrderedNegativeFP(N->getOperand(0)->getOperand(0)) ||
+ DAG.canIgnoreSignBitOfZero(SDValue(N, 0));
// For signed conversions: The optimization changes signed zero behavior.
if (IsSigned && !IsSignedZeroSafe)
return SDValue();
diff --git a/llvm/test/CodeGen/AArch64/fp-to-int-to-fp.ll b/llvm/test/CodeGen/AArch64/fp-to-int-to-fp.ll
index a50716e4ab183..0ee7d09e8f998 100644
--- a/llvm/test/CodeGen/AArch64/fp-to-int-to-fp.ll
+++ b/llvm/test/CodeGen/AArch64/fp-to-int-to-fp.ll
@@ -275,6 +275,18 @@ define float @test_fabs(float %x) {
ret float %abs
}
+define float @test_fabs_nneg(float %x) {
+; CHECK-LABEL: test_fabs_nneg:
+; CHECK: // %bb.0:
+; CHECK-NEXT: fabs s0, s0
+; CHECK-NEXT: frintz s0, s0
+; CHECK-NEXT: ret
+ %nneg = call float @llvm.fabs(float %x)
+ %conv1 = fptosi float %nneg to i32
+ %conv2 = sitofp i32 %conv1 to float
+ ret float %conv2
+}
+
define float @test_copysign(float %x, float %y) {
; CHECK-LABEL: test_copysign:
; CHECK: // %bb.0:
More information about the llvm-commits
mailing list