[PATCH] D69963: Handling null AssumptionCache in simplifyCFG

Rodrigo Caetano Rocha via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 7 16:55:53 PST 2019


rcorcs updated this revision to Diff 228340.
rcorcs added a comment.

Added test case that exercises this issue.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69963/new/

https://reviews.llvm.org/D69963

Files:
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/unittests/Transforms/Utils/LocalTest.cpp


Index: llvm/unittests/Transforms/Utils/LocalTest.cpp
===================================================================
--- llvm/unittests/Transforms/Utils/LocalTest.cpp
+++ llvm/unittests/Transforms/Utils/LocalTest.cpp
@@ -9,6 +9,7 @@
 #include "llvm/Transforms/Utils/Local.h"
 #include "llvm/Analysis/DomTreeUpdater.h"
 #include "llvm/Analysis/PostDominators.h"
+#include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/AsmParser/Parser.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/DIBuilder.h"
@@ -948,3 +949,52 @@
 
   runWithDomTree(*M, "f", checkRUBlocksRetVal);
 }
+
+TEST(Local, SimplifyCFGWithNullAC) {
+  LLVMContext Ctx;
+
+  std::unique_ptr<Module> M = parseIR(Ctx,
+                                      R"(
+    declare void @true_path()
+    declare void @false_path()
+    declare void @llvm.assume(i1 %cond);
+
+    define i32 @foo(i1, i32) {
+    entry:
+      %cmp = icmp sgt i32 %1, 0
+      br i1 %cmp, label %if.bb1, label %then.bb1
+    if.bb1:
+      call void @true_path()
+      br label %end.if1
+    then.bb1:
+      call void @false_path()
+      br label %end.if1
+    end.if1:
+      %phi = phi i1 [1, %if.bb1], [%0, %then.bb1]
+      call void @llvm.assume(i1 %0)
+      br i1 %phi, label %if.bb2, label %then.bb2
+    if.bb2:
+      call void @true_path()
+      ret i32 %1
+    then.bb2:
+      call void @false_path()
+      ret i32 0
+    }
+  )");
+
+  Function &F = *cast<Function>(M->getNamedValue("foo"));
+  TargetTransformInfo TTI(M->getDataLayout());
+
+  SimplifyCFGOptions Options{};
+  Options.setAssumptionCache(nullptr);
+  
+  bool Changed = false;
+  for (BasicBlock &BB : F) {
+    if (isa<PHINode>(&*BB.begin())) {
+      Changed = Changed || simplifyCFG(&BB, TTI, Options);
+      break;
+    }
+  }
+  
+  EXPECT_TRUE(Changed);
+}
Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -2269,7 +2269,7 @@
 
       // Register the new instruction with the assumption cache if necessary.
       if (auto *II = dyn_cast_or_null<IntrinsicInst>(N))
-        if (II->getIntrinsicID() == Intrinsic::assume)
+        if (AC && II->getIntrinsicID() == Intrinsic::assume)
           AC->registerAssumption(II);
     }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69963.228340.patch
Type: text/x-patch
Size: 2338 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191108/59665ac5/attachment-0001.bin>


More information about the llvm-commits mailing list