Skip to content

Commit 53d929e

Browse files
committed
Mitigate with demanded bits
1 parent 4f585c4 commit 53d929e

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38449,9 +38449,9 @@ X86TargetLowering::targetShrinkDemandedConstant(SDValue Op,
3844938449
return false;
3845038450
}
3845138451

38452-
// Only optimize Ands to prevent shrinking a constant that could be
38453-
// matched by movzx.
38454-
if (Opcode != ISD::AND)
38452+
// Only optimize certain opcodes to prevent shrinking a constant that could be
38453+
// matched by specific instructions.
38454+
if (Opcode != ISD::AND && Opcode != ISD::XOR)
3845538455
return false;
3845638456

3845738457
// Make sure the RHS really is a constant.
@@ -38461,6 +38461,21 @@ X86TargetLowering::targetShrinkDemandedConstant(SDValue Op,
3846138461

3846238462
const APInt &Mask = C->getAPIntValue();
3846338463

38464+
if (Opcode == ISD::XOR) {
38465+
// If all demanded bits are 1s in the mask, we can replace the mask with
38466+
// all 1s, which allows this to be turned into a NOT.
38467+
if (DemandedBits.isSubsetOf(Mask)) {
38468+
if (Mask.isAllOnes())
38469+
return false;
38470+
// Replace the constant with all ones.
38471+
SDLoc DL(Op);
38472+
SDValue NewC = TLO.DAG.getConstant(APInt::getAllOnes(EltSize), DL, VT);
38473+
SDValue NewOp = TLO.DAG.getNode(ISD::XOR, DL, VT, Op.getOperand(0), NewC);
38474+
return TLO.CombineTo(Op, NewOp);
38475+
}
38476+
return false;
38477+
}
38478+
3846438479
// Clear all non-demanded bits initially.
3846538480
APInt ShrunkMask = Mask & DemandedBits;
3846638481

0 commit comments

Comments
 (0)