[llvm] [X86] LowerSELECTWithCmpZero - extend branchless OR/XOR select codegen to handle ADD/SUB as well (PR #107612)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 6 10:36:15 PDT 2024
================
@@ -24084,18 +24084,32 @@ static SDValue LowerSELECTWithCmpZero(SDValue CmpVal, SDValue LHS, SDValue RHS,
if (!CmpVT.isScalarInteger() || !VT.isScalarInteger())
return SDValue();
- // Convert OR/XOR '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))
+ // 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))) {
SDValue Src1, Src2;
auto isIdentityPattern = [&]() {
----------------
goldsteinn wrote:
In the middle end we have `getBinOpIdentity`, maybe we should provide a generic helper in SelectionDAG?
https://github.com/llvm/llvm-project/pull/107612
More information about the llvm-commits
mailing list