[PATCH] D75814: [InstCombine] Don't simplify calls without uses
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 7 12:28:17 PST 2020
nikic created this revision.
nikic added reviewers: spatel, lebedev.ri, xbolva00.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D75814
Files:
lib/Transforms/InstCombine/InstCombineCalls.cpp
test/Transforms/InstCombine/pr44245.ll
Index: test/Transforms/InstCombine/pr44245.ll
===================================================================
--- test/Transforms/InstCombine/pr44245.ll
+++ test/Transforms/InstCombine/pr44245.ll
@@ -59,7 +59,7 @@
; CHECK-NEXT: br label [[BB47]]
; CHECK: bb152:
; CHECK-NEXT: [[TMP1848]] = load i8*, i8** inttoptr (i64 16 to i8**), align 16
-; CHECK-NEXT: call void undef()
+; CHECK-NEXT: store i1 true, i1* undef, align 1
; CHECK-NEXT: br label [[BB150]]
;
bb16: ; preds = %bb
Index: lib/Transforms/InstCombine/InstCombineCalls.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1787,8 +1787,11 @@
/// 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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75814.248953.patch
Type: text/x-patch
Size: 1389 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200307/2672250f/attachment.bin>
More information about the llvm-commits
mailing list