[llvm] [X86] Use the standard cmp+cmov for select (X != 0), -1, Y if we will be setting sbb to 0 anyway (PR #149672)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 19 16:00:11 PDT 2025
================
@@ -24917,6 +24917,30 @@ static SDValue LowerSELECTWithCmpZero(SDValue CmpVal, SDValue LHS, SDValue RHS,
if ((X86CC == X86::COND_E || X86CC == X86::COND_NE) &&
(isAllOnesConstant(LHS) || isAllOnesConstant(RHS))) {
SDValue Y = isAllOnesConstant(RHS) ? LHS : RHS;
+
+ // If CMOV is available, use it instead. Only prefer CMOV when SBB
+ // dependency breaking is not available or when CMOV is likely to be more
+ // efficient
+ if (Subtarget.canUseCMOV() &&
+ (VT == MVT::i16 || VT == MVT::i32 || VT == MVT::i64) &&
+ !Subtarget.hasSBBDepBreaking()) {
+ // Create comparison against zero to set EFLAGS
+ SDValue Zero = DAG.getConstant(0, DL, CmpVT);
+ SDValue Cmp = DAG.getNode(X86ISD::CMP, DL, MVT::i32, CmpVal, Zero);
+
+ // For CMOV: FalseVal is used when condition is false, TrueVal when
+ // condition is true We want: when X==0 return -1, when X!=0 return Y So
+ // condition should be (X == 0), TrueVal = -1, FalseVal = Y The SBB
+ // pattern implements: (CmpVal X86CC 0) ? LHS : RHS We need to implement
+ // exactly the same select operation with CMOV CMOV semantics: CMOV
+ // condition, TrueVal, FalseVal Returns TrueVal if condition is true,
+ // FalseVal if condition is false
+
+ return DAG.getNode(X86ISD::CMOV, DL, VT, RHS, LHS,
----------------
topperc wrote:
What happens if we return `SDValue()` here instead?
https://github.com/llvm/llvm-project/pull/149672
More information about the llvm-commits
mailing list