Skip to content

Commit f807f6a

Browse files
committedDec 5, 2016
[x86] fold fand (fxor X, -1) Y --> fandn X, Y
I noticed this gap in the scalar FP-logic matching with: D26712 and: rL287171 Differential Revision: https://reviews.llvm.org/D27385 llvm-svn: 288675
1 parent bfd6a75 commit f807f6a

File tree

2 files changed

+34
-6
lines changed

2 files changed

+34
-6
lines changed
 

‎llvm/lib/Target/X86/X86ISelLowering.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -31764,6 +31764,34 @@ static SDValue getNullFPConstForNullVal(SDValue V, SelectionDAG &DAG,
3176431764
return V;
3176531765
}
3176631766

31767+
static SDValue combineFAndFNotToFAndn(SDNode *N, SelectionDAG &DAG,
31768+
const X86Subtarget &Subtarget) {
31769+
SDValue N0 = N->getOperand(0);
31770+
SDValue N1 = N->getOperand(1);
31771+
EVT VT = N->getValueType(0);
31772+
SDLoc DL(N);
31773+
31774+
// Vector types are handled in combineANDXORWithAllOnesIntoANDNP().
31775+
if (!((VT == MVT::f32 && Subtarget.hasSSE1()) ||
31776+
(VT == MVT::f64 && Subtarget.hasSSE2())))
31777+
return SDValue();
31778+
31779+
auto isAllOnesConstantFP = [](SDValue V) {
31780+
auto *C = dyn_cast<ConstantFPSDNode>(V);
31781+
return C && C->getConstantFPValue()->isAllOnesValue();
31782+
};
31783+
31784+
// fand (fxor X, -1), Y --> fandn X, Y
31785+
if (N0.getOpcode() == X86ISD::FXOR && isAllOnesConstantFP(N0.getOperand(1)))
31786+
return DAG.getNode(X86ISD::FANDN, DL, VT, N0.getOperand(0), N1);
31787+
31788+
// fand X, (fxor Y, -1) --> fandn Y, X
31789+
if (N1.getOpcode() == X86ISD::FXOR && isAllOnesConstantFP(N1.getOperand(1)))
31790+
return DAG.getNode(X86ISD::FANDN, DL, VT, N1.getOperand(0), N0);
31791+
31792+
return SDValue();
31793+
}
31794+
3176731795
/// Do target-specific dag combines on X86ISD::FAND nodes.
3176831796
static SDValue combineFAnd(SDNode *N, SelectionDAG &DAG,
3176931797
const X86Subtarget &Subtarget) {
@@ -31775,6 +31803,9 @@ static SDValue combineFAnd(SDNode *N, SelectionDAG &DAG,
3177531803
if (SDValue V = getNullFPConstForNullVal(N->getOperand(1), DAG, Subtarget))
3177631804
return V;
3177731805

31806+
if (SDValue V = combineFAndFNotToFAndn(N, DAG, Subtarget))
31807+
return V;
31808+
3177831809
return lowerX86FPLogicOp(N, DAG, Subtarget);
3177931810
}
3178031811

‎llvm/test/CodeGen/X86/fp-logic-replace.ll

+3-6
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,13 @@ define double @FsANDPSrr(double %x, double %y) {
2929
define double @FsANDNPSrr(double %x, double %y) {
3030
; SSE-LABEL: FsANDNPSrr:
3131
; SSE: # BB#0:
32-
; SSE-NEXT: movsd {{.*#+}} xmm2 = mem[0],zero
33-
; SSE-NEXT: xorpd %xmm1, %xmm2
34-
; SSE-NEXT: andpd %xmm2, %xmm0
32+
; SSE-NEXT: andnps %xmm0, %xmm1
33+
; SSE-NEXT: movaps %xmm1, %xmm0
3534
; SSE-NEXT: retq
3635
;
3736
; AVX-LABEL: FsANDNPSrr:
3837
; AVX: # BB#0:
39-
; AVX-NEXT: vmovsd {{.*#+}} xmm2 = mem[0],zero
40-
; AVX-NEXT: vxorpd %xmm2, %xmm1, %xmm1
41-
; AVX-NEXT: vandpd %xmm1, %xmm0, %xmm0
38+
; AVX-NEXT: vandnps %xmm0, %xmm1, %xmm0
4239
; AVX-NEXT: retq
4340
;
4441
%bc1 = bitcast double %x to i64

0 commit comments

Comments
 (0)
Please sign in to comment.