summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRodrigo Caetano Rocha <rcor.cs@gmail.com>2019-12-07 16:47:00 +0000
committerFlorian Hahn <flo@fhahn.com>2019-12-07 16:54:49 +0000
commitd714aa0dfdb16270fc279e8e91d4a83ace531529 (patch)
tree20cfa25ed25d3fbad2a1b80413ca41a9b084784e
parent071dca24cea9dcabe25cbe98c4053d874183be37 (diff)
downloadbcm5719-llvm-d714aa0dfdb16270fc279e8e91d4a83ace531529.tar.gz
bcm5719-llvm-d714aa0dfdb16270fc279e8e91d4a83ace531529.zip
[SimplifyCFG] Handle AssumptionCache being null.
AssumptionCache can be null in SimplifyCFGOptions. However, FoldCondBranchOnPHI() was not properly handling that when passing a null AssumptionCache to simplifyCFG. Patch by Rodrigo Caetano Rocha <rcor.cs@gmail.com> Reviewers: fhahn, lebedev.ri, spatel Reviewed By: spatel Differential Revision: https://reviews.llvm.org/D69963
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyCFG.cpp5
-rw-r--r--llvm/unittests/Transforms/Utils/LocalTest.cpp50
2 files changed, 52 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 79d4857c2c8..16044210f52 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -2274,9 +2274,8 @@ static bool FoldCondBranchOnPHI(BranchInst *BI, const DataLayout &DL,
EdgeBB->getInstList().insert(InsertPt, N);
// Register the new instruction with the assumption cache if necessary.
- if (auto *II = dyn_cast_or_null<IntrinsicInst>(N))
- if (II->getIntrinsicID() == Intrinsic::assume)
- AC->registerAssumption(II);
+ if (AC && match(N, m_Intrinsic<Intrinsic::assume>()))
+ AC->registerAssumption(cast<IntrinsicInst>(N));
}
// Loop over all of the edges from PredBB to BB, changing them to branch
diff --git a/llvm/unittests/Transforms/Utils/LocalTest.cpp b/llvm/unittests/Transforms/Utils/LocalTest.cpp
index 99713d5817f..5551a07beb9 100644
--- a/llvm/unittests/Transforms/Utils/LocalTest.cpp
+++ b/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"
@@ -951,3 +952,52 @@ TEST(Local, RemoveUnreachableBlocks) {
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 %test.bb
+ then.bb1:
+ call void @false_path()
+ br label %test.bb
+ test.bb:
+ %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:
+ ret i32 %1
+ then.bb2:
+ ret i32 0
+ }
+ )");
+
+ Function &F = *cast<Function>(M->getNamedValue("foo"));
+ TargetTransformInfo TTI(M->getDataLayout());
+
+ SimplifyCFGOptions Options{};
+ Options.setAssumptionCache(nullptr);
+
+ // Obtain BasicBlock of interest to this test, %test.bb.
+ BasicBlock *TestBB = nullptr;
+ for (BasicBlock &BB : F) {
+ if (BB.getName().equals("test.bb")) {
+ TestBB = &BB;
+ break;
+ }
+ }
+ ASSERT_TRUE(TestBB);
+
+ // %test.bb is expected to be simplified by FoldCondBranchOnPHI.
+ EXPECT_TRUE(simplifyCFG(TestBB, TTI, Options));
+}
OpenPOWER on IntegriCloud