Skip to content

Commit a25d91a

Browse files
authored
[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.
1 parent 1adca7a commit a25d91a

File tree

4 files changed

+6
-12
lines changed

4 files changed

+6
-12
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17085,7 +17085,7 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
1708517085
// fold (bitconvert (fneg x)) -> (xor (bitconvert x), signbit)
1708617086
// fold (bitconvert (fabs x)) -> (and (bitconvert x), (not signbit))
1708717087
if (!(Op0.getOpcode() == ISD::FNEG || Op0.getOpcode() == ISD::FABS) ||
17088-
!Op0.getNode()->hasOneUse())
17088+
!Op0.getNode()->hasOneUse() || Subtarget.hasStdExtZdinx())
1708917089
break;
1709017090
SDValue NewSplitF64 =
1709117091
DAG.getNode(RISCVISD::SplitF64, DL, DAG.getVTList(MVT::i32, MVT::i32),

llvm/test/CodeGen/RISCV/double-arith.ll

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -844,8 +844,7 @@ define double @fnmadd_d_3(double %a, double %b, double %c) nounwind {
844844
; RV32IZFINXZDINX-LABEL: fnmadd_d_3:
845845
; RV32IZFINXZDINX: # %bb.0:
846846
; RV32IZFINXZDINX-NEXT: fmadd.d a0, a0, a2, a4
847-
; RV32IZFINXZDINX-NEXT: lui a2, 524288
848-
; RV32IZFINXZDINX-NEXT: xor a1, a1, a2
847+
; RV32IZFINXZDINX-NEXT: fneg.d a0, a0
849848
; RV32IZFINXZDINX-NEXT: ret
850849
;
851850
; RV64IZFINXZDINX-LABEL: fnmadd_d_3:
@@ -890,9 +889,7 @@ define double @fnmadd_nsz(double %a, double %b, double %c) nounwind {
890889
;
891890
; RV32IZFINXZDINX-LABEL: fnmadd_nsz:
892891
; RV32IZFINXZDINX: # %bb.0:
893-
; RV32IZFINXZDINX-NEXT: fmadd.d a0, a0, a2, a4
894-
; RV32IZFINXZDINX-NEXT: lui a2, 524288
895-
; RV32IZFINXZDINX-NEXT: xor a1, a1, a2
892+
; RV32IZFINXZDINX-NEXT: fnmadd.d a0, a0, a2, a4
896893
; RV32IZFINXZDINX-NEXT: ret
897894
;
898895
; RV64IZFINXZDINX-LABEL: fnmadd_nsz:

llvm/test/CodeGen/RISCV/double-bitmanip-dagcombines.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ define double @fneg(double %a) nounwind {
3636
;
3737
; RV32IZFINXZDINX-LABEL: fneg:
3838
; RV32IZFINXZDINX: # %bb.0:
39-
; RV32IZFINXZDINX-NEXT: lui a2, 524288
40-
; RV32IZFINXZDINX-NEXT: xor a1, a1, a2
39+
; RV32IZFINXZDINX-NEXT: fneg.d a0, a0
4140
; RV32IZFINXZDINX-NEXT: ret
4241
;
4342
; RV64I-LABEL: fneg:
@@ -79,8 +78,7 @@ define double @fabs(double %a) nounwind {
7978
;
8079
; RV32IZFINXZDINX-LABEL: fabs:
8180
; RV32IZFINXZDINX: # %bb.0:
82-
; RV32IZFINXZDINX-NEXT: slli a1, a1, 1
83-
; RV32IZFINXZDINX-NEXT: srli a1, a1, 1
81+
; RV32IZFINXZDINX-NEXT: fabs.d a0, a0
8482
; RV32IZFINXZDINX-NEXT: ret
8583
;
8684
; RV64I-LABEL: fabs:

llvm/test/CodeGen/RISCV/double-intrinsics.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,7 @@ define double @fabs_f64(double %a) nounwind {
678678
;
679679
; RV32IZFINXZDINX-LABEL: fabs_f64:
680680
; RV32IZFINXZDINX: # %bb.0:
681-
; RV32IZFINXZDINX-NEXT: slli a1, a1, 1
682-
; RV32IZFINXZDINX-NEXT: srli a1, a1, 1
681+
; RV32IZFINXZDINX-NEXT: fabs.d a0, a0
683682
; RV32IZFINXZDINX-NEXT: ret
684683
;
685684
; RV64IZFINXZDINX-LABEL: fabs_f64:

0 commit comments

Comments
 (0)