diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-03-07 20:21:09 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-03-09 18:47:46 +0100 |
commit | c3ca6876ed0cf833dfde681e18c37ed288bb554c (patch) | |
tree | f8ce13fffa692fd5329a3eb69c74fa59feb06d59 /llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | |
parent | 829d377a98fd3ee087935ea215677e49c8b51b27 (diff) | |
download | llvm-c3ca6876ed0cf833dfde681e18c37ed288bb554c.zip llvm-c3ca6876ed0cf833dfde681e18c37ed288bb554c.tar.gz llvm-c3ca6876ed0cf833dfde681e18c37ed288bb554c.tar.bz2 |
[InstCombine] Don't simplify calls without uses
When simplifying a call without uses, replaceInstUsesWith() is
going to do nothing, but we'll skip all following folds. We can
only run into this problem with calls that both simplify and are
not trivially dead if unused, which currently seems to happen only
with calls to undef, as the test diff shows. When extending
SimplifyCall() to handle "returned" attributes, this becomes a much
bigger problem, so I'm fixing this first.
Differential Revision: https://reviews.llvm.org/D75814
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 1fcd853..4946265 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -1787,8 +1787,11 @@ Instruction *InstCombiner::foldIntrinsicWithOverflowCommon(IntrinsicInst *II) { /// instructions. For normal calls, it allows visitCallBase to do the heavy /// lifting. Instruction *InstCombiner::visitCallInst(CallInst &CI) { - if (Value *V = SimplifyCall(&CI, SQ.getWithInstruction(&CI))) - return replaceInstUsesWith(CI, V); + // Don't try to simplify calls without uses. It will not do anything useful, + // but will result in the following folds being skipped. + if (!CI.use_empty()) + if (Value *V = SimplifyCall(&CI, SQ.getWithInstruction(&CI))) + return replaceInstUsesWith(CI, V); if (isFreeCall(&CI, &TLI)) return visitFree(CI); |