[llvm] 3a6f3fc - Fix return status of SimplifyCFG
via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 4 22:54:43 PDT 2020
Author: serge-sans-paille
Date: 2020-09-05T07:54:15+02:00
New Revision: 3a6f3fc16039293920bfd6982052fd5fc14529e4
URL: https://github.com/llvm/llvm-project/commit/3a6f3fc16039293920bfd6982052fd5fc14529e4
DIFF: https://github.com/llvm/llvm-project/commit/3a6f3fc16039293920bfd6982052fd5fc14529e4.diff
LOG: Fix return status of SimplifyCFG
When a switch case is folded into default's case, that's an IR change that
should be reported, update ConstantFoldTerminator accordingly.
Differential Revision: https://reviews.llvm.org/D87142
Added:
llvm/test/Transforms/SimplifyCFG/merge-default.ll
Modified:
llvm/lib/Transforms/Utils/Local.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 2b0ae722458b..41349457e2b9 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -182,6 +182,8 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions,
TheOnlyDest = SI->case_begin()->getCaseSuccessor();
}
+ bool Changed = false;
+
// Figure out which case it goes to.
for (auto i = SI->case_begin(), e = SI->case_end(); i != e;) {
// Found case matching a constant operand?
@@ -220,6 +222,7 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions,
DefaultDest->removePredecessor(ParentBB);
i = SI->removeCase(i);
e = SI->case_end();
+ Changed = true;
if (DTU)
DTU->applyUpdatesPermissive(
{{DominatorTree::Delete, ParentBB, DefaultDest}});
@@ -308,7 +311,7 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions,
SI->eraseFromParent();
return true;
}
- return false;
+ return Changed;
}
if (auto *IBI = dyn_cast<IndirectBrInst>(T)) {
diff --git a/llvm/test/Transforms/SimplifyCFG/merge-default.ll b/llvm/test/Transforms/SimplifyCFG/merge-default.ll
new file mode 100644
index 000000000000..93b64d708807
--- /dev/null
+++ b/llvm/test/Transforms/SimplifyCFG/merge-default.ll
@@ -0,0 +1,45 @@
+; RUN: opt -simplifycfg -S < %s | FileCheck %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+declare void @g()
+declare void @f()
+
+define void @foo(i32 %Kind) {
+; CHECK-LABEL: @foo(
+; CHECK-NEXT:entry:
+; CHECK-NEXT: switch i32 %Kind, label %sw.epilog [
+; CHECK-NEXT: i32 15, label %sw.bb2
+; CHECK-NEXT: i32 2, label %sw.bb
+; CHECK-NEXT: ]
+; CHECK: sw.bb:
+; CHECK-NEXT: call void @g()
+; CHECK-NEXT: call void @g()
+; CHECK-NEXT: br label %sw.epilog
+; CHECK: sw.bb2:
+; CHECK-NEXT: call void @f()
+; CHECK-NEXT: br label %sw.epilog
+; CHECK: sw.epilog:
+; CHECK-NEXT: ret void
+; CHECK-NEXT:}
+
+entry:
+ switch i32 %Kind, label %sw.epilog [
+ i32 1, label %sw.epilog
+ i32 2, label %sw.bb
+ i32 15, label %sw.bb2
+ ]
+
+sw.bb:
+ call void @g()
+ call void @g()
+ br label %sw.epilog
+
+sw.bb2:
+ call void @f()
+ br label %sw.epilog
+
+sw.epilog:
+ ret void
+}
More information about the llvm-commits
mailing list