Skip to content

Commit

Permalink
[RISCV] Skip DAG combine for bitcast fabs/fneg (llvm#115325)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
futog authored Nov 8, 2024
1 parent 1adca7a commit a25d91a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
7 changes: 2 additions & 5 deletions llvm/test/CodeGen/RISCV/double-arith.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 2 additions & 4 deletions llvm/test/CodeGen/RISCV/double-bitmanip-dagcombines.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions llvm/test/CodeGen/RISCV/double-intrinsics.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a25d91a

Please sign in to comment.