|
9 | 9 | #include "llvm/Transforms/Utils/Local.h"
|
10 | 10 | #include "llvm/Analysis/DomTreeUpdater.h"
|
11 | 11 | #include "llvm/Analysis/PostDominators.h"
|
| 12 | +#include "llvm/Analysis/TargetTransformInfo.h" |
12 | 13 | #include "llvm/AsmParser/Parser.h"
|
13 | 14 | #include "llvm/IR/BasicBlock.h"
|
14 | 15 | #include "llvm/IR/DIBuilder.h"
|
@@ -951,3 +952,52 @@ TEST(Local, RemoveUnreachableBlocks) {
|
951 | 952 |
|
952 | 953 | runWithDomTree(*M, "f", checkRUBlocksRetVal);
|
953 | 954 | }
|
| 955 | + |
| 956 | +TEST(Local, SimplifyCFGWithNullAC) { |
| 957 | + LLVMContext Ctx; |
| 958 | + |
| 959 | + std::unique_ptr<Module> M = parseIR(Ctx, R"( |
| 960 | + declare void @true_path() |
| 961 | + declare void @false_path() |
| 962 | + declare void @llvm.assume(i1 %cond); |
| 963 | +
|
| 964 | + define i32 @foo(i1, i32) { |
| 965 | + entry: |
| 966 | + %cmp = icmp sgt i32 %1, 0 |
| 967 | + br i1 %cmp, label %if.bb1, label %then.bb1 |
| 968 | + if.bb1: |
| 969 | + call void @true_path() |
| 970 | + br label %test.bb |
| 971 | + then.bb1: |
| 972 | + call void @false_path() |
| 973 | + br label %test.bb |
| 974 | + test.bb: |
| 975 | + %phi = phi i1 [1, %if.bb1], [%0, %then.bb1] |
| 976 | + call void @llvm.assume(i1 %0) |
| 977 | + br i1 %phi, label %if.bb2, label %then.bb2 |
| 978 | + if.bb2: |
| 979 | + ret i32 %1 |
| 980 | + then.bb2: |
| 981 | + ret i32 0 |
| 982 | + } |
| 983 | + )"); |
| 984 | + |
| 985 | + Function &F = *cast<Function>(M->getNamedValue("foo")); |
| 986 | + TargetTransformInfo TTI(M->getDataLayout()); |
| 987 | + |
| 988 | + SimplifyCFGOptions Options{}; |
| 989 | + Options.setAssumptionCache(nullptr); |
| 990 | + |
| 991 | + // Obtain BasicBlock of interest to this test, %test.bb. |
| 992 | + BasicBlock *TestBB = nullptr; |
| 993 | + for (BasicBlock &BB : F) { |
| 994 | + if (BB.getName().equals("test.bb")) { |
| 995 | + TestBB = &BB; |
| 996 | + break; |
| 997 | + } |
| 998 | + } |
| 999 | + ASSERT_TRUE(TestBB); |
| 1000 | + |
| 1001 | + // %test.bb is expected to be simplified by FoldCondBranchOnPHI. |
| 1002 | + EXPECT_TRUE(simplifyCFG(TestBB, TTI, Options)); |
| 1003 | +} |
0 commit comments