From a25d91a164b0a283dd809cf9b4d9442d24173fb7 Mon Sep 17 00:00:00 2001 From: Gergely Futo Date: Fri, 8 Nov 2024 08:37:46 +0100 Subject: [PATCH] [RISCV] Skip DAG combine for bitcast fabs/fneg (#115325) 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/lib/Target/RISCV/RISCVISelLowering.cpp | 2 +- llvm/test/CodeGen/RISCV/double-arith.ll | 7 ++----- llvm/test/CodeGen/RISCV/double-bitmanip-dagcombines.ll | 6 ++---- llvm/test/CodeGen/RISCV/double-intrinsics.ll | 3 +-- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp index 48a7c1f047ff46..8b5a79990d7c61 100644 --- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp @@ -17085,7 +17085,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: