diff options
author | David Bolvansky <david.bolvansky@gmail.com> | 2019-06-09 18:18:57 +0000 |
---|---|---|
committer | David Bolvansky <david.bolvansky@gmail.com> | 2019-06-09 18:18:57 +0000 |
commit | dcf5e6abdf0c122edef0ece6d32b039455120c78 (patch) | |
tree | c690f478ca1b60ae7bbc6d3ad83dcf63e212cde8 /llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | |
parent | d669758d84217f7e057740053783e012369337d0 (diff) | |
download | bcm5719-llvm-dcf5e6abdf0c122edef0ece6d32b039455120c78.tar.gz bcm5719-llvm-dcf5e6abdf0c122edef0ece6d32b039455120c78.zip |
[TargetLowering] Simplify (ctpop x) == 1
Reviewers: craig.topper, spatel, RKSimon, bkramer
Reviewed By: spatel
Subscribers: javed.absar, lebedev.ri, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D63004
llvm-svn: 362912
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp index c2123dbfdd9..7d93e8685e8 100644 --- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -2691,7 +2691,18 @@ SDValue TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1, return DAG.getSetCC(dl, VT, And, DAG.getConstant(0, dl, CTVT), CC); } - // TODO: (ctpop x) == 1 -> x && (x & x-1) == 0 iff ctpop is illegal. + // (ctpop x) == 1 -> x && (x & x-1) == 0 iff ctpop is illegal. + if (Cond == ISD::SETEQ && C1 == 1 && + !isOperationLegalOrCustom(ISD::CTPOP, CTVT)) { + SDValue Sub = + DAG.getNode(ISD::SUB, dl, CTVT, CTOp, DAG.getConstant(1, dl, CTVT)); + SDValue And = DAG.getNode(ISD::AND, dl, CTVT, CTOp, Sub); + SDValue LHS = DAG.getSetCC(dl, VT, CTOp, DAG.getConstant(0, dl, CTVT), + ISD::SETUGT); + SDValue RHS = + DAG.getSetCC(dl, VT, And, DAG.getConstant(0, dl, CTVT), ISD::SETEQ); + return DAG.getNode(ISD::AND, dl, VT, LHS, RHS); + } } // (zext x) == C --> x == (trunc C) |