Skip to content

Commit 86755dd

Browse files
committed
[llvm] Use ConstantInt::getAllOnesValue()
Prefer getAllOnesValue() over get(-1). This is good practice to avoid issues with sign extension for large types.
1 parent 2c3ca10 commit 86755dd

File tree

10 files changed

+23
-20
lines changed

10 files changed

+23
-20
lines changed

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ std::pair<const SCEV *, const SCEV *> llvm::getStartAndEndForAccess(
363363
ScEnd = SE->getAddExpr(
364364
SE->getNegativeSCEV(EltSizeSCEV),
365365
SE->getSCEV(ConstantExpr::getIntToPtr(
366-
ConstantInt::get(EltSizeSCEV->getType(), -1), AR->getType())));
366+
ConstantInt::getAllOnesValue(EltSizeSCEV->getType()),
367+
AR->getType())));
367368
}
368369
}
369370
const SCEV *Step = AR->getStepRecurrence(*SE);

llvm/lib/Analysis/MemoryBuiltins.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,8 @@ Value *llvm::lowerObjectSizeCall(
707707

708708
// The non-constant size expression cannot evaluate to -1.
709709
if (!isa<Constant>(Size) || !isa<Constant>(Offset))
710-
Builder.CreateAssumption(
711-
Builder.CreateICmpNE(Ret, ConstantInt::get(ResultType, -1)));
710+
Builder.CreateAssumption(Builder.CreateICmpNE(
711+
Ret, ConstantInt::getAllOnesValue(ResultType)));
712712

713713
return Ret;
714714
}

