-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[RISCV] Skip DAG combine for bitcast fabs/fneg #115325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Disable the DAG combine for bitcast fabs/fneg in case of the zdinx extension. The combine folds the fabs/fneg nodes in some cases. This might result in suboptimal code if compiled with the zdinx extension. In case of the zdinx extension, there is no need to load the double value from an x register to an f register, so the combine can be skipped.
|
@llvm/pr-subscribers-backend-risc-v Author: Gergely Futo (futog) ChangesDisable the DAG combine for bitcast fabs/fneg in case of the zdinx extension. The combine folds the fabs/fneg nodes in some cases. This might result in suboptimal code if compiled with the zdinx extension. In case of the zdinx extension, there is no need to load the double value from an x register to an f register, so the combine can be skipped. Full diff: https://github.com/llvm/llvm-project/pull/115325.diff 4 Files Affected:
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 5600524b69a620..5e824fde78e859 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -17075,7 +17075,7 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
// fold (bitconvert (fneg x)) -> (xor (bitconvert x), signbit)
// fold (bitconvert (fabs x)) -> (and (bitconvert x), (not signbit))
if (!(Op0.getOpcode() == ISD::FNEG || Op0.getOpcode() == ISD::FABS) ||
- !Op0.getNode()->hasOneUse())
+ !Op0.getNode()->hasOneUse() || Subtarget.hasStdExtZdinx())
break;
SDValue NewSplitF64 =
DAG.getNode(RISCVISD::SplitF64, DL, DAG.getVTList(MVT::i32, MVT::i32),
diff --git a/llvm/test/CodeGen/RISCV/double-arith.ll b/llvm/test/CodeGen/RISCV/double-arith.ll
index fa74dcb4810060..5f06398daa8b9a 100644
--- a/llvm/test/CodeGen/RISCV/double-arith.ll
+++ b/llvm/test/CodeGen/RISCV/double-arith.ll
@@ -844,8 +844,7 @@ define double @fnmadd_d_3(double %a, double %b, double %c) nounwind {
; RV32IZFINXZDINX-LABEL: fnmadd_d_3:
; RV32IZFINXZDINX: # %bb.0:
; RV32IZFINXZDINX-NEXT: fmadd.d a0, a0, a2, a4
-; RV32IZFINXZDINX-NEXT: lui a2, 524288
-; RV32IZFINXZDINX-NEXT: xor a1, a1, a2
+; RV32IZFINXZDINX-NEXT: fneg.d a0, a0
; RV32IZFINXZDINX-NEXT: ret
;
; RV64IZFINXZDINX-LABEL: fnmadd_d_3:
@@ -890,9 +889,7 @@ define double @fnmadd_nsz(double %a, double %b, double %c) nounwind {
;
; RV32IZFINXZDINX-LABEL: fnmadd_nsz:
; RV32IZFINXZDINX: # %bb.0:
-; RV32IZFINXZDINX-NEXT: fmadd.d a0, a0, a2, a4
-; RV32IZFINXZDINX-NEXT: lui a2, 524288
-; RV32IZFINXZDINX-NEXT: xor a1, a1, a2
+; RV32IZFINXZDINX-NEXT: fnmadd.d a0, a0, a2, a4
; RV32IZFINXZDINX-NEXT: ret
;
; RV64IZFINXZDINX-LABEL: fnmadd_nsz:
diff --git a/llvm/test/CodeGen/RISCV/double-bitmanip-dagcombines.ll b/llvm/test/CodeGen/RISCV/double-bitmanip-dagcombines.ll
index f7d57178b03d41..01aa25c15c8d2b 100644
--- a/llvm/test/CodeGen/RISCV/double-bitmanip-dagcombines.ll
+++ b/llvm/test/CodeGen/RISCV/double-bitmanip-dagcombines.ll
@@ -36,8 +36,7 @@ define double @fneg(double %a) nounwind {
;
; RV32IZFINXZDINX-LABEL: fneg:
; RV32IZFINXZDINX: # %bb.0:
-; RV32IZFINXZDINX-NEXT: lui a2, 524288
-; RV32IZFINXZDINX-NEXT: xor a1, a1, a2
+; RV32IZFINXZDINX-NEXT: fneg.d a0, a0
; RV32IZFINXZDINX-NEXT: ret
;
; RV64I-LABEL: fneg:
@@ -79,8 +78,7 @@ define double @fabs(double %a) nounwind {
;
; RV32IZFINXZDINX-LABEL: fabs:
; RV32IZFINXZDINX: # %bb.0:
-; RV32IZFINXZDINX-NEXT: slli a1, a1, 1
-; RV32IZFINXZDINX-NEXT: srli a1, a1, 1
+; RV32IZFINXZDINX-NEXT: fabs.d a0, a0
; RV32IZFINXZDINX-NEXT: ret
;
; RV64I-LABEL: fabs:
diff --git a/llvm/test/CodeGen/RISCV/double-intrinsics.ll b/llvm/test/CodeGen/RISCV/double-intrinsics.ll
index bf21ee6696a282..a65fd09613424c 100644
--- a/llvm/test/CodeGen/RISCV/double-intrinsics.ll
+++ b/llvm/test/CodeGen/RISCV/double-intrinsics.ll
@@ -678,8 +678,7 @@ define double @fabs_f64(double %a) nounwind {
;
; RV32IZFINXZDINX-LABEL: fabs_f64:
; RV32IZFINXZDINX: # %bb.0:
-; RV32IZFINXZDINX-NEXT: slli a1, a1, 1
-; RV32IZFINXZDINX-NEXT: srli a1, a1, 1
+; RV32IZFINXZDINX-NEXT: fabs.d a0, a0
; RV32IZFINXZDINX-NEXT: ret
;
; RV64IZFINXZDINX-LABEL: fabs_f64:
|
topperc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/195/builds/784 Here is the relevant piece of the build log for the reference |
Disable the DAG combine for bitcast fabs/fneg in case of the zdinx extension. The combine folds the fabs/fneg nodes in some cases. This might result in suboptimal code if compiled with the zdinx extension. In case of the zdinx extension, there is no need to load the double value from an x register to an f register, so the combine can be skipped.
Disable the DAG combine for bitcast fabs/fneg in case of the zdinx extension.
The combine folds the fabs/fneg nodes in some cases. This might result in suboptimal code if compiled with the zdinx extension. In case of the zdinx extension, there is no need to load the double value from an x register to an f register, so the combine can be skipped.