[llvm] [DAG] combineVSelectWithAllOnesOrZeros - fold select Cond, 0, x -> and not(Cond), x (PR #147472)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 8 02:41:20 PDT 2025
================
@@ -9902,11 +9902,14 @@ SDValue DAGCombiner::visitXOR(SDNode *N) {
if (SDValue Combined = visitADDLike(N))
return Combined;
- // fold !(x cc y) -> (x !cc y)
+ // fold xor (setcc x y cc) -1 -> setcc x y !cc
+ // Avoid breaking: and (xor (setcc x y cc) -1) z -> andn for vec
unsigned N0Opcode = N0.getOpcode();
SDValue LHS, RHS, CC;
if (TLI.isConstTrueVal(N1) &&
- isSetCCEquivalent(N0, LHS, RHS, CC, /*MatchStrict*/ true)) {
+ isSetCCEquivalent(N0, LHS, RHS, CC, /*MatchStrict*/ true) &&
+ !(N->hasOneUse() && TLI.hasAndNot(SDValue(N, 0)) &&
+ N->use_begin()->getUser()->getOpcode() == ISD::AND && VT.isVector())) {
----------------
RKSimon wrote:
Put the use logic later as its often more computationally expensive:
```
!(VT.isVector() && TLI.hasAndNot(SDValue(N, 0)) &&
N->hasOneUse() && N->use_begin()->getUser()->getOpcode() == ISD::AND)
```
https://github.com/llvm/llvm-project/pull/147472
More information about the llvm-commits
mailing list