[llvm] 378f4e5 - [AssumptionCache] Do not track llvm.assume calls (PR49043)

Johannes Doerfert via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 6 10:18:37 PST 2021


Author: Johannes Doerfert
Date: 2021-02-06T12:18:30-06:00
New Revision: 378f4e5ec26c3e0d2119c1112ec645b369eed2de

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

LOG: [AssumptionCache] Do not track llvm.assume calls (PR49043)

This fixes PR49043 by invalidating the handle on RAUW. This will work
fine assuming all existing RAUW users add the new assumption to the
cache. That means, if a new llvm.assume call replaces an old one, you
need to add the new one now as a RAUW is not enough anymore.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D96208

Added: 
    llvm/test/Transforms/GVNSink/assumption.ll

Modified: 
    llvm/include/llvm/Analysis/AssumptionCache.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Analysis/AssumptionCache.h b/llvm/include/llvm/Analysis/AssumptionCache.h
index 0ef63dc68e1c..c4602d3449c0 100644
--- a/llvm/include/llvm/Analysis/AssumptionCache.h
+++ b/llvm/include/llvm/Analysis/AssumptionCache.h
@@ -45,7 +45,7 @@ class AssumptionCache {
   enum : unsigned { ExprResultIdx = std::numeric_limits<unsigned>::max() };
 
   struct ResultElem {
-    WeakTrackingVH Assume;
+    WeakVH Assume;
 
     /// contains either ExprResultIdx or the index of the operand bundle
     /// containing the knowledge.

diff  --git a/llvm/test/Transforms/GVNSink/assumption.ll b/llvm/test/Transforms/GVNSink/assumption.ll
new file mode 100644
index 000000000000..6b3d832435dc
--- /dev/null
+++ b/llvm/test/Transforms/GVNSink/assumption.ll
@@ -0,0 +1,32 @@
+; RUN: opt < %s -S -passes="print<assumptions>,gvn-sink,loop-unroll" -unroll-count=3 | FileCheck %s
+;
+; This crashed because the cached assumption was replaced and the replacement
+; was then in the cache twice.
+;
+; PR49043
+
+ at g = external global i32
+
+define void @main() {
+bb:
+  %i1.i = load volatile i32, i32* @g
+  %i32.i = icmp eq i32 %i1.i, 0
+  call void @llvm.assume(i1 %i32.i) #3
+  br label %bb4.i
+
+bb4.i:                                            ; preds = %bb4.i, %bb
+  %i.i = load volatile i32, i32* @g
+  %i3.i = icmp eq i32 %i.i, 0
+  call void @llvm.assume(i1 %i3.i) #3
+  br label %bb4.i
+
+func_1.exit:                                      ; No predecessors!
+  unreachable
+}
+
+declare void @llvm.assume(i1)
+
+; CHECK:  call void @llvm.assume(
+; CHECK:  call void @llvm.assume(
+; CHECK:  call void @llvm.assume(
+


        


More information about the llvm-commits mailing list