Skip to content

Commit e35199a

Browse files
RKSimongithub-actions[bot]
authored andcommitted
Automerge: [X86] combinePTESTCC - canonicalize constants to the RHS if the PTEST/TESTP node just uses the ZF flag (#165601)
If we're just comparing against zero then move the constant to the RHS to reduce duplicated folds. Noticed while triaging #156233
2 parents 98f7b3d + ba769e1 commit e35199a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48787,6 +48787,11 @@ static SDValue combinePTESTCC(SDValue EFLAGS, X86::CondCode &CC,
4878748787
}
4878848788

4878948789
if (CC == X86::COND_E || CC == X86::COND_NE) {
48790+
// Canonicalize constant to RHS if we're just using ZF.
48791+
if (Op0 != Op1 && DAG.isConstantIntBuildVectorOrConstantInt(Op0) &&
48792+
!DAG.isConstantIntBuildVectorOrConstantInt(Op1))
48793+
return DAG.getNode(EFLAGS.getOpcode(), SDLoc(EFLAGS), VT, Op1, Op0);
48794+
4879048795
// TESTZ(X,~Y) == TESTC(Y,X)
4879148796
if (SDValue NotOp1 = IsNOT(Op1, DAG)) {
4879248797
CC = (CC == X86::COND_E ? X86::COND_B : X86::COND_AE);
@@ -48850,10 +48855,6 @@ static SDValue combinePTESTCC(SDValue EFLAGS, X86::CondCode &CC,
4885048855
}
4885148856
}
4885248857

48853-
// TESTZ(-1,X) == TESTZ(X,X)
48854-
if (ISD::isBuildVectorAllOnes(Op0.getNode()))
48855-
return DAG.getNode(EFLAGS.getOpcode(), SDLoc(EFLAGS), VT, Op1, Op1);
48856-
4885748858
// TESTZ(X,-1) == TESTZ(X,X)
4885848859
if (ISD::isBuildVectorAllOnes(Op1.getNode()))
4885948860
return DAG.getNode(EFLAGS.getOpcode(), SDLoc(EFLAGS), VT, Op0, Op0);

0 commit comments

Comments
 (0)