[llvm] 5beebf9 - [DAG] foldLogicOfSetCCs - Generalize and/or (setcc X, CMax, ne), (setcc X, CMin, ne/eq) fold. NFCI.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 11 09:09:35 PST 2021
Author: Simon Pilgrim
Date: 2021-02-11T17:09:01Z
New Revision: 5beebf9c58be2e4e3db1dacec1d76ee909a138b8
URL: https://github.com/llvm/llvm-project/commit/5beebf9c58be2e4e3db1dacec1d76ee909a138b8
DIFF: https://github.com/llvm/llvm-project/commit/5beebf9c58be2e4e3db1dacec1d76ee909a138b8.diff
LOG: [DAG] foldLogicOfSetCCs - Generalize and/or (setcc X, CMax, ne), (setcc X, CMin, ne/eq) fold. NFCI.
Prep work to add support for non-uniform vectors - replace APInt values with using the SDValue ops directly.
Added:
Modified:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index cbfd6d3ed592..dc6a5ffd4ed2 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -4883,20 +4883,20 @@ SDValue DAGCombiner::foldLogicOfSetCCs(bool IsAnd, SDValue N0, SDValue N1,
ConstantSDNode *C0 = isConstOrConstSplat(LR);
ConstantSDNode *C1 = isConstOrConstSplat(RR);
if (LL == RL && C0 && C1 && !C0->isOpaque() && !C1->isOpaque()) {
- // Canonicalize larger constant as C0.
- if (C1->getAPIntValue().ugt(C0->getAPIntValue()))
- std::swap(C0, C1);
-
+ const APInt &CMax =
+ APIntOps::umax(C0->getAPIntValue(), C1->getAPIntValue());
+ const APInt &CMin =
+ APIntOps::umin(C0->getAPIntValue(), C1->getAPIntValue());
// The
diff erence of the constants must be a single bit.
- const APInt &C0Val = C0->getAPIntValue();
- const APInt &C1Val = C1->getAPIntValue();
- if ((C0Val - C1Val).isPowerOf2()) {
- // and/or (setcc X, C0, ne), (setcc X, C1, ne/eq) -->
- // setcc ((add X, -C1), ~(C0 - C1)), 0, ne/eq
- SDValue OffsetC = DAG.getConstant(-C1Val, DL, OpVT);
- SDValue Add = DAG.getNode(ISD::ADD, DL, OpVT, LL, OffsetC);
- SDValue MaskC = DAG.getConstant(~(C0Val - C1Val), DL, OpVT);
- SDValue And = DAG.getNode(ISD::AND, DL, OpVT, Add, MaskC);
+ if ((CMax - CMin).isPowerOf2()) {
+ // and/or (setcc X, CMax, ne), (setcc X, CMin, ne/eq) -->
+ // setcc ((sub X, CMin), ~(CMax - CMin)), 0, ne/eq
+ SDValue Max = DAG.getNode(ISD::UMAX, DL, OpVT, LR, RR);
+ SDValue Min = DAG.getNode(ISD::UMIN, DL, OpVT, LR, RR);
+ SDValue Offset = DAG.getNode(ISD::SUB, DL, OpVT, LL, Min);
+ SDValue Diff = DAG.getNode(ISD::SUB, DL, OpVT, Max, Min);
+ SDValue Mask = DAG.getNOT(DL, Diff, OpVT);
+ SDValue And = DAG.getNode(ISD::AND, DL, OpVT, Offset, Mask);
SDValue Zero = DAG.getConstant(0, DL, OpVT);
return DAG.getSetCC(DL, VT, And, Zero, CC0);
}
More information about the llvm-commits
mailing list