summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kazantsev <max.kazantsev@azul.com>2018-08-22 02:40:49 +0000
committerMax Kazantsev <max.kazantsev@azul.com>2018-08-22 02:40:49 +0000
commit611d645a08d154b46d9748bab73d5cc5180a6e68 (patch)
tree9d93e4bfc2afdce540084d4f2d2aa37b6d80b59e
parent9ba5740ba56c23aedc05b70bf8028dd3cad82a83 (diff)
downloadbcm5719-llvm-611d645a08d154b46d9748bab73d5cc5180a6e68.tar.gz
bcm5719-llvm-611d645a08d154b46d9748bab73d5cc5180a6e68.zip
[GuardWidening] Ignore guards with trivial conditions
Guard widening should not spend efforts on dealing with guards with trivial true/false conditions. Such guards can easily be eliminated by any further cleanup pass like instcombine. However we should not unconditionally delete them because it may be profitable to widen other conditions into such guards. Differential Revision: https://reviews.llvm.org/D50247 Reviewed By: fedor.sergeev llvm-svn: 340381
-rw-r--r--llvm/lib/Transforms/Scalar/GuardWidening.cpp6
-rw-r--r--llvm/test/Transforms/GuardWidening/basic.ll26
2 files changed, 32 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/GuardWidening.cpp b/llvm/lib/Transforms/Scalar/GuardWidening.cpp
index 9467e5ed651..68be46ec07b 100644
--- a/llvm/lib/Transforms/Scalar/GuardWidening.cpp
+++ b/llvm/lib/Transforms/Scalar/GuardWidening.cpp
@@ -347,6 +347,12 @@ bool GuardWideningImpl::eliminateGuardViaWidening(
Instruction *GuardInst, const df_iterator<DomTreeNode *> &DFSI,
const DenseMap<BasicBlock *, SmallVector<Instruction *, 8>> &
GuardsInBlock, bool InvertCondition) {
+ // Ignore trivial true or false conditions. These instructions will be
+ // trivially eliminated by any cleanup pass. Do not erase them because other
+ // guards can possibly be widened into them.
+ if (isa<ConstantInt>(getCondition(GuardInst)))
+ return false;
+
Instruction *BestSoFar = nullptr;
auto BestScoreSoFar = WS_IllegalOrNegative;
auto *GuardInstLoop = LI.getLoopFor(GuardInst->getParent());
diff --git a/llvm/test/Transforms/GuardWidening/basic.ll b/llvm/test/Transforms/GuardWidening/basic.ll
index 5b746a5d7dd..ab18ed7362a 100644
--- a/llvm/test/Transforms/GuardWidening/basic.ll
+++ b/llvm/test/Transforms/GuardWidening/basic.ll
@@ -379,3 +379,29 @@ left:
right:
ret void
}
+
+; Make sure we do not widen guard by trivial true conditions into something.
+define void @f_15(i1 %cond_0, i1 %cond_1) {
+; CHECK-LABEL: @f_15(
+entry:
+; CHECK: call void (i1, ...) @llvm.experimental.guard(i1 %cond_0) [ "deopt"() ]
+; CHECK: call void (i1, ...) @llvm.experimental.guard(i1 true) [ "deopt"() ]
+; CHECK: ret void
+
+ call void(i1, ...) @llvm.experimental.guard(i1 %cond_0) [ "deopt"() ]
+ call void(i1, ...) @llvm.experimental.guard(i1 true) [ "deopt"() ]
+ ret void
+}
+
+; Make sure we do not widen guard by trivial false conditions into something.
+define void @f_16(i1 %cond_0, i1 %cond_1) {
+; CHECK-LABEL: @f_16(
+entry:
+; CHECK: call void (i1, ...) @llvm.experimental.guard(i1 %cond_0) [ "deopt"() ]
+; CHECK: call void (i1, ...) @llvm.experimental.guard(i1 false) [ "deopt"() ]
+; CHECK: ret void
+
+ call void(i1, ...) @llvm.experimental.guard(i1 %cond_0) [ "deopt"() ]
+ call void(i1, ...) @llvm.experimental.guard(i1 false) [ "deopt"() ]
+ ret void
+}
OpenPOWER on IntegriCloud