[llvm] 5419b67 - [SimplifyCFG] Update FoldTwoEntryPHINode to handle and/or of select and binop equally
Juneyoung Lee via llvm-commits
llvm-commits at lists.llvm.org
Sun Feb 28 20:35:12 PST 2021
Author: Juneyoung Lee
Date: 2021-03-01T13:34:51+09:00
New Revision: 5419b671375c46299ff1da6c929859040e7beaf5
URL: https://github.com/llvm/llvm-project/commit/5419b671375c46299ff1da6c929859040e7beaf5
DIFF: https://github.com/llvm/llvm-project/commit/5419b671375c46299ff1da6c929859040e7beaf5.diff
LOG: [SimplifyCFG] Update FoldTwoEntryPHINode to handle and/or of select and binop equally
This is a minor change that fixes FoldTwoEntryPHINode to handle
phis with and/ors of select form and binop form equally.
Added:
Modified:
llvm/include/llvm/IR/PatternMatch.h
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index 6edbf32de199..575eff4650e1 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -2446,6 +2446,9 @@ m_LogicalAnd(const LHS &L, const RHS &R) {
return LogicalOp_match<LHS, RHS, Instruction::And>(L, R);
}
+/// Matches L && R where L and R are arbitrary values.
+inline auto m_LogicalAnd() { return m_LogicalAnd(m_Value(), m_Value()); }
+
/// Matches L || R either in the form of L | R or L ? true : R.
/// Note that the latter form is poison-blocking.
template <typename LHS, typename RHS>
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index e8dd03367113..8ca324291886 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -2598,13 +2598,17 @@ static bool FoldTwoEntryPHINode(PHINode *PN, const TargetTransformInfo &TTI,
return match(V0, m_Not(m_Value())) && match(V1, Invertible);
};
- // Don't fold i1 branches on PHIs which contain binary operators, unless one
- // of the incoming values is an 'not' and another one is freely invertible.
+ // Don't fold i1 branches on PHIs which contain binary operators or
+ // select form of or/ands, unless one of the incoming values is an 'not' and
+ // another one is freely invertible.
// These can often be turned into switches and other things.
+ auto IsBinOpOrAnd = [](Value *V) {
+ return match(
+ V, m_CombineOr(m_BinOp(), m_CombineOr(m_LogicalAnd(), m_LogicalOr())));
+ };
if (PN->getType()->isIntegerTy(1) &&
- (isa<BinaryOperator>(PN->getIncomingValue(0)) ||
- isa<BinaryOperator>(PN->getIncomingValue(1)) ||
- isa<BinaryOperator>(IfCond)) &&
+ (IsBinOpOrAnd(PN->getIncomingValue(0)) ||
+ IsBinOpOrAnd(PN->getIncomingValue(1)) || IsBinOpOrAnd(IfCond)) &&
!CanHoistNotFromBothValues(PN->getIncomingValue(0),
PN->getIncomingValue(1)))
return Changed;
More information about the llvm-commits
mailing list