summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorJan Vesely <jan.vesely@rutgers.edu>2014-08-13 20:31:53 +0000
committerJan Vesely <jan.vesely@rutgers.edu>2014-08-13 20:31:53 +0000
commit0cd3ec6cfa8c191efb4d6b517bc0b251107b54e7 (patch)
treeb3509a454761ad3ce52f1231c3200567994542e9 /llvm
parent5a956d49f7515694a1b3777e2b372e11e9ff0198 (diff)
downloadbcm5719-llvm-0cd3ec6cfa8c191efb4d6b517bc0b251107b54e7.tar.gz
bcm5719-llvm-0cd3ec6cfa8c191efb4d6b517bc0b251107b54e7.zip
utils: Fix segfault in flattencfg
v2: continue iterating through the rest of the bb use for loop v3: initialize FlattenCFG pass in ScalarOps add test v4: split off initializing flattencfg to a separate patch add comment Signed-off-by: Jan Vesely <jan.vesely@rutgers.edu> llvm-svn: 215574
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Transforms/Utils/FlattenCFG.cpp9
-rw-r--r--llvm/test/Transforms/Util/flattencfg.ll26
2 files changed, 31 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/Utils/FlattenCFG.cpp b/llvm/lib/Transforms/Utils/FlattenCFG.cpp
index 51ead40c916..4eb3e3dd17d 100644
--- a/llvm/lib/Transforms/Utils/FlattenCFG.cpp
+++ b/llvm/lib/Transforms/Utils/FlattenCFG.cpp
@@ -238,9 +238,13 @@ bool FlattenCFGOpt::FlattenParallelAndOr(BasicBlock *BB, IRBuilder<> &Builder,
// Do branch inversion.
BasicBlock *CurrBlock = LastCondBlock;
bool EverChanged = false;
- while (1) {
+ for (;CurrBlock != FirstCondBlock;
+ CurrBlock = CurrBlock->getSinglePredecessor()) {
BranchInst *BI = dyn_cast<BranchInst>(CurrBlock->getTerminator());
CmpInst *CI = dyn_cast<CmpInst>(BI->getCondition());
+ if (!CI)
+ continue;
+
CmpInst::Predicate Predicate = CI->getPredicate();
// Canonicalize icmp_ne -> icmp_eq, fcmp_one -> fcmp_oeq
if ((Predicate == CmpInst::ICMP_NE) || (Predicate == CmpInst::FCMP_ONE)) {
@@ -248,9 +252,6 @@ bool FlattenCFGOpt::FlattenParallelAndOr(BasicBlock *BB, IRBuilder<> &Builder,
BI->swapSuccessors();
EverChanged = true;
}
- if (CurrBlock == FirstCondBlock)
- break;
- CurrBlock = CurrBlock->getSinglePredecessor();
}
return EverChanged;
}
diff --git a/llvm/test/Transforms/Util/flattencfg.ll b/llvm/test/Transforms/Util/flattencfg.ll
new file mode 100644
index 00000000000..4fcb77ab023
--- /dev/null
+++ b/llvm/test/Transforms/Util/flattencfg.ll
@@ -0,0 +1,26 @@
+; RUN: opt -flattencfg -S < %s | FileCheck %s
+
+
+; This test checks whether the pass completes without a crash.
+; The code is not transformed in any way
+;
+; CHECK-LABEL: @test_not_crash
+define void @test_not_crash(i32 %in_a) #0 {
+entry:
+ %cmp0 = icmp eq i32 %in_a, -1
+ %cmp1 = icmp ne i32 %in_a, 0
+ %cond0 = and i1 %cmp0, %cmp1
+ br i1 %cond0, label %b0, label %b1
+
+b0: ; preds = %entry
+ %cmp2 = icmp eq i32 %in_a, 0
+ %cmp3 = icmp ne i32 %in_a, 1
+ %cond1 = or i1 %cmp2, %cmp3
+ br i1 %cond1, label %exit, label %b1
+
+b1: ; preds = %entry, %b0
+ br label %exit
+
+exit: ; preds = %entry, %b0, %b1
+ ret void
+}
OpenPOWER on IntegriCloud