-
Notifications
You must be signed in to change notification settings - Fork 15k
[X86] combinePTESTCC - fold PTESTZ(X,SIGNMASK) -> VTESTPD/PSZ(X,X) on AVX targets #165676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48860,6 +48860,26 @@ static SDValue combinePTESTCC(SDValue EFLAGS, X86::CondCode &CC, | |
| return DAG.getNode(EFLAGS.getOpcode(), SDLoc(EFLAGS), VT, Op0, Op0); | ||
| } | ||
|
|
||
| // Attempt to convert PTESTZ(X,SIGNMASK) -> VTESTPD/PSZ(X,X) on AVX targets. | ||
| if (EFLAGS.getOpcode() == X86ISD::PTEST && Subtarget.hasAVX()) { | ||
| KnownBits KnownOp1 = DAG.computeKnownBits(Op1); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SDM doesn't define element width, while There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't the i32 the (scalar) result type (for X86SETCC handling?) The isel patterns all use v2i64/v4i64 vectors for the input operands. But I agree, technically PTEST shouldn't care about vector element type but there's never been any need to make it work generically. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I took it as a element type 🤦♀️ |
||
| assert(KnownOp1.getBitWidth() == 64 && | ||
| "Illegal PTEST vector element width"); | ||
| if (KnownOp1.isConstant()) { | ||
| const APInt &Mask = KnownOp1.getConstant(); | ||
| if (Mask.isSignMask()) { | ||
| MVT FpVT = MVT::getVectorVT(MVT::f64, OpVT.getSizeInBits() / 64); | ||
| Op0 = DAG.getBitcast(FpVT, DAG.getFreeze(Op0)); | ||
| return DAG.getNode(X86ISD::TESTP, SDLoc(EFLAGS), VT, Op0, Op0); | ||
| } | ||
| if (Mask.isSplat(32) && Mask.trunc(32).isSignMask()) { | ||
| MVT FpVT = MVT::getVectorVT(MVT::f32, OpVT.getSizeInBits() / 32); | ||
| Op0 = DAG.getBitcast(FpVT, DAG.getFreeze(Op0)); | ||
| return DAG.getNode(X86ISD::TESTP, SDLoc(EFLAGS), VT, Op0, Op0); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // TESTZ(OR(LO(X),HI(X)),OR(LO(Y),HI(Y))) -> TESTZ(X,Y) | ||
| // TODO: Add COND_NE handling? | ||
| if (CC == X86::COND_E && OpVT.is128BitVector() && Subtarget.hasAVX()) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to freeze
X?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! Yes, we should - all the similar folds in combinePTESTCC seem to be missing that.