Skip to content

Commit 25c3ecf

Browse files
committed
[X86] Add isConstantPowerOf2 helper to replace repeated code. NFC.
Prep work for llvm#110875
1 parent 01cbbc5 commit 25c3ecf

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5190,6 +5190,21 @@ static bool getTargetShuffleMaskIndices(SDValue MaskNode,
51905190
return true;
51915191
}
51925192

5193+
static bool isConstantPowerOf2(SDValue V, unsigned EltSizeInBIts,
5194+
bool AllowUndefs) {
5195+
APInt UndefElts;
5196+
SmallVector<APInt, 64> EltBits;
5197+
if (!getTargetConstantBitsFromNode(V, EltSizeInBIts, UndefElts, EltBits,
5198+
/*AllowWholeUndefs*/ AllowUndefs,
5199+
/*AllowPartialUndefs*/ false))
5200+
return false;
5201+
5202+
bool IsPow2OrUndef = true;
5203+
for (unsigned I = 0, E = EltBits.size(); I != E; ++I)
5204+
IsPow2OrUndef &= UndefElts[I] || EltBits[I].isPowerOf2();
5205+
return IsPow2OrUndef;
5206+
}
5207+
51935208
// Match not(xor X, -1) -> X.
51945209
// Match not(pcmpgt(C, X)) -> pcmpgt(X, C - 1).
51955210
// Match not(extract_subvector(xor X, -1)) -> extract_subvector(X).
@@ -23600,17 +23615,11 @@ static SDValue LowerVSETCC(SDValue Op, const X86Subtarget &Subtarget,
2360023615
// Revert part of the simplifySetCCWithAnd combine, to avoid an invert.
2360123616
if (Cond == ISD::SETNE && ISD::isBuildVectorAllZeros(Op1.getNode())) {
2360223617
SDValue BC0 = peekThroughBitcasts(Op0);
23603-
if (BC0.getOpcode() == ISD::AND) {
23604-
APInt UndefElts;
23605-
SmallVector<APInt, 64> EltBits;
23606-
if (getTargetConstantBitsFromNode(
23607-
BC0.getOperand(1), VT.getScalarSizeInBits(), UndefElts, EltBits,
23608-
/*AllowWholeUndefs*/ false, /*AllowPartialUndefs*/ false)) {
23609-
if (llvm::all_of(EltBits, [](APInt &V) { return V.isPowerOf2(); })) {
23610-
Cond = ISD::SETEQ;
23611-
Op1 = DAG.getBitcast(VT, BC0.getOperand(1));
23612-
}
23613-
}
23618+
if (BC0.getOpcode() == ISD::AND &&
23619+
isConstantPowerOf2(BC0.getOperand(1), VT.getScalarSizeInBits(),
23620+
/*AllowUndefs=*/false)) {
23621+
Cond = ISD::SETEQ;
23622+
Op1 = DAG.getBitcast(VT, BC0.getOperand(1));
2361423623
}
2361523624
}
2361623625

@@ -51224,20 +51233,11 @@ static SDValue combineOrXorWithSETCC(unsigned Opc, const SDLoc &DL, EVT VT,
5122451233
if (Opc == ISD::XOR && N0.getOpcode() == X86ISD::PCMPEQ &&
5122551234
N0.getOperand(0).getOpcode() == ISD::AND &&
5122651235
ISD::isBuildVectorAllZeros(N0.getOperand(1).getNode()) &&
51227-
ISD::isBuildVectorAllOnes(N1.getNode())) {
51228-
APInt UndefElts;
51229-
SmallVector<APInt> EltBits;
51230-
if (getTargetConstantBitsFromNode(N0.getOperand(0).getOperand(1),
51231-
VT.getScalarSizeInBits(), UndefElts,
51232-
EltBits)) {
51233-
bool IsPow2OrUndef = true;
51234-
for (unsigned I = 0, E = EltBits.size(); I != E; ++I)
51235-
IsPow2OrUndef &= UndefElts[I] || EltBits[I].isPowerOf2();
51236-
51237-
if (IsPow2OrUndef)
51238-
return DAG.getNode(X86ISD::PCMPEQ, DL, VT, N0.getOperand(0),
51239-
N0.getOperand(0).getOperand(1));
51240-
}
51236+
ISD::isBuildVectorAllOnes(N1.getNode()) &&
51237+
isConstantPowerOf2(N0.getOperand(0).getOperand(1),
51238+
VT.getScalarSizeInBits(), /*AllowUndefs=*/true)) {
51239+
return DAG.getNode(X86ISD::PCMPEQ, DL, VT, N0.getOperand(0),
51240+
N0.getOperand(0).getOperand(1));
5124151241
}
5124251242

5124351243
return SDValue();

0 commit comments

Comments
 (0)