Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 1886c8e

Browse files
committed
[CodeGen] When promoting CTTZ operations to larger type, don't insert a select to detect if the input is zero to return the original size instead of the extended size. Instead just set the first bit in the zero extended part.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267280 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent a51154f commit 1886c8e

File tree

2 files changed

+14
-67
lines changed

2 files changed

+14
-67
lines changed

lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -4010,18 +4010,20 @@ void SelectionDAGLegalize::PromoteNode(SDNode *Node) {
40104010
case ISD::CTPOP:
40114011
// Zero extend the argument.
40124012
Tmp1 = DAG.getNode(ISD::ZERO_EXTEND, dl, NVT, Node->getOperand(0));
4013+
if (Node->getOpcode() == ISD::CTTZ) {
4014+
// The count is the same in the promoted type except if the original
4015+
// value was zero. This can be handled by setting the bit just off
4016+
// the top of the original type.
4017+
auto TopBit = APInt::getOneBitSet(NVT.getSizeInBits(),
4018+
OVT.getSizeInBits());
4019+
Tmp1 = DAG.getNode(ISD::OR, dl, NVT, Tmp1,
4020+
DAG.getConstant(TopBit, dl, NVT));
4021+
}
40134022
// Perform the larger operation. For CTPOP and CTTZ_ZERO_UNDEF, this is
40144023
// already the correct result.
40154024
Tmp1 = DAG.getNode(Node->getOpcode(), dl, NVT, Tmp1);
4016-
if (Node->getOpcode() == ISD::CTTZ) {
4017-
// FIXME: This should set a bit in the zero extended value instead.
4018-
Tmp2 = DAG.getSetCC(dl, getSetCCResultType(NVT),
4019-
Tmp1, DAG.getConstant(NVT.getSizeInBits(), dl, NVT),
4020-
ISD::SETEQ);
4021-
Tmp1 = DAG.getSelect(dl, NVT, Tmp2,
4022-
DAG.getConstant(OVT.getSizeInBits(), dl, NVT), Tmp1);
4023-
} else if (Node->getOpcode() == ISD::CTLZ ||
4024-
Node->getOpcode() == ISD::CTLZ_ZERO_UNDEF) {
4025+
if (Node->getOpcode() == ISD::CTLZ ||
4026+
Node->getOpcode() == ISD::CTLZ_ZERO_UNDEF) {
40254027
// Tmp1 = Tmp1 - (sizeinbits(NVT) - sizeinbits(Old VT))
40264028
Tmp1 = DAG.getNode(ISD::SUB, dl, NVT, Tmp1,
40274029
DAG.getConstant(NVT.getSizeInBits() -

0 commit comments

Comments
 (0)