From ee81b23fe78d70aef8a49df2c55a6d98f611a77d Mon Sep 17 00:00:00 2001 From: Sanjoy Das Date: Fri, 29 Apr 2016 21:52:58 +0000 Subject: [EarlyCSE] Simplify guard intrinsics Summary: This change teaches EarlyCSE some basic properties of guard intrinsics: - Guard intrinsics read all memory, but don't write to any memory - After a guard has executed, the condition it was guarding on can be assumed to be true - Guard intrinsics on a constant `true` are no-ops Reviewers: reames, hfinkel Subscribers: mcrosier, llvm-commits Differential Revision: http://reviews.llvm.org/D19578 llvm-svn: 268120 --- llvm/lib/Transforms/Scalar/EarlyCSE.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp index 123064d2ae9..c453c843bfc 100644 --- a/llvm/lib/Transforms/Scalar/EarlyCSE.cpp +++ b/llvm/lib/Transforms/Scalar/EarlyCSE.cpp @@ -554,6 +554,29 @@ bool EarlyCSE::processNode(DomTreeNode *Node) { continue; } + if (match(Inst, m_Intrinsic())) { + Value *Cond = cast(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(Cond)) { + // The condition we're on guarding here is true for all dominated + // locations. + if (SimpleValue::canHandle(CondI)) + AvailableValues.insert(CondI, ConstantInt::getTrue(BB->getContext())); + } + + // Guard intrinsics read all memory, but don't write any memory. + // Accordingly, don't update the generation but consume the last store (to + // avoid an incorrect DSE). + LastStore = nullptr; + continue; + } + // If the instruction can be simplified (e.g. X+0 = X) then replace it with // its simpler value. if (Value *V = SimplifyInstruction(Inst, DL, &TLI, &DT, &AC)) { -- cgit v1.2.3