forked from OSchip/llvm-project
[DAGCombiner] Add vector support to (sub -1, x) -> (xor x, -1) canonicalization
Improves commutation potential llvm-svn: 284113
This commit is contained in:
parent
bb51662d8d
commit
833b8a2071
|
@ -863,6 +863,17 @@ static bool isOneConstantOrOneSplatConstant(SDValue N) {
|
|||
return false;
|
||||
}
|
||||
|
||||
// Determines if it is a constant integer of all ones or a splatted vector of a
|
||||
// constant integer of all ones (with no undefs).
|
||||
// Do not permit build vector implicit truncation.
|
||||
static bool isAllOnesConstantOrAllOnesSplatConstant(SDValue N) {
|
||||
unsigned BitWidth = N.getScalarValueSizeInBits();
|
||||
if (ConstantSDNode *Splat = isConstOrConstSplat(N))
|
||||
return Splat->isAllOnesValue() &&
|
||||
Splat->getAPIntValue().getBitWidth() == BitWidth;
|
||||
return false;
|
||||
}
|
||||
|
||||
SDValue DAGCombiner::ReassociateOps(unsigned Opc, const SDLoc &DL, SDValue N0,
|
||||
SDValue N1) {
|
||||
EVT VT = N0.getValueType();
|
||||
|
@ -1938,7 +1949,7 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
|
|||
}
|
||||
|
||||
// Canonicalize (sub -1, x) -> ~x, i.e. (xor x, -1)
|
||||
if (isAllOnesConstant(N0))
|
||||
if (isAllOnesConstantOrAllOnesSplatConstant(N0))
|
||||
return DAG.getNode(ISD::XOR, DL, VT, N1, N0);
|
||||
|
||||
// fold A-(A-B) -> B
|
||||
|
|
|
@ -50,14 +50,13 @@ define <4 x i32> @combine_vec_sub_negone(<4 x i32> %x) {
|
|||
; SSE-LABEL: combine_vec_sub_negone:
|
||||
; SSE: # BB#0:
|
||||
; SSE-NEXT: pcmpeqd %xmm1, %xmm1
|
||||
; SSE-NEXT: psubd %xmm0, %xmm1
|
||||
; SSE-NEXT: movdqa %xmm1, %xmm0
|
||||
; SSE-NEXT: pxor %xmm1, %xmm0
|
||||
; SSE-NEXT: retq
|
||||
;
|
||||
; AVX-LABEL: combine_vec_sub_negone:
|
||||
; AVX: # BB#0:
|
||||
; AVX-NEXT: vpcmpeqd %xmm1, %xmm1, %xmm1
|
||||
; AVX-NEXT: vpsubd %xmm0, %xmm1, %xmm0
|
||||
; AVX-NEXT: vpxor %xmm1, %xmm0, %xmm0
|
||||
; AVX-NEXT: retq
|
||||
%1 = sub <4 x i32> <i32 -1, i32 -1, i32 -1, i32 -1>, %x
|
||||
ret <4 x i32> %1
|
||||
|
|
Loading…
Reference in New Issue