diff options
author | Roman Lebedev <lebedev.ri@gmail.com> | 2019-08-10 19:28:54 +0000 |
---|---|---|
committer | Roman Lebedev <lebedev.ri@gmail.com> | 2019-08-10 19:28:54 +0000 |
commit | a8d20b446766d8dd1cdbd0332daf646294f6ea77 (patch) | |
tree | 3d5386a12942c90b526ba14cd5c93a176f51ddea /llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | |
parent | 64fe806c4e11d90d8abaed65b659673be677b856 (diff) | |
download | bcm5719-llvm-a8d20b446766d8dd1cdbd0332daf646294f6ea77.tar.gz bcm5719-llvm-a8d20b446766d8dd1cdbd0332daf646294f6ea77.zip |
[InstCombine] Shift amount reassociation in bittest: relax one-use check when shifting constant
If one of the values being shifted is a constant, since the new shift
amount is known-constant, the new shift will end up being constant-folded
so, we don't need that one-use restriction then.
llvm-svn: 368519
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index edad6a45121..f82a5b1806c 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -3314,7 +3314,7 @@ foldShiftIntoShiftInAnotherHandOfAndInICmp(ICmpInst &I, const SimplifyQuery SQ, // Pick the single-use shift as XShift. Value *XShift, *YShift; if (!match(I.getOperand(0), - m_c_And(m_OneUse(m_CombineAnd(m_AnyLogicalShift, m_Value(XShift))), + m_c_And(m_CombineAnd(m_AnyLogicalShift, m_Value(XShift)), m_CombineAnd(m_AnyLogicalShift, m_Value(YShift))))) return nullptr; @@ -3332,6 +3332,16 @@ foldShiftIntoShiftInAnotherHandOfAndInICmp(ICmpInst &I, const SimplifyQuery SQ, match(XShift, m_BinOp(m_Value(X), m_Value(XShAmt))); match(YShift, m_BinOp(m_Value(Y), m_Value(YShAmt))); + // If one of the values being shifted is a constant, then we will end with + // and+icmp, and shift instr will be constant-folded. If they are not, + // however, we will need to ensure that we won't increase instruction count. + if (!isa<Constant>(X) && !isa<Constant>(Y)) { + // At least one of the hands of the 'and' should be one-use shift. + if (!match(I.getOperand(0), + m_c_And(m_OneUse(m_AnyLogicalShift), m_Value()))) + return nullptr; + } + // Can we fold (XShAmt+YShAmt) ? Value *NewShAmt = SimplifyBinOp(Instruction::BinaryOps::Add, XShAmt, YShAmt, SQ.getWithInstruction(&I)); |