[llvm] r268126 - Mark guards on true as "trivially dead"
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 29 15:23:16 PDT 2016
Author: sanjoy
Date: Fri Apr 29 17:23:16 2016
New Revision: 268126
URL: http://llvm.org/viewvc/llvm-project?rev=268126&view=rev
Log:
Mark guards on true as "trivially dead"
This moves some logic added to EarlyCSE in rL268120 into
`llvm::isInstructionTriviallyDead`. Adds a test case for DCE to
demonstrate that passes other than EarlyCSE can now pick up on the new
information.
Added:
llvm/trunk/test/Transforms/DCE/guards.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp
llvm/trunk/lib/Transforms/Utils/Local.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp?rev=268126&r1=268125&r2=268126&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/EarlyCSE.cpp Fri Apr 29 17:23:16 2016
@@ -555,15 +555,8 @@ bool EarlyCSE::processNode(DomTreeNode *
}
if (match(Inst, m_Intrinsic<Intrinsic::experimental_guard>())) {
- Value *Cond = cast<CallInst>(Inst)->getArgOperand(0);
-
- if (match(Cond, m_One())) {
- // Elide guards on true, since operationally they're no-ops. In the
- // future we can consider more sophisticated tradeoffs here with
- // consideration to potential for check widening, but for now we keep
- // things simple.
- Inst->eraseFromParent();
- } else if (auto *CondI = dyn_cast<Instruction>(Cond)) {
+ if (auto *CondI =
+ dyn_cast<Instruction>(cast<CallInst>(Inst)->getArgOperand(0))) {
// The condition we're on guarding here is true for all dominated
// locations.
if (SimpleValue::canHandle(CondI))
Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=268126&r1=268125&r2=268126&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/Local.cpp Fri Apr 29 17:23:16 2016
@@ -321,8 +321,12 @@ bool llvm::isInstructionTriviallyDead(In
II->getIntrinsicID() == Intrinsic::lifetime_end)
return isa<UndefValue>(II->getArgOperand(1));
- // Assumptions are dead if their condition is trivially true.
- if (II->getIntrinsicID() == Intrinsic::assume) {
+ // Assumptions are dead if their condition is trivially true. Guards on
+ // true are operationally no-ops. In the future we can consider more
+ // sophisticated tradeoffs for guards considering potential for check
+ // widening, but for now we keep things simple.
+ if (II->getIntrinsicID() == Intrinsic::assume ||
+ II->getIntrinsicID() == Intrinsic::experimental_guard) {
if (ConstantInt *Cond = dyn_cast<ConstantInt>(II->getArgOperand(0)))
return !Cond->isZero();
Added: llvm/trunk/test/Transforms/DCE/guards.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/DCE/guards.ll?rev=268126&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/DCE/guards.ll (added)
+++ llvm/trunk/test/Transforms/DCE/guards.ll Fri Apr 29 17:23:16 2016
@@ -0,0 +1,11 @@
+; RUN: opt -dce -S < %s | FileCheck %s
+
+declare void @llvm.experimental.guard(i1,...)
+
+define void @f(i32 %val) {
+; CHECK-LABEL: @f(
+; CHECK-NEXT: ret void
+ %val2 = add i32 %val, 1
+ call void(i1, ...) @llvm.experimental.guard(i1 true) [ "deopt"(i32 %val2) ]
+ ret void
+}
More information about the llvm-commits
mailing list