[PATCH] D100353: Support nodebug in SCCP

David Blaikie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 12 17:15:54 PDT 2021


dblaikie created this revision.
dblaikie added a reviewer: fhahn.
Herald added a subscriber: hiraditya.
dblaikie requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Looks like any place this code checks for declarations it should also
check for the nodebug attribute to avoid doing any inter-functional
optimizations based on the contents of a nodebug function.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100353

Files:
  llvm/lib/Transforms/Scalar/SCCP.cpp
  llvm/test/Transforms/SCCP/nodebug.ll


Index: llvm/test/Transforms/SCCP/nodebug.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/SCCP/nodebug.ll
@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -ipsccp -instcombine -S | FileCheck %s
+
+attributes #0 = { noinline optnone }
+
+define i32 @callee() #0 {
+  ret i32 52
+}
+
+define i32 @caller() {
+  ; CHECK: define i32 @caller()
+  ; CHECK: ret i32 %X
+  %X = call i32 @callee()
+  ret i32 %X
+}
+
Index: llvm/lib/Transforms/Scalar/SCCP.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/SCCP.cpp
+++ llvm/lib/Transforms/Scalar/SCCP.cpp
@@ -1207,7 +1207,8 @@
 
   // Otherwise, if we have a single return value case, and if the function is
   // a declaration, maybe we can constant fold it.
-  if (F && F->isDeclaration() && canConstantFoldCallTo(&CB, F)) {
+  if (F && (F->isDeclaration() || F->hasOptNone()) &&
+      canConstantFoldCallTo(&CB, F)) {
     SmallVector<Constant *, 8> Operands;
     for (auto AI = CB.arg_begin(), E = CB.arg_end(); AI != E; ++AI) {
       if (AI->get()->getType()->isStructTy())
@@ -1380,7 +1381,7 @@
   // The common case is that we aren't tracking the callee, either because we
   // are not doing interprocedural analysis or the callee is indirect, or is
   // external.  Handle these cases first.
-  if (!F || F->isDeclaration())
+  if (!F || F->isDeclaration() || F->hasOptNone())
     return handleCallOverdefined(CB);
 
   // If this is a single/zero retval case, see if we're tracking the function.
@@ -1938,7 +1939,7 @@
   // Loop over all functions, marking arguments to those with their addresses
   // taken or that are external as overdefined.
   for (Function &F : M) {
-    if (F.isDeclaration())
+    if (F.isDeclaration() || F.hasOptNone())
       continue;
 
     Solver.addAnalysis(F, getAnalysis(F));
@@ -1992,7 +1993,7 @@
   // constants if we have found them to be of constant values.
 
   for (Function &F : M) {
-    if (F.isDeclaration())
+    if (F.isDeclaration() || F.hasOptNone())
       continue;
 
     SmallVector<BasicBlock *, 512> BlocksToErase;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100353.336998.patch
Type: text/x-patch
Size: 2198 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210413/a999029c/attachment.bin>


More information about the llvm-commits mailing list