[llvm] 1ab649c - [X86] LowerSELECTWithCmpZero - move !canUseCMOV check inside fold and update comment describing fold for clarity. NFC.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 8 02:40:26 PDT 2024
Author: Simon Pilgrim
Date: 2024-09-08T10:08:50+01:00
New Revision: 1ab649c18a0368af2a2a046ff7ac245282f9a895
URL: https://github.com/llvm/llvm-project/commit/1ab649c18a0368af2a2a046ff7ac245282f9a895
DIFF: https://github.com/llvm/llvm-project/commit/1ab649c18a0368af2a2a046ff7ac245282f9a895.diff
LOG: [X86] LowerSELECTWithCmpZero - move !canUseCMOV check inside fold and update comment describing fold for clarity. NFC.
Minor refactor step before extending fold to support more patterns.
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 839b87dd5d4dd8..3b90ab3acddbd6 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -24084,13 +24084,9 @@ static SDValue LowerSELECTWithCmpZero(SDValue CmpVal, SDValue LHS, SDValue RHS,
if (!CmpVT.isScalarInteger() || !VT.isScalarInteger())
return SDValue();
- // Convert 'identity' patterns (iff X is 0 or 1):
- // SELECT (X != 0), Y, (OR Y, Z) -> (OR Y, (AND (0 - X), Z))
- // SELECT (X != 0), Y, (XOR Y, Z) -> (XOR Y, (AND (0 - X), Z))
- // SELECT (X != 0), Y, (ADD Y, Z) -> (ADD Y, (AND (0 - X), Z))
- // SELECT (X != 0), Y, (SUB Y, Z) -> (SUB Y, (AND (0 - X), Z))
- if (!Subtarget.canUseCMOV() && X86CC == X86::COND_E &&
- CmpVal.getOpcode() == ISD::AND && isOneConstant(CmpVal.getOperand(1))) {
+ if (X86CC == X86::COND_E && CmpVal.getOpcode() == ISD::AND &&
+ isOneConstant(CmpVal.getOperand(1))) {
+
SDValue Src1, Src2;
auto isIdentityPattern = [&]() {
switch (RHS.getOpcode()) {
@@ -24114,7 +24110,12 @@ static SDValue LowerSELECTWithCmpZero(SDValue CmpVal, SDValue LHS, SDValue RHS,
return false;
};
- if (isIdentityPattern()) {
+ // Convert 'identity' patterns (iff X is 0 or 1):
+ // SELECT (AND(X,1) == 0), Y, (OR Y, Z) -> (OR Y, (AND NEG(AND(X,1)), Z))
+ // SELECT (AND(X,1) == 0), Y, (XOR Y, Z) -> (XOR Y, (AND NEG(AND(X,1)), Z))
+ // SELECT (AND(X,1) == 0), Y, (ADD Y, Z) -> (ADD Y, (AND NEG(AND(X,1)), Z))
+ // SELECT (AND(X,1) == 0), Y, (SUB Y, Z) -> (SUB Y, (AND NEG(AND(X,1)), Z))
+ if (!Subtarget.canUseCMOV() && isIdentityPattern()) {
// we need mask of all zeros or ones with same size of the other
// operands.
SDValue Neg = CmpVal;
More information about the llvm-commits
mailing list