[llvm] [X86] Combine `PTEST` to `TESTP` (PR #157249)
Abhishek Kaushik via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 8 11:44:36 PDT 2025
abhishek-kaushik22 wrote:
> We already have a similar fold in combinePTESTCC that uses SimplifyMultipleUseDemandedBits - any idea why it isn't firing?
I guess because of this, we should probably move this combine at the end.
```cpp
// TESTZ(AND(X,Y),AND(X,Y)) == TESTZ(X,Y)
if (BC.getOpcode() == ISD::AND || BC.getOpcode() == X86ISD::FAND) {
return DAG.getNode(EFLAGS.getOpcode(), SDLoc(EFLAGS), VT,
DAG.getBitcast(OpVT, BC.getOperand(0)),
DAG.getBitcast(OpVT, BC.getOperand(1)));
}
```
There is one other which is very similar
```cpp
if (DAG.ComputeNumSignBits(BC) == EltBits) {
assert(VT == MVT::i32 && "Expected i32 EFLAGS comparison result");
APInt SignMask = APInt::getSignMask(EltBits);
if (SDValue Res =
TLI.SimplifyMultipleUseDemandedBits(BC, SignMask, DAG)) {
// For vXi16 cases we need to use pmovmksb and extract every other
// sign bit.
SDLoc DL(EFLAGS);
if ((EltBits == 32 || EltBits == 64) && Subtarget.hasAVX()) {
MVT FloatSVT = MVT::getFloatingPointVT(EltBits);
MVT FloatVT =
MVT::getVectorVT(FloatSVT, OpVT.getSizeInBits() / EltBits);
Res = DAG.getBitcast(FloatVT, Res);
return DAG.getNode(X86ISD::TESTP, SDLoc(EFLAGS), VT, Res, Res);
}
```
but it checks for all sign bits but it can handle the simple case of `and Op, constant`
https://github.com/llvm/llvm-project/pull/157249
More information about the llvm-commits
mailing list