diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -408,8 +408,10 @@ /// which is the branch condition. VPUser CondBitUser; - /// Current block predicate - null if the block does not need a predicate. - VPValue *Predicate = nullptr; + /// If the block is predicated, its predicate is stored as an operand of this + /// VPUser to maintain the def-use relations. Otherwise there is no operand + /// here. + VPUser PredicateUser; /// VPlan containing the block. Can only be set on the entry block of the /// plan. @@ -579,11 +581,29 @@ CondBitUser.addOperand(CV); } - VPValue *getPredicate() { return Predicate; } + VPValue *getPredicate() { + if (PredicateUser.getNumOperands()) + return PredicateUser.getOperand(0); + return nullptr; + } - const VPValue *getPredicate() const { return Predicate; } + const VPValue *getPredicate() const { + if (PredicateUser.getNumOperands()) + return PredicateUser.getOperand(0); + return nullptr; + } - void setPredicate(VPValue *Pred) { Predicate = Pred; } + void setPredicate(VPValue *Pred) { + if (!Pred) { + if (PredicateUser.getNumOperands() == 1) + PredicateUser.removeLastOperand(); + return; + } + if (PredicateUser.getNumOperands() == 1) + PredicateUser.setOperand(0, Pred); + else + PredicateUser.addOperand(Pred); + } /// Set a given VPBlockBase \p Successor as the single successor of this /// VPBlockBase. This VPBlockBase is not added as predecessor of \p Successor.