diff options
author | Nikita Popov <npopov@redhat.com> | 2022-07-21 12:10:36 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2022-07-21 12:39:35 +0200 |
commit | c81dff3c306dd1a26e5f6377a040f811c325ba76 (patch) | |
tree | cfedd4f206146a3f5999c3388f47dd72727ccb93 /llvm/lib/Transforms/Utils/Local.cpp | |
parent | d2a4d6bf9c52861f3d418bf7bb7d05f6e74dfead (diff) | |
download | llvm-c81dff3c306dd1a26e5f6377a040f811c325ba76.zip llvm-c81dff3c306dd1a26e5f6377a040f811c325ba76.tar.gz llvm-c81dff3c306dd1a26e5f6377a040f811c325ba76.tar.bz2 |
[MemoryBuiltins] Add getFreedOperand() function (NFCI)
We currently assume in a number of places that free-like functions
free their first argument. This is true for all hardcoded free-like
functions, but with the new attribute-based design, the freed
argument is supposed to be indicated by the allocptr attribute.
To make sure we handle this correctly once allockind(free) is
respected, add a getFreedOperand() helper which returns the freed
argument, rather than just indicating whether the call frees *some*
argument.
This migrates most but not all users of isFreeCall() to the new
API. The remaining users are a bit more tricky.
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 83e67b1..c1cf1f1 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -493,13 +493,13 @@ bool llvm::wouldInstructionBeTriviallyDead(Instruction *I, } } - if (CallInst *CI = isFreeCall(I, TLI)) - if (Constant *C = dyn_cast<Constant>(CI->getArgOperand(0))) - return C->isNullValue() || isa<UndefValue>(C); - - if (auto *Call = dyn_cast<CallBase>(I)) + if (auto *Call = dyn_cast<CallBase>(I)) { + if (Value *FreedOp = getFreedOperand(Call, TLI)) + if (Constant *C = dyn_cast<Constant>(FreedOp)) + return C->isNullValue() || isa<UndefValue>(C); if (isMathLibCallNoop(Call, TLI)) return true; + } // Non-volatile atomic loads from constants can be removed. if (auto *LI = dyn_cast<LoadInst>(I)) |