[PATCH] D108123: [Local] Move isFreeCall() before willReturn()

guopeilin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 16 05:00:18 PDT 2021


guopeilin created this revision.
guopeilin added reviewers: wwei, mdchen, fhahn, nikic, efriedma, jdoerfert.
Herald added a subscriber: hiraditya.
guopeilin requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Information about the willreturn() judgment condition is
introduced: https://reviews.llvm.org/D94106. I find no
discussion of where this condition is added.

      

Some FreeCall instructions should be judged dead here,
but it doesn't initially add the willreturn attribute,
so is intercepted by the willReturn() conditional branch.
Maybe we can move the judgment isFreeCall() before
willReturn().


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108123

Files:
  llvm/lib/Transforms/Utils/Local.cpp
  llvm/test/Transforms/InstCombine/free-undef.ll


Index: llvm/test/Transforms/InstCombine/free-undef.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/InstCombine/free-undef.ll
@@ -0,0 +1,35 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -instcombine -S -o - | FileCheck %s -check-prefix=INSTCOMBINE
+; RUN: opt < %s -instcombine -simplifycfg -S -o - | FileCheck %s -check-prefix=SIMPLIFYCFG
+
+; Function Attrs: mustprogress nounwind uwtable
+define dso_local i32 @_Z4funcv() local_unnamed_addr {
+; CHECK-LABEL: @_Z4funcv(
+;
+; INSTCOMBINE-LABEL: @_Z4funcv(
+; INSTCOMBINE-NOT:    store
+;
+; SIMPLIFYCFG-LABEL: @_Z4funcv(
+; SIMPLIFYCFG-NOT:    unreachable
+;
+entry:
+  br label %delete.notnull
+
+delete.notnull:                                   ; preds = %entry
+  call void @_ZdlPv(i8* undef)
+  br label %delete.end
+
+delete.end:                                       ; preds = %delete.notnull
+  ret i32 1
+}
+
+; Function Attrs: nobuiltin nounwind
+declare dso_local void @_ZdlPv(i8*) local_unnamed_addr
+
+; Function Attrs: mustprogress norecurse nounwind uwtable
+define dso_local i32 @main() local_unnamed_addr {
+entry:
+  %call = call i32 @_Z4funcv()
+  ret i32 0
+}
+
Index: llvm/lib/Transforms/Utils/Local.cpp
===================================================================
--- llvm/lib/Transforms/Utils/Local.cpp
+++ llvm/lib/Transforms/Utils/Local.cpp
@@ -430,6 +430,10 @@
     return true;
   }
 
+  if (CallInst *CI = isFreeCall(I, TLI))
+    if (Constant *C = dyn_cast<Constant>(CI->getArgOperand(0)))
+      return C->isNullValue() || isa<UndefValue>(C);
+
   if (!I->willReturn())
     return false;
 
@@ -483,10 +487,6 @@
   if (isAllocLikeFn(I, TLI))
     return true;
 
-  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 (isMathLibCallNoop(Call, TLI))
       return true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108123.366594.patch
Type: text/x-patch
Size: 2027 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210816/e307a8fd/attachment.bin>


More information about the llvm-commits mailing list