Skip to content

Commit

Permalink
[llvm] Use ConstantInt::{isZero,isOne} (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazutakahirata committed Mar 22, 2023
1 parent 2b21327 commit b9c4b95
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion llvm/lib/Analysis/TypeMetadataUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ Constant *llvm::getPointerAtOffset(Constant *I, uint64_t Offset, Module &M,

// Relative-pointer support starts here.
if (auto *CI = dyn_cast<ConstantInt>(I)) {
if (Offset == 0 && CI->getZExtValue() == 0) {
if (Offset == 0 && CI->isZero()) {
return I;
}
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,8 +844,8 @@ void IRTranslator::emitSwitchCase(SwitchCG::CaseBlock &CB,
// For conditional branch lowering, we might try to do something silly like
// emit an G_ICMP to compare an existing G_ICMP i1 result with true. If so,
// just re-use the existing condition vreg.
if (MRI->getType(CondLHS).getSizeInBits() == 1 && CI &&
CI->getZExtValue() == 1 && CB.PredInfo.Pred == CmpInst::ICMP_EQ) {
if (MRI->getType(CondLHS).getSizeInBits() == 1 && CI && CI->isOne() &&
CB.PredInfo.Pred == CmpInst::ICMP_EQ) {
Cond = CondLHS;
} else {
Register CondRHS = getOrCreateVReg(*CB.CmpRHS);
Expand Down
4 changes: 1 addition & 3 deletions llvm/lib/IR/IRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ Value *IRBuilderBase::CreateVScale(Constant *Scaling, const Twine &Name) {
Function *TheFn =
Intrinsic::getDeclaration(M, Intrinsic::vscale, {Scaling->getType()});
CallInst *CI = CreateCall(TheFn, {}, {}, Name);
return cast<ConstantInt>(Scaling)->getSExtValue() == 1
? CI
: CreateMul(CI, Scaling);
return cast<ConstantInt>(Scaling)->isOne() ? CI : CreateMul(CI, Scaling);
}

Value *IRBuilderBase::CreateElementCount(Type *DstType, ElementCount EC) {
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13953,7 +13953,7 @@ bool AArch64TargetLowering::shouldSinkOperands(
ConstantInt *ElementConstant =
dyn_cast<ConstantInt>(Insert->getOperand(2));
// Check that the insertelement is inserting into element 0
if (!ElementConstant || ElementConstant->getZExtValue() != 0)
if (!ElementConstant || !ElementConstant->isZero())
continue;

unsigned Opcode = OperandInstr->getOpcode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2240,7 +2240,7 @@ bool AArch64InstructionSelector::earlySelect(MachineInstr &I) {
case TargetOpcode::G_CONSTANT: {
bool IsZero = false;
if (I.getOperand(1).isCImm())
IsZero = I.getOperand(1).getCImm()->getZExtValue() == 0;
IsZero = I.getOperand(1).getCImm()->isZero();
else if (I.getOperand(1).isImm())
IsZero = I.getOperand(1).getImm() == 0;

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/ARM/ARMAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ void ARMAsmPrinter::emitAttributes() {

auto *PACValue = mdconst::extract_or_null<ConstantInt>(
SourceModule->getModuleFlag("sign-return-address"));
if (PACValue && PACValue->getZExtValue() == 1) {
if (PACValue && PACValue->isOne()) {
// If "+pacbti" is used as an architecture extension,
// Tag_PAC_extension is emitted in
// ARMTargetStreamer::emitTargetAttributes().
Expand All @@ -775,7 +775,7 @@ void ARMAsmPrinter::emitAttributes() {

auto *BTIValue = mdconst::extract_or_null<ConstantInt>(
SourceModule->getModuleFlag("branch-target-enforcement"));
if (BTIValue && BTIValue->getZExtValue() == 1) {
if (BTIValue && BTIValue->isOne()) {
// If "+pacbti" is used as an architecture extension,
// Tag_BTI_extension is emitted in
// ARMTargetStreamer::emitTargetAttributes().
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ Value *PolynomialMultiplyRecognize::getCountIV(BasicBlock *BB) {
continue;

if (auto *T = dyn_cast<ConstantInt>(IncV))
if (T->getZExtValue() == 1)
if (T->isOne())
return PN;
}
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ bool NVPTXAsmPrinter::isLoopHeaderOfNoUnroll(
if (MDNode *UnrollCountMD =
GetUnrollMetadata(LoopID, "llvm.loop.unroll.count")) {
if (mdconst::extract<ConstantInt>(UnrollCountMD->getOperand(1))
->getZExtValue() == 1)
->isOne())
return true;
}
}
Expand Down
5 changes: 2 additions & 3 deletions llvm/lib/Transforms/IPO/GlobalDCE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ void GlobalDCEPass::ScanVTables(Module &M) {
auto *LTOPostLinkMD =
cast_or_null<ConstantAsMetadata>(M.getModuleFlag("LTOPostLink"));
bool LTOPostLink =
LTOPostLinkMD &&
(cast<ConstantInt>(LTOPostLinkMD->getValue())->getZExtValue() != 0);
LTOPostLinkMD && !cast<ConstantInt>(LTOPostLinkMD->getValue())->isZero();

for (GlobalVariable &GV : M.globals()) {
Types.clear();
Expand Down Expand Up @@ -230,7 +229,7 @@ void GlobalDCEPass::AddVirtualFunctionDependencies(Module &M) {
// Don't attempt VFE in that case.
auto *Val = mdconst::dyn_extract_or_null<ConstantInt>(
M.getModuleFlag("Virtual Function Elim"));
if (!Val || Val->getZExtValue() == 0)
if (!Val || Val->isZero())
return;

ScanVTables(M);
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/IPO/LowerTypeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ bool lowertypetests::isJumpTableCanonical(Function *F) {
return false;
auto *CI = mdconst::extract_or_null<ConstantInt>(
F->getParent()->getModuleFlag("CFI Canonical Jump Tables"));
if (!CI || CI->getZExtValue() != 0)
if (!CI || !CI->isZero())
return true;
return F->hasFnAttribute("cfi-canonical-jump-table");
}
Expand Down Expand Up @@ -1242,7 +1242,7 @@ void LowerTypeTestsModule::createJumpTableEntry(
bool Endbr = false;
if (const auto *MD = mdconst::extract_or_null<ConstantInt>(
Dest->getParent()->getModuleFlag("cf-protection-branch")))
Endbr = MD->getZExtValue() != 0;
Endbr = !MD->isZero();
if (Endbr)
AsmOS << (JumpTableArch == Triple::x86 ? "endbr32\n" : "endbr64\n");
AsmOS << "jmp ${" << ArgIndex << ":c}@plt\n";
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Transforms/IPO/OpenMPOpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3324,7 +3324,7 @@ struct AAHeapToSharedFunction : public AAHeapToShared {
auto Remark = [&](OptimizationRemark OR) {
return OR << "Replaced globalized variable with "
<< ore::NV("SharedMemory", AllocSize->getZExtValue())
<< ((AllocSize->getZExtValue() != 1) ? " bytes " : " byte ")
<< (AllocSize->isOne() ? " byte " : " bytes ")
<< "of shared memory.";
};
A.emitRemark<OptimizationRemark>(CB, "OMP111", Remark);
Expand Down

0 comments on commit b9c4b95

Please sign in to comment.