[llvm] 04b729d - [NFCI][SimplifyCFG] Guard common code hoisting with a (default-on) flag
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 20 00:30:24 PDT 2020
Author: Roman Lebedev
Date: 2020-07-20T10:29:57+03:00
New Revision: 04b729d076af038c2a86b62c0c150e340bf7a622
URL: https://github.com/llvm/llvm-project/commit/04b729d076af038c2a86b62c0c150e340bf7a622
DIFF: https://github.com/llvm/llvm-project/commit/04b729d076af038c2a86b62c0c150e340bf7a622.diff
LOG: [NFCI][SimplifyCFG] Guard common code hoisting with a (default-on) flag
Common code sinking is already guarded with a (with default-off!) flag,
so add a flag for hoisting, too.
D84108 will hopefully make hoisting off-by-default too.
Added:
Modified:
llvm/include/llvm/Transforms/Utils/SimplifyCFGOptions.h
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/test/Transforms/GVNSink/indirect-call.ll
llvm/test/Transforms/GVNSink/sink-common-code.ll
llvm/test/Transforms/SimplifyCFG/2008-12-16-DCECond.ll
llvm/test/Transforms/SimplifyCFG/AArch64/prefer-fma.ll
llvm/test/Transforms/SimplifyCFG/BrUnwind.ll
llvm/test/Transforms/SimplifyCFG/HoistCode.ll
llvm/test/Transforms/SimplifyCFG/PowerPC/prefer-fma.ll
llvm/test/Transforms/SimplifyCFG/PowerPC/prefer-load-i32.ll
llvm/test/Transforms/SimplifyCFG/UncondBranchToReturn.ll
llvm/test/Transforms/SimplifyCFG/X86/empty-cleanuppad.ll
llvm/test/Transforms/SimplifyCFG/X86/pr39187-g.ll
llvm/test/Transforms/SimplifyCFG/X86/remove-debug.ll
llvm/test/Transforms/SimplifyCFG/common-code-hoisting.ll
llvm/test/Transforms/SimplifyCFG/hoist-common-code.ll
llvm/test/Transforms/SimplifyCFG/hoist-dbgvalue-inlined.ll
llvm/test/Transforms/SimplifyCFG/hoist-with-range.ll
llvm/test/Transforms/SimplifyCFG/pr39807.ll
llvm/test/Transforms/SimplifyCFG/preserve-load-metadata-2.ll
llvm/test/Transforms/SimplifyCFG/preserve-load-metadata-3.ll
llvm/test/Transforms/SimplifyCFG/preserve-load-metadata.ll
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/Utils/SimplifyCFGOptions.h b/llvm/include/llvm/Transforms/Utils/SimplifyCFGOptions.h
index ca9a7e7223db..46f6ca0462f8 100644
--- a/llvm/include/llvm/Transforms/Utils/SimplifyCFGOptions.h
+++ b/llvm/include/llvm/Transforms/Utils/SimplifyCFGOptions.h
@@ -25,6 +25,7 @@ struct SimplifyCFGOptions {
bool ForwardSwitchCondToPhi = false;
bool ConvertSwitchToLookupTable = false;
bool NeedCanonicalLoop = true;
+ bool HoistCommonInsts = true;
bool SinkCommonInsts = false;
bool SimplifyCondBranch = true;
bool FoldTwoEntryPHINode = true;
@@ -48,6 +49,10 @@ struct SimplifyCFGOptions {
NeedCanonicalLoop = B;
return *this;
}
+ SimplifyCFGOptions &hoistCommonInsts(bool B) {
+ HoistCommonInsts = B;
+ return *this;
+ }
SimplifyCFGOptions &sinkCommonInsts(bool B) {
SinkCommonInsts = B;
return *this;
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 1766e579c33d..76c3c8a90f2d 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -1763,6 +1763,8 @@ Expected<SimplifyCFGOptions> parseSimplifyCFGOptions(StringRef Params) {
Result.convertSwitchToLookupTable(Enable);
} else if (ParamName == "keep-loops") {
Result.needCanonicalLoops(Enable);
+ } else if (ParamName == "hoist-common-insts") {
+ Result.hoistCommonInsts(Enable);
} else if (ParamName == "sink-common-insts") {
Result.sinkCommonInsts(Enable);
} else if (Enable && ParamName.consume_front("bonus-inst-threshold=")) {
diff --git a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
index 99055b991805..db5211df397a 100644
--- a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
+++ b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
@@ -62,6 +62,10 @@ static cl::opt<bool> UserForwardSwitchCond(
"forward-switch-cond", cl::Hidden, cl::init(false),
cl::desc("Forward switch condition to phi ops (default = false)"));
+static cl::opt<bool> UserHoistCommonInsts(
+ "hoist-common-insts", cl::Hidden, cl::init(true),
+ cl::desc("hoist common instructions (default = true)"));
+
static cl::opt<bool> UserSinkCommonInsts(
"sink-common-insts", cl::Hidden, cl::init(false),
cl::desc("Sink common instructions (default = false)"));
@@ -222,6 +226,8 @@ static void applyCommandLineOverridesToOptions(SimplifyCFGOptions &Options) {
Options.ConvertSwitchToLookupTable = UserSwitchToLookup;
if (UserKeepLoops.getNumOccurrences())
Options.NeedCanonicalLoop = UserKeepLoops;
+ if (UserHoistCommonInsts.getNumOccurrences())
+ Options.HoistCommonInsts = UserHoistCommonInsts;
if (UserSinkCommonInsts.getNumOccurrences())
Options.SinkCommonInsts = UserSinkCommonInsts;
}
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index aa015ffe5622..cc6bf9e864d0 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -105,6 +105,10 @@ static cl::opt<bool> DupRet(
"simplifycfg-dup-ret", cl::Hidden, cl::init(false),
cl::desc("Duplicate return instructions into unconditional branches"));
+static cl::opt<bool>
+ HoistCommon("simplifycfg-hoist-common", cl::Hidden, cl::init(true),
+ cl::desc("Hoist common instructions up to the parent block"));
+
static cl::opt<bool>
SinkCommon("simplifycfg-sink-common", cl::Hidden, cl::init(true),
cl::desc("Sink common instructions down to the end block"));
@@ -6063,8 +6067,9 @@ bool SimplifyCFGOpt::simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
// can hoist it up to the branching block.
if (BI->getSuccessor(0)->getSinglePredecessor()) {
if (BI->getSuccessor(1)->getSinglePredecessor()) {
- if (HoistThenElseCodeToIf(BI, TTI))
- return requestResimplify();
+ if (HoistCommon && Options.HoistCommonInsts)
+ if (HoistThenElseCodeToIf(BI, TTI))
+ return requestResimplify();
} else {
// If Successor #1 has multiple preds, we may be able to conditionally
// execute Successor #0 if it branches to Successor #1.
diff --git a/llvm/test/Transforms/GVNSink/indirect-call.ll b/llvm/test/Transforms/GVNSink/indirect-call.ll
index 57b7297c84bd..66c1a4f647a9 100644
--- a/llvm/test/Transforms/GVNSink/indirect-call.ll
+++ b/llvm/test/Transforms/GVNSink/indirect-call.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -gvn-sink -simplifycfg -simplifycfg-sink-common=false -S | FileCheck %s
+; RUN: opt < %s -gvn-sink -simplifycfg -hoist-common-insts=true -simplifycfg-sink-common=false -S | FileCheck %s
declare i8 @ext(i1)
diff --git a/llvm/test/Transforms/GVNSink/sink-common-code.ll b/llvm/test/Transforms/GVNSink/sink-common-code.ll
index 293e0daff5fb..4131fb37485f 100644
--- a/llvm/test/Transforms/GVNSink/sink-common-code.ll
+++ b/llvm/test/Transforms/GVNSink/sink-common-code.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -gvn-sink -simplifycfg -simplifycfg-sink-common=false -S | FileCheck %s
+; RUN: opt < %s -gvn-sink -simplifycfg -hoist-common-insts=true -simplifycfg-sink-common=false -S | FileCheck %s
define zeroext i1 @test1(i1 zeroext %flag, i32 %blksA, i32 %blksB, i32 %nblks) {
entry:
diff --git a/llvm/test/Transforms/SimplifyCFG/2008-12-16-DCECond.ll b/llvm/test/Transforms/SimplifyCFG/2008-12-16-DCECond.ll
index 4fc21d942237..2e356df75ca2 100644
--- a/llvm/test/Transforms/SimplifyCFG/2008-12-16-DCECond.ll
+++ b/llvm/test/Transforms/SimplifyCFG/2008-12-16-DCECond.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -simplifycfg -S | not grep icmp
+; RUN: opt < %s -simplifycfg -S -hoist-common-insts=true | not grep icmp
; ModuleID = '/tmp/x.bc'
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
target triple = "i686-pc-linux-gnu"
diff --git a/llvm/test/Transforms/SimplifyCFG/AArch64/prefer-fma.ll b/llvm/test/Transforms/SimplifyCFG/AArch64/prefer-fma.ll
index 7144da2d4bce..f9a571418b32 100644
--- a/llvm/test/Transforms/SimplifyCFG/AArch64/prefer-fma.ll
+++ b/llvm/test/Transforms/SimplifyCFG/AArch64/prefer-fma.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -mtriple=aarch64-linux-gnu -simplifycfg -enable-unsafe-fp-math -S >%t
+; RUN: opt < %s -mtriple=aarch64-linux-gnu -simplifycfg -hoist-common-insts=true -enable-unsafe-fp-math -S >%t
; RUN: FileCheck %s < %t
; ModuleID = 't.cc'
diff --git a/llvm/test/Transforms/SimplifyCFG/BrUnwind.ll b/llvm/test/Transforms/SimplifyCFG/BrUnwind.ll
index 14853642c09a..6cd3ad6e4b02 100644
--- a/llvm/test/Transforms/SimplifyCFG/BrUnwind.ll
+++ b/llvm/test/Transforms/SimplifyCFG/BrUnwind.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -simplifycfg -S | \
+; RUN: opt < %s -simplifycfg -hoist-common-insts=true -S | \
; RUN: not grep "br label"
define void @test(i1 %C) {
diff --git a/llvm/test/Transforms/SimplifyCFG/HoistCode.ll b/llvm/test/Transforms/SimplifyCFG/HoistCode.ll
index 575cb4f19eb7..051d66ee752f 100644
--- a/llvm/test/Transforms/SimplifyCFG/HoistCode.ll
+++ b/llvm/test/Transforms/SimplifyCFG/HoistCode.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt < %s -simplifycfg -S | FileCheck %s
+; RUN: opt < %s -simplifycfg -hoist-common-insts=true -S | FileCheck %s
define void @foo(i1 %C, i32* %P) {
; CHECK-LABEL: @foo(
diff --git a/llvm/test/Transforms/SimplifyCFG/PowerPC/prefer-fma.ll b/llvm/test/Transforms/SimplifyCFG/PowerPC/prefer-fma.ll
index 93fe8a201907..7a6ad85dbd6b 100644
--- a/llvm/test/Transforms/SimplifyCFG/PowerPC/prefer-fma.ll
+++ b/llvm/test/Transforms/SimplifyCFG/PowerPC/prefer-fma.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-; RUN: opt < %s -mtriple=powerpc64le-unknown-linux-gnu -simplifycfg -enable-unsafe-fp-math -S | \
+; RUN: opt < %s -mtriple=powerpc64le-unknown-linux-gnu -simplifycfg -hoist-common-insts=true -enable-unsafe-fp-math -S | \
; RUN: FileCheck %s
; This case is copied from test/Transforms/SimplifyCFG/AArch64/
diff --git a/llvm/test/Transforms/SimplifyCFG/PowerPC/prefer-load-i32.ll b/llvm/test/Transforms/SimplifyCFG/PowerPC/prefer-load-i32.ll
index 943fcba57c65..b1e1d85faf29 100644
--- a/llvm/test/Transforms/SimplifyCFG/PowerPC/prefer-load-i32.ll
+++ b/llvm/test/Transforms/SimplifyCFG/PowerPC/prefer-load-i32.ll
@@ -1,5 +1,4 @@
-; RUN: opt < %s -mtriple=powerpc64le-unknown-linux-gnu -simplifycfg -S | \
-; RUN: FileCheck %s
+; RUN: opt < %s -mtriple=powerpc64le-unknown-linux-gnu -simplifycfg -hoist-common-insts=true -S | FileCheck %s
define float @foo(float* %src, float* %dest, i32 signext %count, i32 signext %cond) {
; CHECK-LABEL: @foo(
diff --git a/llvm/test/Transforms/SimplifyCFG/UncondBranchToReturn.ll b/llvm/test/Transforms/SimplifyCFG/UncondBranchToReturn.ll
index b6d54d32566b..78bcd345daf9 100644
--- a/llvm/test/Transforms/SimplifyCFG/UncondBranchToReturn.ll
+++ b/llvm/test/Transforms/SimplifyCFG/UncondBranchToReturn.ll
@@ -2,7 +2,7 @@
; a PHI node and a return. Make sure the simplify cfg can straighten out this
; important case. This is basically the most trivial form of tail-duplication.
-; RUN: opt < %s -simplifycfg -S | \
+; RUN: opt < %s -simplifycfg -hoist-common-insts=true -S | \
; RUN: not grep "br label"
define i32 @test(i1 %B, i32 %A, i32 %B.upgrd.1) {
diff --git a/llvm/test/Transforms/SimplifyCFG/X86/empty-cleanuppad.ll b/llvm/test/Transforms/SimplifyCFG/X86/empty-cleanuppad.ll
index f9b6e6388339..ce7621908ff0 100644
--- a/llvm/test/Transforms/SimplifyCFG/X86/empty-cleanuppad.ll
+++ b/llvm/test/Transforms/SimplifyCFG/X86/empty-cleanuppad.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -simplifycfg -S | FileCheck %s
+; RUN: opt < %s -simplifycfg -S -hoist-common-insts=true | FileCheck %s
; ModuleID = 'cppeh-simplify.cpp'
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
diff --git a/llvm/test/Transforms/SimplifyCFG/X86/pr39187-g.ll b/llvm/test/Transforms/SimplifyCFG/X86/pr39187-g.ll
index 2c9dcc5dfff3..1013fab20d1c 100644
--- a/llvm/test/Transforms/SimplifyCFG/X86/pr39187-g.ll
+++ b/llvm/test/Transforms/SimplifyCFG/X86/pr39187-g.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -S -simplifycfg | FileCheck %s
+; RUN: opt < %s -S -simplifycfg -hoist-common-insts=true | FileCheck %s
; SimplifyCFG can hoist any common code in the 'then' and 'else' blocks to
; the 'if' basic block.
diff --git a/llvm/test/Transforms/SimplifyCFG/X86/remove-debug.ll b/llvm/test/Transforms/SimplifyCFG/X86/remove-debug.ll
index 2da7caf157e3..7a69e05267e2 100644
--- a/llvm/test/Transforms/SimplifyCFG/X86/remove-debug.ll
+++ b/llvm/test/Transforms/SimplifyCFG/X86/remove-debug.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -simplifycfg -S | FileCheck %s
+; RUN: opt < %s -simplifycfg -S -hoist-common-insts=true | FileCheck %s
; TODO: Track the acutal DebugLoc of the hoisted instruction when no-line
; DebugLoc is supported (https://reviews.llvm.org/D24180)
diff --git a/llvm/test/Transforms/SimplifyCFG/common-code-hoisting.ll b/llvm/test/Transforms/SimplifyCFG/common-code-hoisting.ll
index c44676bdf0cc..b58017ba7ef0 100644
--- a/llvm/test/Transforms/SimplifyCFG/common-code-hoisting.ll
+++ b/llvm/test/Transforms/SimplifyCFG/common-code-hoisting.ll
@@ -1,4 +1,6 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -simplifycfg -hoist-common-insts=1 -S < %s | FileCheck %s --check-prefixes=HOIST
+; RUN: opt -simplifycfg -hoist-common-insts=0 -S < %s | FileCheck %s --check-prefixes=NOHOIST
; RUN: opt -simplifycfg -S < %s | FileCheck %s --check-prefixes=HOIST,DEFAULT
; This example is produced from a very basic C code:
@@ -57,6 +59,23 @@ define void @_Z4loopi(i1 %cmp) {
; HOIST: return:
; HOIST-NEXT: ret void
;
+; NOHOIST-LABEL: @_Z4loopi(
+; NOHOIST-NEXT: entry:
+; NOHOIST-NEXT: br i1 [[CMP:%.*]], label [[RETURN:%.*]], label [[FOR_COND:%.*]]
+; NOHOIST: for.cond:
+; NOHOIST-NEXT: [[CMP1:%.*]] = call i1 @gen1()
+; NOHOIST-NEXT: br i1 [[CMP1]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
+; NOHOIST: for.body:
+; NOHOIST-NEXT: call void @f0()
+; NOHOIST-NEXT: call void @f1()
+; NOHOIST-NEXT: br label [[FOR_COND]]
+; NOHOIST: for.end:
+; NOHOIST-NEXT: call void @f0()
+; NOHOIST-NEXT: call void @f2()
+; NOHOIST-NEXT: br label [[RETURN]]
+; NOHOIST: return:
+; NOHOIST-NEXT: ret void
+;
entry:
br i1 %cmp, label %if.then, label %if.end
diff --git a/llvm/test/Transforms/SimplifyCFG/hoist-common-code.ll b/llvm/test/Transforms/SimplifyCFG/hoist-common-code.ll
index c1ca605cc206..958cd35a172f 100644
--- a/llvm/test/Transforms/SimplifyCFG/hoist-common-code.ll
+++ b/llvm/test/Transforms/SimplifyCFG/hoist-common-code.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -simplifycfg -S | not grep br
+; RUN: opt < %s -simplifycfg -S -hoist-common-insts=true | not grep br
declare void @bar(i32)
diff --git a/llvm/test/Transforms/SimplifyCFG/hoist-dbgvalue-inlined.ll b/llvm/test/Transforms/SimplifyCFG/hoist-dbgvalue-inlined.ll
index 968c6fd01f4a..c2fc73f3c7ea 100644
--- a/llvm/test/Transforms/SimplifyCFG/hoist-dbgvalue-inlined.ll
+++ b/llvm/test/Transforms/SimplifyCFG/hoist-dbgvalue-inlined.ll
@@ -1,4 +1,4 @@
-; RUN: opt -simplifycfg -S < %s | FileCheck %s
+; RUN: opt -simplifycfg -hoist-common-insts=true -S < %s | FileCheck %s
; Verify that we don't crash due an invalid !dbg location on the hoisted llvm.dbg.value
define i64 @caller(i64* %ptr, i64 %flag) !dbg !10 {
diff --git a/llvm/test/Transforms/SimplifyCFG/hoist-with-range.ll b/llvm/test/Transforms/SimplifyCFG/hoist-with-range.ll
index 6c12971167a5..82d4538bcbeb 100644
--- a/llvm/test/Transforms/SimplifyCFG/hoist-with-range.ll
+++ b/llvm/test/Transforms/SimplifyCFG/hoist-with-range.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -simplifycfg -S | FileCheck %s
+; RUN: opt < %s -simplifycfg -hoist-common-insts=true -S | FileCheck %s
define void @foo(i1 %c, i8* %p) {
; CHECK: if:
diff --git a/llvm/test/Transforms/SimplifyCFG/pr39807.ll b/llvm/test/Transforms/SimplifyCFG/pr39807.ll
index 8148f79503c8..1214c6fbeafb 100644
--- a/llvm/test/Transforms/SimplifyCFG/pr39807.ll
+++ b/llvm/test/Transforms/SimplifyCFG/pr39807.ll
@@ -1,4 +1,4 @@
-; RUN: opt -S -simplifycfg < %s | FileCheck %s
+; RUN: opt -S -simplifycfg -hoist-common-insts=true < %s | FileCheck %s
declare void @personality()
diff --git a/llvm/test/Transforms/SimplifyCFG/preserve-load-metadata-2.ll b/llvm/test/Transforms/SimplifyCFG/preserve-load-metadata-2.ll
index 94d3565ce985..bb3216e5c67f 100644
--- a/llvm/test/Transforms/SimplifyCFG/preserve-load-metadata-2.ll
+++ b/llvm/test/Transforms/SimplifyCFG/preserve-load-metadata-2.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -simplifycfg -S | FileCheck %s
+; RUN: opt < %s -simplifycfg -hoist-common-insts=true -S | FileCheck %s
declare void @bar(i32*)
declare void @baz(i32*)
diff --git a/llvm/test/Transforms/SimplifyCFG/preserve-load-metadata-3.ll b/llvm/test/Transforms/SimplifyCFG/preserve-load-metadata-3.ll
index 92bdf6ec5c1a..2a80e980c8f3 100644
--- a/llvm/test/Transforms/SimplifyCFG/preserve-load-metadata-3.ll
+++ b/llvm/test/Transforms/SimplifyCFG/preserve-load-metadata-3.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -simplifycfg -S | FileCheck %s
+; RUN: opt < %s -simplifycfg -hoist-common-insts=true -S | FileCheck %s
declare void @bar(i32*)
declare void @baz(i32*)
diff --git a/llvm/test/Transforms/SimplifyCFG/preserve-load-metadata.ll b/llvm/test/Transforms/SimplifyCFG/preserve-load-metadata.ll
index 89815c843152..3e87651e7e14 100644
--- a/llvm/test/Transforms/SimplifyCFG/preserve-load-metadata.ll
+++ b/llvm/test/Transforms/SimplifyCFG/preserve-load-metadata.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -simplifycfg -S | FileCheck %s
+; RUN: opt < %s -simplifycfg -hoist-common-insts=true -S | FileCheck %s
declare void @bar(i32*)
declare void @baz(i32*)
More information about the llvm-commits
mailing list