[llvm] 19c2e12 - [JumpThreading] Update computeValueKnownInPredecessors to recognize logical and/or patterns
Juneyoung Lee via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 23 07:06:31 PST 2021
Author: Juneyoung Lee
Date: 2021-02-24T00:06:10+09:00
New Revision: 19c2e129475013a8a36696d475c9d8681ce52614
URL: https://github.com/llvm/llvm-project/commit/19c2e129475013a8a36696d475c9d8681ce52614
DIFF: https://github.com/llvm/llvm-project/commit/19c2e129475013a8a36696d475c9d8681ce52614.diff
LOG: [JumpThreading] Update computeValueKnownInPredecessors to recognize logical and/or patterns
This allows JumpThreading's computeValueKnownInPredecessors to
recognize select form of and/or patterns as well.
Added:
Modified:
llvm/include/llvm/IR/PatternMatch.h
llvm/lib/Transforms/Scalar/JumpThreading.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index 0895002f2344..6edbf32de199 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -2454,6 +2454,11 @@ m_LogicalOr(const LHS &L, const RHS &R) {
return LogicalOp_match<LHS, RHS, Instruction::Or>(L, R);
}
+/// Matches L || R where L and R are arbitrary values.
+inline auto m_LogicalOr() {
+ return m_LogicalOr(m_Value(), m_Value());
+}
+
} // end namespace PatternMatch
} // end namespace llvm
diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
index 10b08b4e2224..1a15b8ce041a 100644
--- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp
+++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp
@@ -733,23 +733,26 @@ bool JumpThreadingPass::computeValueKnownInPredecessorsImpl(
// Handle some boolean conditions.
if (I->getType()->getPrimitiveSizeInBits() == 1) {
+ using namespace PatternMatch;
+
assert(Preference == WantInteger && "One-bit non-integer type?");
// X | true -> true
// X & false -> false
- if (I->getOpcode() == Instruction::Or ||
- I->getOpcode() == Instruction::And) {
+ Value *Op0, *Op1;
+ if (match(I, m_LogicalOr(m_Value(Op0), m_Value(Op1))) ||
+ match(I, m_LogicalAnd(m_Value(Op0), m_Value(Op1)))) {
PredValueInfoTy LHSVals, RHSVals;
- computeValueKnownInPredecessorsImpl(I->getOperand(0), BB, LHSVals,
- WantInteger, RecursionSet, CxtI);
- computeValueKnownInPredecessorsImpl(I->getOperand(1), BB, RHSVals,
- WantInteger, RecursionSet, CxtI);
+ computeValueKnownInPredecessorsImpl(Op0, BB, LHSVals, WantInteger,
+ RecursionSet, CxtI);
+ computeValueKnownInPredecessorsImpl(Op1, BB, RHSVals, WantInteger,
+ RecursionSet, CxtI);
if (LHSVals.empty() && RHSVals.empty())
return false;
ConstantInt *InterestingVal;
- if (I->getOpcode() == Instruction::Or)
+ if (match(I, m_LogicalOr()))
InterestingVal = ConstantInt::getTrue(I->getContext());
else
InterestingVal = ConstantInt::getFalse(I->getContext());
More information about the llvm-commits
mailing list