[llvm] 2a77544 - [SimplifyLibCalls] Erase replaced instructions

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 2 08:33:10 PDT 2020


I reverted this in dffc5031874edff22d4462ce665acd309ecb9cdc, it breaks
asan bots with a use after free as InstCombine still tries to query
the deleted value.

On Wed, Apr 1, 2020 at 8:00 PM Nikita Popov via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
>
>
> Author: Nikita Popov
> Date: 2020-04-01T20:00:10+02:00
> New Revision: 2a77544ad5911a38f81c0300385033fced1cc66d
>
> URL: https://github.com/llvm/llvm-project/commit/2a77544ad5911a38f81c0300385033fced1cc66d
> DIFF: https://github.com/llvm/llvm-project/commit/2a77544ad5911a38f81c0300385033fced1cc66d.diff
>
> LOG: [SimplifyLibCalls] Erase replaced instructions
>
> After RAUWing an instruction, also erase it. This makes sure we
> don't perform extra InstCombine iterations to clean up the garbage.
>
> Added:
>
>
> Modified:
>     llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
>
> Removed:
>
>
>
> ################################################################################
> diff  --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
> index 77fe6c1cb12a..10eb1212a591 100644
> --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
> +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
> @@ -832,6 +832,7 @@ Value *LibCallSimplifier::optimizeStrStr(CallInst *CI, IRBuilderBase &B) {
>            B.CreateICmp(Old->getPredicate(), StrNCmp,
>                         ConstantInt::getNullValue(StrNCmp->getType()), "cmp");
>        replaceAllUsesWith(Old, Cmp);
> +      eraseFromParent(Old);
>      }
>      return CI;
>    }
> @@ -2170,8 +2171,10 @@ Value *LibCallSimplifier::optimizeSinCosPi(CallInst *CI, IRBuilderBase &B) {
>
>    auto replaceTrigInsts = [this](SmallVectorImpl<CallInst *> &Calls,
>                                   Value *Res) {
> -    for (CallInst *C : Calls)
> +    for (CallInst *C : Calls) {
>        replaceAllUsesWith(C, Res);
> +      eraseFromParent(C);
> +    }
>    };
>
>    replaceTrigInsts(SinCalls, Sin);
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits


More information about the llvm-commits mailing list