Skip to content

Commit 168a5e3

Browse files
committed
Reviewer-suggested refactoring
1 parent 165f82d commit 168a5e3

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "llvm/Pass.h"
3535
#include "llvm/Support/KnownBits.h"
3636
#include "llvm/Support/KnownFPClass.h"
37+
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
3738
#include "llvm/Transforms/Utils/IntegerDivision.h"
3839
#include "llvm/Transforms/Utils/Local.h"
3940
#include <cstdint>
@@ -1990,17 +1991,16 @@ Value *AMDGPUCodeGenPrepareImpl::applyFractPat(IRBuilder<> &Builder,
19901991
}
19911992

19921993
bool AMDGPUCodeGenPrepareImpl::visitCtpop(IntrinsicInst &I) {
1993-
uint32_t BitWidth, DestinationWidth, IntrinsicWidth;
1994-
if (!I.hasOneUse() || !I.getType()->isIntegerTy() ||
1995-
!ST.hasBCNT(BitWidth = I.getType()->getIntegerBitWidth()))
1994+
uint32_t BitWidth, DestinationWidth;
1995+
if (!I.hasOneUse() || !I.getType()->isIntegerTy())
19961996
return false;
19971997

1998-
BinaryOperator *MustBeSub = dyn_cast<BinaryOperator>(I.user_back());
1999-
if (!MustBeSub || MustBeSub->getOpcode() != BinaryOperator::Sub)
1998+
BitWidth = I.getType()->getIntegerBitWidth();
1999+
if(!ST.hasBCNT(BitWidth))
20002000
return false;
20012001

2002-
ConstantInt *FirstOperand = dyn_cast<ConstantInt>(MustBeSub->getOperand(0));
2003-
if (!FirstOperand || FirstOperand->getZExtValue() != BitWidth)
2002+
Instruction *MustBeSub = I.user_back();
2003+
if (!match(MustBeSub, m_Sub(m_SpecificInt(BitWidth), m_Specific(&I))))
20042004
return false;
20052005

20062006
IRBuilder<> Builder(MustBeSub);
@@ -2009,14 +2009,12 @@ bool AMDGPUCodeGenPrepareImpl::visitCtpop(IntrinsicInst &I) {
20092009
: Intrinsic::amdgcn_bcnt32_lo,
20102010
{}, {I.getArgOperand(0)});
20112011

2012-
if ((DestinationWidth = MustBeSub->getType()->getIntegerBitWidth()) !=
2013-
(IntrinsicWidth = TransformedIns->getType()->getIntegerBitWidth()))
2014-
TransformedIns = cast<Instruction>(Builder.CreateZExtOrTrunc(
2015-
TransformedIns, Type::getIntNTy(I.getContext(), DestinationWidth)));
2012+
DestinationWidth = MustBeSub->getType()->getIntegerBitWidth();
2013+
TransformedIns = cast<Instruction>(Builder.CreateZExtOrTrunc(
2014+
TransformedIns, Type::getIntNTy(I.getContext(), DestinationWidth)));
20162015

2017-
MustBeSub->replaceAllUsesWith(TransformedIns);
2018-
TransformedIns->takeName(MustBeSub);
2019-
MustBeSub->eraseFromParent();
2016+
BasicBlock::iterator SubIt = MustBeSub->getIterator();
2017+
ReplaceInstWithValue(SubIt,TransformedIns);
20202018
return true;
20212019
}
20222020

0 commit comments

Comments
 (0)