diff options
| author | Roman Lebedev <lebedev.ri@gmail.com> | 2019-09-17 19:32:26 +0000 |
|---|---|---|
| committer | Roman Lebedev <lebedev.ri@gmail.com> | 2019-09-17 19:32:26 +0000 |
| commit | 97bc5ae993bfe82667f333b650e0aaa8c1b1b4a2 (patch) | |
| tree | 48efe8f0a089a1bcf762f0dbe328b01db20941c0 | |
| parent | bed6e08e23b36dc5ac38d675c2a705c2f41a4a94 (diff) | |
| download | bcm5719-llvm-97bc5ae993bfe82667f333b650e0aaa8c1b1b4a2.tar.gz bcm5719-llvm-97bc5ae993bfe82667f333b650e0aaa8c1b1b4a2.zip | |
[NFC][InstCombine] dropRedundantMaskingOfLeftShiftInput(): some NFC diff shaving
llvm-svn: 372171
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp index b451beebd0f..cda83544a4d 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp @@ -131,7 +131,8 @@ reassociateShiftAmtsOfTwoSameDirectionShifts(BinaryOperator *Sh0, // c,d,e,f) (ShiftShAmt-MaskShAmt) s>= 0 (i.e. ShiftShAmt u>= MaskShAmt) static Instruction * dropRedundantMaskingOfLeftShiftInput(BinaryOperator *OuterShift, - const SimplifyQuery &SQ) { + const SimplifyQuery &SQ, + InstCombiner::BuilderTy &Builder) { assert(OuterShift->getOpcode() == Instruction::BinaryOps::Shl && "The input must be 'shl'!"); @@ -153,17 +154,19 @@ dropRedundantMaskingOfLeftShiftInput(BinaryOperator *OuterShift, Value *X; if (match(Masked, m_c_And(m_CombineOr(MaskA, MaskB), m_Value(X)))) { // Can we simplify (MaskShAmt+ShiftShAmt) ? - Value *SumOfShAmts = + auto *SumOfShAmts = dyn_cast_or_null<Constant>( SimplifyAddInst(MaskShAmt, ShiftShAmt, /*IsNSW=*/false, /*IsNUW=*/false, - SQ.getWithInstruction(OuterShift)); + SQ.getWithInstruction(OuterShift))); if (!SumOfShAmts) return nullptr; // Did not simplify. - // Is the total shift amount *not* smaller than the bit width? - // FIXME: could also rely on ConstantRange. - unsigned BitWidth = X->getType()->getScalarSizeInBits(); + Type *Ty = X->getType(); + unsigned BitWidth = Ty->getScalarSizeInBits(); + // In this pattern SumOfShAmts correlates with the number of low bits that + // shall remain in the root value (OuterShift). If SumOfShAmts is less than + // bitwidth, we'll need to also produce a mask to keep SumOfShAmts low bits. if (!match(SumOfShAmts, m_SpecificInt_ICMP(ICmpInst::Predicate::ICMP_UGE, APInt(BitWidth, BitWidth)))) - return nullptr; + return nullptr; // FIXME. // All good, we can do this fold. } else if (match(Masked, m_c_And(m_CombineOr(MaskC, MaskD), m_Value(X))) || match(Masked, m_Shr(m_Shl(m_Value(X), m_Value(MaskShAmt)), @@ -751,7 +754,7 @@ Instruction *InstCombiner::visitShl(BinaryOperator &I) { if (Instruction *V = commonShiftTransforms(I)) return V; - if (Instruction *V = dropRedundantMaskingOfLeftShiftInput(&I, SQ)) + if (Instruction *V = dropRedundantMaskingOfLeftShiftInput(&I, SQ, Builder)) return V; Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1); |

