diff --git a/llvm/include/llvm/IR/IntrinsicInst.h b/llvm/include/llvm/IR/IntrinsicInst.h index c07b83a81a63e..227a726aa9e5e 100644 --- a/llvm/include/llvm/IR/IntrinsicInst.h +++ b/llvm/include/llvm/IR/IntrinsicInst.h @@ -1506,6 +1506,7 @@ class InstrProfIncrementInst : public InstrProfCntrInstBase { return isa(V) && classof(cast(V)); } Value *getStep() const; + Value *getAtomicStep() const; }; /// This represents the llvm.instrprof.increment.step intrinsic. diff --git a/llvm/lib/IR/IntrinsicInst.cpp b/llvm/lib/IR/IntrinsicInst.cpp index 89403e1d7fcb4..7fe7f89bc4b4e 100644 --- a/llvm/lib/IR/IntrinsicInst.cpp +++ b/llvm/lib/IR/IntrinsicInst.cpp @@ -288,9 +288,26 @@ Value *InstrProfIncrementInst::getStep() const { } const Module *M = getModule(); LLVMContext &Context = M->getContext(); + const auto &DL = M->getDataLayout(); + Type *LargestLegalIntTy = DL.getLargestLegalIntType(Context); + + if (LargestLegalIntTy) { + return ConstantInt::get(LargestLegalIntTy, 1); + } + return ConstantInt::get(Type::getInt64Ty(Context), 1); } +Value *InstrProfIncrementInst::getAtomicStep() const { + if (InstrProfIncrementInstStep::classof(this)) { + return const_cast(getArgOperand(4)); + } + const Module *M = getModule(); + LLVMContext &Context = M->getContext(); + const auto &DL = M->getDataLayout(); + return ConstantInt::get(DL.getIntPtrType(Context), 1); +} + std::optional ConstrainedFPIntrinsic::getRoundingMode() const { unsigned NumOperands = arg_size(); Metadata *MD = nullptr; diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp index c42c53edd5119..ee55e1b1c32d5 100644 --- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp +++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp @@ -958,7 +958,7 @@ void InstrLowerer::lowerIncrement(InstrProfIncrementInst *Inc) { IRBuilder<> Builder(Inc); if (Options.Atomic || AtomicCounterUpdateAll || (Inc->getIndex()->isZeroValue() && AtomicFirstCounter)) { - Builder.CreateAtomicRMW(AtomicRMWInst::Add, Addr, Inc->getStep(), + Builder.CreateAtomicRMW(AtomicRMWInst::Add, Addr, Inc->getAtomicStep(), MaybeAlign(), AtomicOrdering::Monotonic); } else { Value *IncStep = Inc->getStep();