llvm/lib/Frontend/Offloading/OffloadWrapper.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -494,13 +494,13 @@ Function *createRegisterGlobalsFunction(Module &M, bool IsHIP,
494494

495495
// Create kernel registration code.
496496
Builder.SetInsertPoint(IfThenBB);
497-
Builder.CreateCall(RegFunc, {RegGlobalsFn->arg_begin(), Addr, Name, Name,
498-
ConstantInt::get(Type::getInt32Ty(C), -1),
499-
ConstantPointerNull::get(Int8PtrTy),
500-
ConstantPointerNull::get(Int8PtrTy),
501-
ConstantPointerNull::get(Int8PtrTy),
502-
ConstantPointerNull::get(Int8PtrTy),
503-
ConstantPointerNull::get(Int32PtrTy)});
497+
Builder.CreateCall(
498+
RegFunc,
499+
{RegGlobalsFn->arg_begin(), Addr, Name, Name,
500+
ConstantInt::getAllOnesValue(Type::getInt32Ty(C)),
501+
ConstantPointerNull::get(Int8PtrTy), ConstantPointerNull::get(Int8PtrTy),
502+
ConstantPointerNull::get(Int8PtrTy), ConstantPointerNull::get(Int8PtrTy),
503+
ConstantPointerNull::get(Int32PtrTy)});
504504
Builder.CreateBr(IfEndBB);
505505
Builder.SetInsertPoint(IfElseBB);
506506

llvm/lib/Target/AMDGPU/AMDGPUAsanInstrumentation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ void instrumentAddress(Module &M, IRBuilder<> &IRB, Instruction *OrigIns,
208208
Value *NumBits = IRB.CreateTypeSize(IntptrTy, TypeStoreSize);
209209
Value *Size = IRB.CreateLShr(NumBits, ConstantInt::get(IntptrTy, 3));
210210
Value *AddrLong = IRB.CreatePtrToInt(Addr, IntptrTy);
211-
Value *SizeMinusOne = IRB.CreateAdd(Size, ConstantInt::get(IntptrTy, -1));
211+
Value *SizeMinusOne =
212+
IRB.CreateAdd(Size, ConstantInt::getAllOnesValue(IntptrTy));
212213
Value *LastByte =
213214
IRB.CreateIntToPtr(IRB.CreateAdd(AddrLong, SizeMinusOne), AddrTy);
214215
instrumentAddressImpl(M, IRB, OrigIns, InsertBefore, Addr, {}, 8, IsWrite,

llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ std::pair<Value *, Value *> AMDGPUAtomicOptimizerImpl::buildScanIteratively(
589589
// return the next active lane
590590
auto *Mask = B.CreateShl(ConstantInt::get(WaveTy, 1), FF1);
591591

592-
auto *InverseMask = B.CreateXor(Mask, ConstantInt::get(WaveTy, -1));
592+
auto *InverseMask = B.CreateXor(Mask, ConstantInt::getAllOnesValue(WaveTy));
593593
auto *NewActiveBits = B.CreateAnd(ActiveBits, InverseMask);
594594
ActiveBits->addIncoming(NewActiveBits, ComputeLoop);
595595

llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3156,7 +3156,7 @@ auto HexagonVectorCombine::getNullValue(Type *Ty) const -> Constant * {
31563156

31573157
auto HexagonVectorCombine::getFullValue(Type *Ty) const -> Constant * {
31583158
assert(Ty->isIntOrIntVectorTy());
3159-
auto Minus1 = ConstantInt::get(Ty->getScalarType(), -1);
3159+
auto Minus1 = ConstantInt::getAllOnesValue(Ty->getScalarType());
31603160
if (auto *VecTy = dyn_cast<VectorType>(Ty))
31613161
return ConstantVector::getSplat(VecTy->getElementCount(), Minus1);
31623162
return Minus1;

llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,11 @@ static void createInitOrFiniCalls(Function &F, bool IsCtor) {
147147
auto *ValuePtr = IRB.CreateGEP(PointerType::get(C, 0), BeginVal,
148148
ArrayRef<Value *>({Offset}));
149149
EndVal = BeginVal;
150-
BeginVal = IRB.CreateInBoundsGEP(
151-
PointerType::get(C, 0), ValuePtr,
152-
ArrayRef<Value *>(ConstantInt::get(IntegerType::getInt64Ty(C), -1)),
153-
"start");
150+
BeginVal =
151+
IRB.CreateInBoundsGEP(PointerType::get(C, 0), ValuePtr,
152+
ArrayRef<Value *>(ConstantInt::getAllOnesValue(
153+
IntegerType::getInt64Ty(C))),
154+
"start");
154155
}
155156
IRB.CreateCondBr(
156157
IRB.CreateCmp(IsCtor ? ICmpInst::ICMP_NE : ICmpInst::ICMP_UGE, BeginVal,

llvm/lib/Transforms/IPO/OpenMPOpt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4457,7 +4457,7 @@ struct AAKernelInfoFunction : AAKernelInfo {
44574457

44584458
Instruction *IsWorker =
44594459
ICmpInst::Create(ICmpInst::ICmp, llvm::CmpInst::ICMP_NE, KernelInitCB,
4460-
ConstantInt::get(KernelInitCB->getType(), -1),
4460+
ConstantInt::getAllOnesValue(KernelInitCB->getType()),
44614461
"thread.is_worker", InitBB);
44624462
IsWorker->setDebugLoc(DLoc);
44634463
BranchInst::Create(IsWorkerCheckBB, UserCodeEntryBB, IsWorker, InitBB);

llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2698,7 +2698,7 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB,
26982698

26992699
// ODR should not happen for local linkage.
27002700
if (NewGlobal->hasLocalLinkage()) {
2701-
ODRIndicator = ConstantInt::get(IntptrTy, -1);
2701+
ODRIndicator = ConstantInt::getAllOnesValue(IntptrTy);
27022702
} else if (UseOdrIndicator) {
27032703
// With local aliases, we need to provide another externally visible
27042704
// symbol __odr_asan_XXX to detect ODR violation.

llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ void ModuleSanitizerCoverage::createFunctionControlFlow(Function &F) {
12261226
if (CB->isIndirectCall()) {
12271227
// TODO(navidem): handle indirect calls, for now mark its existence.
12281228
CFs.push_back((Constant *)IRB.CreateIntToPtr(
1229-
ConstantInt::get(IntptrTy, -1), PtrTy));
1229+
ConstantInt::getAllOnesValue(IntptrTy), PtrTy));
12301230
} else {
12311231
auto CalledF = CB->getCalledFunction();
12321232
if (CalledF && !CalledF->isIntrinsic())

0 commit comments

Comments
 (0)