[llvm] ba769e1 - [X86] combinePTESTCC - canonicalize constants to the RHS if the PTEST/TESTP node just uses the ZF flag (#165601)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 29 11:16:41 PDT 2025
Author: Simon Pilgrim
Date: 2025-10-29T18:16:36Z
New Revision: ba769e125b106c059321de16a760658449b02c8a
URL: https://github.com/llvm/llvm-project/commit/ba769e125b106c059321de16a760658449b02c8a
DIFF: https://github.com/llvm/llvm-project/commit/ba769e125b106c059321de16a760658449b02c8a.diff
LOG: [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
Added:
Modified:
llvm/lib/Target/X86/X86ISelLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 89b42da9a40f0..624cff24ddf03 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -48787,6 +48787,11 @@ static SDValue combinePTESTCC(SDValue EFLAGS, X86::CondCode &CC,
}
if (CC == X86::COND_E || CC == X86::COND_NE) {
+ // Canonicalize constant to RHS if we're just using ZF.
+ if (Op0 != Op1 && DAG.isConstantIntBuildVectorOrConstantInt(Op0) &&
+ !DAG.isConstantIntBuildVectorOrConstantInt(Op1))
+ return DAG.getNode(EFLAGS.getOpcode(), SDLoc(EFLAGS), VT, Op1, Op0);
+
// TESTZ(X,~Y) == TESTC(Y,X)
if (SDValue NotOp1 = IsNOT(Op1, DAG)) {
CC = (CC == X86::COND_E ? X86::COND_B : X86::COND_AE);
@@ -48850,10 +48855,6 @@ static SDValue combinePTESTCC(SDValue EFLAGS, X86::CondCode &CC,
}
}
- // TESTZ(-1,X) == TESTZ(X,X)
- if (ISD::isBuildVectorAllOnes(Op0.getNode()))
- return DAG.getNode(EFLAGS.getOpcode(), SDLoc(EFLAGS), VT, Op1, Op1);
-
// TESTZ(X,-1) == TESTZ(X,X)
if (ISD::isBuildVectorAllOnes(Op1.getNode()))
return DAG.getNode(EFLAGS.getOpcode(), SDLoc(EFLAGS), VT, Op0, Op0);
More information about the llvm-commits
mailing list