[llvm] 8542d8f - [Attributor][FIX] Ensure the function manager cache is updated

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 9 20:12:59 PDT 2023


Author: Johannes Doerfert
Date: 2023-07-09T20:12:31-07:00
New Revision: 8542d8f3cdc269f3dd786cc88606f0cf39174665

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

LOG: [Attributor][FIX] Ensure the function manager cache is updated

When a function is removed we need to clear cached analysis from the
function manager cache.

Added: 
    llvm/test/Transforms/Attributor/reduced/clear_cached_analysis_for_deleted_functions.ll

Modified: 
    llvm/lib/Transforms/Utils/CallGraphUpdater.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/CallGraphUpdater.cpp b/llvm/lib/Transforms/Utils/CallGraphUpdater.cpp
index d0b89ba2606ea5..d0b9884aa9099b 100644
--- a/llvm/lib/Transforms/Utils/CallGraphUpdater.cpp
+++ b/llvm/lib/Transforms/Utils/CallGraphUpdater.cpp
@@ -120,6 +120,8 @@ void CallGraphUpdater::removeFunction(Function &DeadFn) {
     DeadCGN->removeAllCalledFunctions();
     CGSCC->DeleteNode(DeadCGN);
   }
+  if (FAM)
+    FAM->clear(DeadFn, DeadFn.getName());
 }
 
 void CallGraphUpdater::replaceFunctionWith(Function &OldFn, Function &NewFn) {

diff  --git a/llvm/test/Transforms/Attributor/reduced/clear_cached_analysis_for_deleted_functions.ll b/llvm/test/Transforms/Attributor/reduced/clear_cached_analysis_for_deleted_functions.ll
new file mode 100644
index 00000000000000..0bef8e18570498
--- /dev/null
+++ b/llvm/test/Transforms/Attributor/reduced/clear_cached_analysis_for_deleted_functions.ll
@@ -0,0 +1,33 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals
+; RUN: opt -aa-pipeline=basic-aa -passes="attributor-cgscc,argpromotion" -S < %s | FileCheck %s --check-prefixes=CGSCC
+
+; This used to crash because the attributor-cgscc pass rewrote the
+; flag_GetFlagValue function but did not clear the cached analysis for the
+; deleted function. Argument promotion got an invalid cache entry for the
+; dominator tree of list_Car and things exploded.
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define i32 @clause_LiteralComputeWeight(ptr %call23) {
+entry:
+  br label %do.body
+
+do.body:                                          ; preds = %do.body, %entry
+  %Term.0 = phi ptr [ null, %entry ], [ %call24, %do.body ]
+  %call2 = load volatile i32, ptr %Term.0, align 4
+  %call3 = call i32 @flag_GetFlagValue(ptr null)
+  %call24 = call ptr @list_Car(ptr %call23)
+  br label %do.body
+}
+
+define internal i32 @flag_GetFlagValue(ptr %Store) #1 {
+entry:
+  ret i32 0
+}
+
+define internal ptr @list_Car(ptr %L) #0 {
+entry:
+  %0 = load ptr, ptr %L, align 8
+  ret ptr %0
+}


        


More information about the llvm-commits mailing list