[llvm] r237216 - [SLSR] handles non-canonicalized Mul candidates

Jingyue Wu jingyue at google.com
Tue May 12 17:03:17 PDT 2015


Author: jingyue
Date: Tue May 12 19:03:17 2015
New Revision: 237216

URL: http://llvm.org/viewvc/llvm-project?rev=237216&view=rev
Log:
[SLSR] handles non-canonicalized Mul candidates

such as (2 + B) * S.

Tested by @non_canonicalized in slsr-mul.ll

Modified:
    llvm/trunk/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
    llvm/trunk/test/Transforms/StraightLineStrengthReduce/slsr-mul.ll

Modified: llvm/trunk/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp?rev=237216&r1=237215&r2=237216&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp Tue May 12 19:03:17 2015
@@ -408,8 +408,8 @@ void StraightLineStrengthReduce::allocat
     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);

Modified: llvm/trunk/test/Transforms/StraightLineStrengthReduce/slsr-mul.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/StraightLineStrengthReduce/slsr-mul.ll?rev=237216&r1=237215&r2=237216&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/StraightLineStrengthReduce/slsr-mul.ll (original)
+++ llvm/trunk/test/Transforms/StraightLineStrengthReduce/slsr-mul.ll Tue May 12 19:03:17 2015
@@ -23,6 +23,27 @@ define void @slsr1(i32 %b, i32 %s) {
   ret void
 }
 
+define void @non_canonicalized(i32 %b, i32 %s) {
+; CHECK-LABEL: @non_canonicalized(
+  ; foo(b * s);
+  %mul0 = mul i32 %b, %s
+; CHECK: mul i32
+; CHECK-NOT: mul i32
+  call void @foo(i32 %mul0)
+
+  ; foo((1 + b) * s);
+  %b1 = add i32 1, %b
+  %mul1 = mul i32 %b1, %s
+  call void @foo(i32 %mul1)
+
+  ; foo((2 + b) * s);
+  %b2 = add i32 2, %b
+  %mul2 = mul i32 %b2, %s
+  call void @foo(i32 %mul2)
+
+  ret void
+}
+
 ; foo(a * b)
 ; foo((a + 1) * b)
 ; foo(a * (b + 1))





More information about the llvm-commits mailing list