[SLSR] handles non-canonicalized Mul candidates

such as (2 + B) * S.

Tested by @non_canonicalized in slsr-mul.ll


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237216 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jingyue Wu
2015-05-13 00:03:17 +00:00
parent ead2d1fbe0
commit 3062272092
2 changed files with 23 additions and 2 deletions

View File

@@ -408,8 +408,8 @@ void StraightLineStrengthReduce::allocateCandidatesAndFindBasisForMul(
Value *LHS, Value *RHS, Instruction *I) {
Value *B = nullptr;
ConstantInt *Idx = nullptr;
// Only handle the canonical operand ordering.
if (match(LHS, m_Add(m_Value(B), m_ConstantInt(Idx)))) {
if (match(LHS, m_Add(m_Value(B), m_ConstantInt(Idx))) ||
match(LHS, m_Add(m_ConstantInt(Idx), m_Value(B)))) {
// If LHS is in the form of "Base + Index", then I is in the form of
// "(Base + Index) * RHS".
allocateCandidatesAndFindBasis(Candidate::Mul, SE->getSCEV(B), Idx, RHS, I);