[llvm] c3ca687 - [InstCombine] Don't simplify calls without uses

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 9 10:51:27 PDT 2020


Author: Nikita Popov
Date: 2020-03-09T18:47:46+01:00
New Revision: c3ca6876ed0cf833dfde681e18c37ed288bb554c

URL: https://github.com/llvm/llvm-project/commit/c3ca6876ed0cf833dfde681e18c37ed288bb554c
DIFF: https://github.com/llvm/llvm-project/commit/c3ca6876ed0cf833dfde681e18c37ed288bb554c.diff

LOG: [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

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
    llvm/test/Transforms/InstCombine/pr44245.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 1fcd8533f126..494626519c06 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);

diff  --git a/llvm/test/Transforms/InstCombine/pr44245.ll b/llvm/test/Transforms/InstCombine/pr44245.ll
index f7eb806ba4c6..f12bc3782f31 100644
--- a/llvm/test/Transforms/InstCombine/pr44245.ll
+++ b/llvm/test/Transforms/InstCombine/pr44245.ll
@@ -59,7 +59,7 @@ define void @test(i1 %c) {
 ; 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


        


More information about the llvm-commits mailing list