[llvm] 86755dd - [llvm] Use ConstantInt::getAllOnesValue()
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 9 03:02:49 PST 2025
Author: Nikita Popov
Date: 2025-12-09T12:02:39+01:00
New Revision: 86755dd0bf559ec64fafc753142ca7e1d5c247f7
URL: https://github.com/llvm/llvm-project/commit/86755dd0bf559ec64fafc753142ca7e1d5c247f7
DIFF: https://github.com/llvm/llvm-project/commit/86755dd0bf559ec64fafc753142ca7e1d5c247f7.diff
LOG: [llvm] Use ConstantInt::getAllOnesValue()
Prefer getAllOnesValue() over get(-1). This is good practice to
avoid issues with sign extension for large types.
Added:
Modified:
llvm/lib/Analysis/LoopAccessAnalysis.cpp
llvm/lib/Analysis/MemoryBuiltins.cpp
llvm/lib/Frontend/Offloading/OffloadWrapper.cpp
llvm/lib/Target/AMDGPU/AMDGPUAsanInstrumentation.cpp
llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp
llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp
llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp
llvm/lib/Transforms/IPO/OpenMPOpt.cpp
llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
index df793de7c817b..a5f47d88430e3 100644
--- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp
@@ -363,7 +363,8 @@ std::pair<const SCEV *, const SCEV *> llvm::getStartAndEndForAccess(
ScEnd = SE->getAddExpr(
SE->getNegativeSCEV(EltSizeSCEV),
SE->getSCEV(ConstantExpr::getIntToPtr(
- ConstantInt::get(EltSizeSCEV->getType(), -1), AR->getType())));
+ ConstantInt::getAllOnesValue(EltSizeSCEV->getType()),
+ AR->getType())));
}
}
const SCEV *Step = AR->getStepRecurrence(*SE);
diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp
index 6c7259d2d875c..8de8df8f1769a 100644
--- a/llvm/lib/Analysis/MemoryBuiltins.cpp
+++ b/llvm/lib/Analysis/MemoryBuiltins.cpp
@@ -707,8 +707,8 @@ Value *llvm::lowerObjectSizeCall(
// The non-constant size expression cannot evaluate to -1.
if (!isa<Constant>(Size) || !isa<Constant>(Offset))
- Builder.CreateAssumption(
- Builder.CreateICmpNE(Ret, ConstantInt::get(ResultType, -1)));
+ Builder.CreateAssumption(Builder.CreateICmpNE(
+ Ret, ConstantInt::getAllOnesValue(ResultType)));
return Ret;
}
diff --git a/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp b/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp
index 288fa10fc04bb..5f101cc6c946b 100644
--- a/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp
+++ b/llvm/lib/Frontend/Offloading/OffloadWrapper.cpp
@@ -494,13 +494,13 @@ Function *createRegisterGlobalsFunction(Module &M, bool IsHIP,
// Create kernel registration code.
Builder.SetInsertPoint(IfThenBB);
- Builder.CreateCall(RegFunc, {RegGlobalsFn->arg_begin(), Addr, Name, Name,
- ConstantInt::get(Type::getInt32Ty(C), -1),
- ConstantPointerNull::get(Int8PtrTy),
- ConstantPointerNull::get(Int8PtrTy),
- ConstantPointerNull::get(Int8PtrTy),
- ConstantPointerNull::get(Int8PtrTy),
- ConstantPointerNull::get(Int32PtrTy)});
+ Builder.CreateCall(
+ RegFunc,
+ {RegGlobalsFn->arg_begin(), Addr, Name, Name,
+ ConstantInt::getAllOnesValue(Type::getInt32Ty(C)),
+ ConstantPointerNull::get(Int8PtrTy), ConstantPointerNull::get(Int8PtrTy),
+ ConstantPointerNull::get(Int8PtrTy), ConstantPointerNull::get(Int8PtrTy),
+ ConstantPointerNull::get(Int32PtrTy)});
Builder.CreateBr(IfEndBB);
Builder.SetInsertPoint(IfElseBB);
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAsanInstrumentation.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAsanInstrumentation.cpp
index 93732a7ea25ca..9af3b05ff01fa 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAsanInstrumentation.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAsanInstrumentation.cpp
@@ -208,7 +208,8 @@ void instrumentAddress(Module &M, IRBuilder<> &IRB, Instruction *OrigIns,
Value *NumBits = IRB.CreateTypeSize(IntptrTy, TypeStoreSize);
Value *Size = IRB.CreateLShr(NumBits, ConstantInt::get(IntptrTy, 3));
Value *AddrLong = IRB.CreatePtrToInt(Addr, IntptrTy);
- Value *SizeMinusOne = IRB.CreateAdd(Size, ConstantInt::get(IntptrTy, -1));
+ Value *SizeMinusOne =
+ IRB.CreateAdd(Size, ConstantInt::getAllOnesValue(IntptrTy));
Value *LastByte =
IRB.CreateIntToPtr(IRB.CreateAdd(AddrLong, SizeMinusOne), AddrTy);
instrumentAddressImpl(M, IRB, OrigIns, InsertBefore, Addr, {}, 8, IsWrite,
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp b/llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp
index 0a163f8dc7f6b..784ee36d55c1e 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUAtomicOptimizer.cpp
@@ -589,7 +589,7 @@ std::pair<Value *, Value *> AMDGPUAtomicOptimizerImpl::buildScanIteratively(
// return the next active lane
auto *Mask = B.CreateShl(ConstantInt::get(WaveTy, 1), FF1);
- auto *InverseMask = B.CreateXor(Mask, ConstantInt::get(WaveTy, -1));
+ auto *InverseMask = B.CreateXor(Mask, ConstantInt::getAllOnesValue(WaveTy));
auto *NewActiveBits = B.CreateAnd(ActiveBits, InverseMask);
ActiveBits->addIncoming(NewActiveBits, ComputeLoop);
diff --git a/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp b/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp
index ce5431758b1c7..84176ae3fb03a 100644
--- a/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonVectorCombine.cpp
@@ -3156,7 +3156,7 @@ auto HexagonVectorCombine::getNullValue(Type *Ty) const -> Constant * {
auto HexagonVectorCombine::getFullValue(Type *Ty) const -> Constant * {
assert(Ty->isIntOrIntVectorTy());
- auto Minus1 = ConstantInt::get(Ty->getScalarType(), -1);
+ auto Minus1 = ConstantInt::getAllOnesValue(Ty->getScalarType());
if (auto *VecTy = dyn_cast<VectorType>(Ty))
return ConstantVector::getSplat(VecTy->getElementCount(), Minus1);
return Minus1;
diff --git a/llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp b/llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp
index 4e069398d540f..ef0035fa9da4d 100644
--- a/llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXCtorDtorLowering.cpp
@@ -147,10 +147,11 @@ static void createInitOrFiniCalls(Function &F, bool IsCtor) {
auto *ValuePtr = IRB.CreateGEP(PointerType::get(C, 0), BeginVal,
ArrayRef<Value *>({Offset}));
EndVal = BeginVal;
- BeginVal = IRB.CreateInBoundsGEP(
- PointerType::get(C, 0), ValuePtr,
- ArrayRef<Value *>(ConstantInt::get(IntegerType::getInt64Ty(C), -1)),
- "start");
+ BeginVal =
+ IRB.CreateInBoundsGEP(PointerType::get(C, 0), ValuePtr,
+ ArrayRef<Value *>(ConstantInt::getAllOnesValue(
+ IntegerType::getInt64Ty(C))),
+ "start");
}
IRB.CreateCondBr(
IRB.CreateCmp(IsCtor ? ICmpInst::ICMP_NE : ICmpInst::ICMP_UGE, BeginVal,
diff --git a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
index 4880fd9da288b..1f52f9a78b907 100644
--- a/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
+++ b/llvm/lib/Transforms/IPO/OpenMPOpt.cpp
@@ -4457,7 +4457,7 @@ struct AAKernelInfoFunction : AAKernelInfo {
Instruction *IsWorker =
ICmpInst::Create(ICmpInst::ICmp, llvm::CmpInst::ICMP_NE, KernelInitCB,
- ConstantInt::get(KernelInitCB->getType(), -1),
+ ConstantInt::getAllOnesValue(KernelInitCB->getType()),
"thread.is_worker", InitBB);
IsWorker->setDebugLoc(DLoc);
BranchInst::Create(IsWorkerCheckBB, UserCodeEntryBB, IsWorker, InitBB);
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index c9f249a8733ac..3ea290a77b18b 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2698,7 +2698,7 @@ void ModuleAddressSanitizer::instrumentGlobals(IRBuilder<> &IRB,
// ODR should not happen for local linkage.
if (NewGlobal->hasLocalLinkage()) {
- ODRIndicator = ConstantInt::get(IntptrTy, -1);
+ ODRIndicator = ConstantInt::getAllOnesValue(IntptrTy);
} else if (UseOdrIndicator) {
// With local aliases, we need to provide another externally visible
// symbol __odr_asan_XXX to detect ODR violation.
diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
index 09abf6a33648c..d72d216e0b3b2 100644
--- a/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
+++ b/llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp
@@ -1226,7 +1226,7 @@ void ModuleSanitizerCoverage::createFunctionControlFlow(Function &F) {
if (CB->isIndirectCall()) {
// TODO(navidem): handle indirect calls, for now mark its existence.
CFs.push_back((Constant *)IRB.CreateIntToPtr(
- ConstantInt::get(IntptrTy, -1), PtrTy));
+ ConstantInt::getAllOnesValue(IntptrTy), PtrTy));
} else {
auto CalledF = CB->getCalledFunction();
if (CalledF && !CalledF->isIntrinsic())
More information about the llvm-commits
mailing list