The first operand to a call or invoke instruction is the callee, then comes the arguments. getArgOperand(0) returns the first argument to the call, while getOperand(0) would return the callee.

The function you quoted then checks whether the first argument to the function call is a load and if so switches out ans for the pointer that was being loaded. Then if ans is a bitcast, it peeks through the bitcast to replace ans with the casted value. Why it does this is not clear from the context (what about multiple bitcasts?), but that's what it does.

Update1: I think it's a version issue. It looks like right now all getArgOperand(i) does is return getOperand(i). Instead getCalledOperand(), which returns the callee, now does getOperand(-1)! Regardless, this is why getArgOperand() was originally added.

Answer from Nick Lewycky on Stack Overflow
🌐
Vu
few.vu.nl › ~lsc300 › LLVM › doxygen › classllvm_1_1CallInst.html
LLVM: llvm::CallInst Class Reference
Referenced by HandleCallsInBlockInlinedThroughInvoke(), and llvm::InstCombiner::visitCallInst(). getArgOperand/setArgOperand - Return/set the i-th call argument. Definition at line 1245 of file Instructions.h. References llvm::User::getOperand().
🌐
LLVM
llvm.org › doxygen › classllvm_1_1CallBase.html
LLVM: llvm::CallBase Class Reference
References getArgOperandNo(). Definition at line 1376 of file InstrTypes.h. References arg_size(), assert(), and llvm::User::getOperandUse().
🌐
Hdoc
docs.hdoc.io › hdoc › llvm-project › rBA0095D496BE5B4E.html
class CallBase: LLVM/Clang 15.x documentation
public llvm::Value * getArgOperandWithAttribute(Attribute::AttrKind Kind) const · public llvm::Attribute getAttributeAtIndex(unsigned int i, llvm::StringRef Kind) const · public llvm::Attribute getAttributeAtIndex(unsigned int i, Attribute::AttrKind Kind) const ·
🌐
LLVM
llvm.org › doxygen › classllvm_1_1FuncletPadInst.html
LLVM: llvm::FuncletPadInst Class Reference
References llvm::User::getNumOperands(). Provide fast operand accessors. getArgOperand/setArgOperand - Return/set the i-th funcletpad argument. Definition at line 2457 of file InstrTypes.h. Referenced by mapWasmLandingPadIndex(). Convenience accessors. Return the outer EH-pad this funclet is nested within.
🌐
Urho3D
docs.huihoo.com › doxygen › llvm › 20140918 › classllvm_1_1CallInst.html
llvm::CallInst Class Reference - Huihoo
Referenced by HandleCallsInBlockInlinedThroughInvoke(), and llvm::InstCombiner::visitCallInst(). getArgOperand/setArgOperand - Return/set the i-th call argument. Definition at line 1335 of file Instructions.h. References llvm::User::getOperand().
🌐
Google Groups
groups.google.com › d › topic › llvm-dev › uYtl-SsDGpI
[LLVMdev] How to get the name and argument of a function
There's a worked example at http://wiki.llvm.org/HowTo:_Find_all_call_sites_of_a_function . With the CallInst/InvokeInst you can query getArgOperand() to get the arguments or getCallee() which return a Function -- or it might not. If the call is an indirect call (ie., function pointer) then ...
🌐
LLVM
llvm.org › doxygen › classllvm_1_1IntrinsicLowering.html
LLVM: llvm::IntrinsicLowering Class Reference
References llvm::CallBase::arg_size(), llvm::CallInst::Create(), llvm::dyn_cast(), llvm::Instruction::eraseFromParent(), llvm::CallBase::getArgOperand(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::Instruction::getModule(), llvm::Value::getName(), llvm::Intrinsic::getOrInsertDeclaration(), llvm::Value::getType(), Int, llvm::Type::isIntegerTy(), and llvm::Value::replaceAllUsesWith().
🌐
LLVM
llvm.org › doxygen › functions_func_g.html
LLVM: Class Members - Functions
getArgOperandNo() : llvm::CallBase, llvm::sandboxir::CallBase
Find elsewhere
🌐
GitHub
github.com › google › clspv › blob › main › lib › ReplaceLLVMIntrinsicsPass.cpp
clspv/lib/ReplaceLLVMIntrinsicsPass.cpp at main · google/clspv
if (F.getName().contains("llvm.memset")) { SmallVector<CallInst *, 8> CallsToReplace; · for (auto U : F.users()) { if (auto CI = dyn_cast<CallInst>(U)) { auto Initializer = dyn_cast<ConstantInt>(CI->getArgOperand(1)); · // We only handle cases where the initializer is a constant int that ·
Author   google
🌐
LLVM
llvm.org › doxygen › classllvm_1_1User.html
LLVM: llvm::User Class Reference
ntoPHI(), foldSelectBinOpIdentity(), ... llvm::InsertValueInst::getAggregateOperand(), llvm::GlobalAlias::getAliaseeObject(), getAlternateBinop(), llvm::CallBase::getArgOperand(), llvm::FuncletPadInst::getArgOperand(), llvm::AArch64TTIImpl::getArithmeticInstrCost(), llvm::AllocaIn...
🌐
LLVM
llvm.org › doxygen › classllvm_1_1CallInst.html
LLVM: llvm::CallInst Class Reference
References llvm::CallBase::getNumOperandBundles(), llvm::User::getNumOperands(), and llvm::CallBase::hasOperandBundles().
🌐
Hackage
hackage.haskell.org › package › LibClang-3.4.0 › src › llvm › lib › Transforms › Utils › SimplifyLibCalls.cpp
SimplifyLibCalls.cpp
( CI->getArgOperand(SizeArgOp))) return SizeCI->getZExtValue() >= Arg->getZExtValue(); } return false; } }; struct MemCpyChkOpt : public InstFortifiedLibCallOptimization { virtual Value *callOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) { this->CI = CI; FunctionType *FT = Callee->getFunctionType(); LLVMContext &Context = CI->getParent()->getContext(); // Check if this has the right signature.
🌐
GitHub
github.com › bugsnag › llvm › blob › master › include › llvm › IR › IntrinsicInst.h
llvm/include/llvm/IR/IntrinsicInst.h at master · bugsnag/llvm
/// This class wraps the llvm.memset intrinsic. class MemSetInst : public MemIntrinsic { public: /// Return the arguments to the instruction. Value *getValue() const { return const_cast<Value*>(getArgOperand(1)); } const Use &getValueUse() const { return getArgOperandUse(1); } Use &getValueUse() { return getArgOperandUse(1); } ·
Author   bugsnag
🌐
GitHub
github.com › llvm-mirror › llvm › blob › master › lib › Transforms › Coroutines › CoroInstr.h
llvm/lib/Transforms/Coroutines/CoroInstr.h at master · llvm-mirror/llvm
return cast<ConstantInt>(getArgOperand(IndexArg)); } · // Methods to support type inquiry through isa, cast, and dyn_cast: static bool classof(const IntrinsicInst *I) { return I->getIntrinsicID() == Intrinsic::coro_subfn_addr; } static bool classof(const Value *V) { return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V)); } }; · /// This represents the llvm.coro.alloc instruction.
Author   llvm-mirror
🌐
GitHub
github.com › llvm › llvm-project › issues › 59757
-O2 Crash: InstrTypes.h:1352: llvm::Value* llvm::CallBase::getArgOperand(unsigned int) const: Assertion `i < arg_size() && "Out of bounds!"' failed. · Issue #59757 · llvm/llvm-project
December 31, 2022 - -O2 Crash: InstrTypes.h:1352: llvm::Value* llvm::CallBase::getArgOperand(unsigned int) const: Assertion `i < arg_size() && "Out of bounds!"' failed.#59757 · Copy link · Assignees · Labels · crashPrefer [crash-on-valid] or [crash-on-invalid]Prefer [crash-on-valid] or [crash-on-invalid]llvm:optimizations ·
Author   llvm
🌐
GitHub
github.com › llvm › llvm-project › issues › 56525
Crashed under O2 with "CoroInstr.h:186: void llvm::CoroIdInst::setCoroutineSelf(): Assertion `isa<ConstantPointerNull>(getArgOperand(CoroutineArg)) && "Coroutine argument is already assigned"' failed." · Issue #56525 · llvm/llvm-project
opt: /home/spica/GitRepo/llvm-project/llvm/lib/Transforms/Coroutines/CoroInstr.h:186: void llvm::CoroIdInst::setCoroutineSelf(): Assertion `isa<ConstantPointerNull>(getArgOperand(CoroutineArg)) && "Coroutine argument is already assigned"' failed. PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Author   llvm