Skip to content

Commit b810b66

Browse files
committed
[X86] combineFMulcFCMulc - use KnownBits to detect conjugate patterns.
We currently look for X86ISD::VBROADCAST_LOAD patterns, but this won't work with a future patch which will improve sharing of constant pool loads.
1 parent 32d1197 commit b810b66

File tree

1 file changed

+8
-27
lines changed

1 file changed

+8
-27
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50824,37 +50824,18 @@ static SDValue combineFMulcFCMulc(SDNode *N, SelectionDAG &DAG,
5082450824
SDValue RHS = N->getOperand(1);
5082550825
int CombineOpcode =
5082650826
N->getOpcode() == X86ISD::VFCMULC ? X86ISD::VFMULC : X86ISD::VFCMULC;
50827-
auto isConjugationConstant = [](const Constant *c) {
50828-
if (const auto *CI = dyn_cast<ConstantInt>(c)) {
50829-
APInt ConjugationInt32 = APInt(32, 0x80000000, true);
50830-
APInt ConjugationInt64 = APInt(64, 0x8000000080000000ULL, true);
50831-
switch (CI->getBitWidth()) {
50832-
case 16:
50833-
return false;
50834-
case 32:
50835-
return CI->getValue() == ConjugationInt32;
50836-
case 64:
50837-
return CI->getValue() == ConjugationInt64;
50838-
default:
50839-
llvm_unreachable("Unexpected bit width");
50840-
}
50841-
}
50842-
if (const auto *CF = dyn_cast<ConstantFP>(c))
50843-
return CF->getType()->isFloatTy() && CF->isNegativeZeroValue();
50844-
return false;
50845-
};
5084650827
auto combineConjugation = [&](SDValue &r) {
5084750828
if (LHS->getOpcode() == ISD::BITCAST && RHS.hasOneUse()) {
5084850829
SDValue XOR = LHS.getOperand(0);
5084950830
if (XOR->getOpcode() == ISD::XOR && XOR.hasOneUse()) {
50850-
SDValue XORRHS = XOR.getOperand(1);
50851-
if (XORRHS.getOpcode() == ISD::BITCAST && XORRHS.hasOneUse())
50852-
XORRHS = XORRHS.getOperand(0);
50853-
if (XORRHS.getOpcode() == X86ISD::VBROADCAST_LOAD &&
50854-
XORRHS.getOperand(1).getNumOperands()) {
50855-
ConstantPoolSDNode *CP =
50856-
dyn_cast<ConstantPoolSDNode>(XORRHS.getOperand(1).getOperand(0));
50857-
if (CP && isConjugationConstant(CP->getConstVal())) {
50831+
KnownBits XORRHS = DAG.computeKnownBits(XOR.getOperand(1));
50832+
if (XORRHS.isConstant()) {
50833+
APInt ConjugationInt32 = APInt(32, 0x80000000, true);
50834+
APInt ConjugationInt64 = APInt(64, 0x8000000080000000ULL, true);
50835+
if ((XORRHS.getBitWidth() == 32 &&
50836+
XORRHS.getConstant() == ConjugationInt32) ||
50837+
(XORRHS.getBitWidth() == 64 &&
50838+
XORRHS.getConstant() == ConjugationInt64)) {
5085850839
SelectionDAG::FlagInserter FlagsInserter(DAG, N);
5085950840
SDValue I2F = DAG.getBitcast(VT, LHS.getOperand(0).getOperand(0));
5086050841
SDValue FCMulC = DAG.getNode(CombineOpcode, SDLoc(N), VT, RHS, I2F);

0 commit comments

Comments
 (0)