[llvm] r316298 - [SimplifyCFG] delay switch condition forwarding to -latesimplifycfg
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 22 12:10:07 PDT 2017
Author: spatel
Date: Sun Oct 22 12:10:07 2017
New Revision: 316298
URL: http://llvm.org/viewvc/llvm-project?rev=316298&view=rev
Log:
[SimplifyCFG] delay switch condition forwarding to -latesimplifycfg
As discussed in D39011:
https://reviews.llvm.org/D39011
...replacing constants with a variable is inverting the transform done
by other IR passes, so we definitely don't want to do this early.
In fact, it's questionable whether this transform belongs in SimplifyCFG
at all. I'll look at moving this to codegen as a follow-up step.
Modified:
llvm/trunk/include/llvm/Transforms/Utils/Local.h
llvm/trunk/lib/Transforms/Scalar/SimplifyCFGPass.cpp
llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/trunk/test/Transforms/SimplifyCFG/ForwardSwitchConditionToPHI.ll
Modified: llvm/trunk/include/llvm/Transforms/Utils/Local.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/Local.h?rev=316298&r1=316297&r2=316298&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/Local.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/Local.h Sun Oct 22 12:10:07 2017
@@ -60,14 +60,16 @@ class TargetTransformInfo;
/// replaced by lookup tables and selects.
struct SimplifyCFGOptions {
int BonusInstThreshold;
+ bool ForwardSwitchCondToPhi;
bool ConvertSwitchToLookupTable;
bool NeedCanonicalLoop;
AssumptionCache *AC;
- SimplifyCFGOptions(int BonusThreshold = 1, bool SwitchToLookup = false,
- bool CanonicalLoops = true,
+ SimplifyCFGOptions(int BonusThreshold = 1, bool ForwardSwitchCond = false,
+ bool SwitchToLookup = false, bool CanonicalLoops = true,
AssumptionCache *AssumpCache = nullptr)
: BonusInstThreshold(BonusThreshold),
+ ForwardSwitchCondToPhi(ForwardSwitchCond),
ConvertSwitchToLookupTable(SwitchToLookup),
NeedCanonicalLoop(CanonicalLoops), AC(AssumpCache) {}
};
Modified: llvm/trunk/lib/Transforms/Scalar/SimplifyCFGPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SimplifyCFGPass.cpp?rev=316298&r1=316297&r2=316298&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SimplifyCFGPass.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SimplifyCFGPass.cpp Sun Oct 22 12:10:07 2017
@@ -179,8 +179,10 @@ static bool simplifyFunctionCFG(Function
return true;
}
+// FIXME: The new pass manager always creates a "late" simplifycfg pass using
+// this default constructor.
SimplifyCFGPass::SimplifyCFGPass()
- : Options(UserBonusInstThreshold, true, false) {}
+ : Options(UserBonusInstThreshold, true, true, false) {}
SimplifyCFGPass::SimplifyCFGPass(const SimplifyCFGOptions &PassOptions)
: Options(PassOptions) {}
@@ -200,12 +202,15 @@ namespace {
struct BaseCFGSimplifyPass : public FunctionPass {
std::function<bool(const Function &)> PredicateFtor;
int BonusInstThreshold;
+ bool ForwardSwitchCondToPhi;
bool ConvertSwitchToLookupTable;
bool KeepCanonicalLoops;
- BaseCFGSimplifyPass(int T, bool ConvertSwitch, bool KeepLoops,
+ BaseCFGSimplifyPass(int T, bool ForwardSwitchCond, bool ConvertSwitch,
+ bool KeepLoops,
std::function<bool(const Function &)> Ftor, char &ID)
: FunctionPass(ID), PredicateFtor(std::move(Ftor)),
+ ForwardSwitchCondToPhi(ForwardSwitchCond),
ConvertSwitchToLookupTable(ConvertSwitch),
KeepCanonicalLoops(KeepLoops) {
BonusInstThreshold = (T == -1) ? UserBonusInstThreshold : T;
@@ -219,8 +224,9 @@ struct BaseCFGSimplifyPass : public Func
const TargetTransformInfo &TTI =
getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
return simplifyFunctionCFG(F, TTI,
- {BonusInstThreshold, ConvertSwitchToLookupTable,
- KeepCanonicalLoops, AC});
+ {BonusInstThreshold, ForwardSwitchCondToPhi,
+ ConvertSwitchToLookupTable, KeepCanonicalLoops,
+ AC});
}
void getAnalysisUsage(AnalysisUsage &AU) const override {
@@ -235,7 +241,7 @@ struct CFGSimplifyPass : public BaseCFGS
CFGSimplifyPass(int T = -1,
std::function<bool(const Function &)> Ftor = nullptr)
- : BaseCFGSimplifyPass(T, false, true, Ftor, ID) {
+ : BaseCFGSimplifyPass(T, false, false, true, Ftor, ID) {
initializeCFGSimplifyPassPass(*PassRegistry::getPassRegistry());
}
};
@@ -245,7 +251,7 @@ struct LateCFGSimplifyPass : public Base
LateCFGSimplifyPass(int T = -1,
std::function<bool(const Function &)> Ftor = nullptr)
- : BaseCFGSimplifyPass(T, true, false, Ftor, ID) {
+ : BaseCFGSimplifyPass(T, true, true, false, Ftor, ID) {
initializeLateCFGSimplifyPassPass(*PassRegistry::getPassRegistry());
}
};
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=316298&r1=316297&r2=316298&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Sun Oct 22 12:10:07 2017
@@ -5563,7 +5563,7 @@ bool SimplifyCFGOpt::SimplifySwitch(Swit
if (switchToSelect(SI, Builder, DL, TTI))
return simplifyCFG(BB, TTI, Options) | true;
- if (ForwardSwitchConditionToPHI(SI))
+ if (Options.ForwardSwitchCondToPhi && ForwardSwitchConditionToPHI(SI))
return simplifyCFG(BB, TTI, Options) | true;
// The conversion from switch to lookup tables results in difficult-to-analyze
Modified: llvm/trunk/test/Transforms/SimplifyCFG/ForwardSwitchConditionToPHI.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/ForwardSwitchConditionToPHI.ll?rev=316298&r1=316297&r2=316298&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/ForwardSwitchConditionToPHI.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/ForwardSwitchConditionToPHI.ll Sun Oct 22 12:10:07 2017
@@ -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 -latesimplifycfg -S | FileCheck %s
; PR10131
More information about the llvm-commits
mailing list