From 7f5b3fa73c39be2491a74283080a35b7140972d3 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Sat, 8 Feb 2020 10:56:27 +0000 Subject: [PATCH] [X86][SSE] Add X86ISD::FRCP handling to isNegatibleForFree Peek through X86ISD::FRCP nodes to see if there is a negatible input. --- llvm/lib/Target/X86/X86ISelLowering.cpp | 8 ++++++++ llvm/test/CodeGen/X86/fma-fneg-combine-2.ll | 6 ++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index dce76b6..85741ca 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -42941,6 +42941,9 @@ char X86TargetLowering::isNegatibleForFree(SDValue Op, SelectionDAG &DAG, } return 1; } + case X86ISD::FRCP: + return isNegatibleForFree(Op.getOperand(0), DAG, LegalOperations, + ForCodeSize, Depth + 1); } return TargetLowering::isNegatibleForFree(Op, DAG, LegalOperations, @@ -42994,6 +42997,11 @@ SDValue X86TargetLowering::getNegatedExpression(SDValue Op, SelectionDAG &DAG, NewOps[i] = Op.getOperand(i); return DAG.getNode(NewOpc, SDLoc(Op), VT, NewOps); } + case X86ISD::FRCP: + return DAG.getNode(Opc, SDLoc(Op), VT, + getNegatedExpression(Op.getOperand(0), DAG, + LegalOperations, ForCodeSize, + Depth + 1)); } return TargetLowering::getNegatedExpression(Op, DAG, LegalOperations, diff --git a/llvm/test/CodeGen/X86/fma-fneg-combine-2.ll b/llvm/test/CodeGen/X86/fma-fneg-combine-2.ll index 3aadee8..0b66d53 100644 --- a/llvm/test/CodeGen/X86/fma-fneg-combine-2.ll +++ b/llvm/test/CodeGen/X86/fma-fneg-combine-2.ll @@ -89,16 +89,14 @@ entry: define <4 x float> @test_fma_rcp_fneg_v4f32(<4 x float> %x, <4 x float> %y, <4 x float> %z) { ; FMA3-LABEL: test_fma_rcp_fneg_v4f32: ; FMA3: # %bb.0: # %entry -; FMA3-NEXT: vxorps {{.*}}(%rip), %xmm2, %xmm2 ; FMA3-NEXT: vrcpps %xmm2, %xmm2 -; FMA3-NEXT: vfmadd213ps {{.*#+}} xmm0 = (xmm1 * xmm0) + xmm2 +; FMA3-NEXT: vfmsub213ps {{.*#+}} xmm0 = (xmm1 * xmm0) - xmm2 ; FMA3-NEXT: retq ; ; FMA4-LABEL: test_fma_rcp_fneg_v4f32: ; FMA4: # %bb.0: # %entry -; FMA4-NEXT: vxorps {{.*}}(%rip), %xmm2, %xmm2 ; FMA4-NEXT: vrcpps %xmm2, %xmm2 -; FMA4-NEXT: vfmaddps %xmm2, %xmm1, %xmm0, %xmm0 +; FMA4-NEXT: vfmsubps %xmm2, %xmm1, %xmm0, %xmm0 ; FMA4-NEXT: retq entry: %0 = fneg <4 x float> %z -- 2.7.4