llvm.org GIT mirror llvm / 3aa5468
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268126 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjoy Das 3 years ago
3 changed file(s) with 19 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
554554 }
555555
556556 if (match(Inst, m_Intrinsic())) {
557 Value *Cond = cast(Inst)->getArgOperand(0);
558
559 if (match(Cond, m_One())) {
560 // Elide guards on true, since operationally they're no-ops. In the
561 // future we can consider more sophisticated tradeoffs here with
562 // consideration to potential for check widening, but for now we keep
563 // things simple.
564 Inst->eraseFromParent();
565 } else if (auto *CondI = dyn_cast(Cond)) {
557 if (auto *CondI =
558 dyn_cast(cast(Inst)->getArgOperand(0))) {
566559 // The condition we're on guarding here is true for all dominated
567560 // locations.
568561 if (SimpleValue::canHandle(CondI))
320320 II->getIntrinsicID() == Intrinsic::lifetime_end)
321321 return isa(II->getArgOperand(1));
322322
323 // Assumptions are dead if their condition is trivially true.
324 if (II->getIntrinsicID() == Intrinsic::assume) {
323 // Assumptions are dead if their condition is trivially true. Guards on
324 // true are operationally no-ops. In the future we can consider more
325 // sophisticated tradeoffs for guards considering potential for check
326 // widening, but for now we keep things simple.
327 if (II->getIntrinsicID() == Intrinsic::assume ||
328 II->getIntrinsicID() == Intrinsic::experimental_guard) {
325329 if (ConstantInt *Cond = dyn_cast(II->getArgOperand(0)))
326330 return !Cond->isZero();
327331
0 ; RUN: opt -dce -S < %s | FileCheck %s
1
2 declare void @llvm.experimental.guard(i1,...)
3
4 define void @f(i32 %val) {
5 ; CHECK-LABEL: @f(
6 ; CHECK-NEXT: ret void
7 %val2 = add i32 %val, 1
8 call void(i1, ...) @llvm.experimental.guard(i1 true) [ "deopt"(i32 %val2) ]
9 ret void
10 }