[llvm-commits] [llvm] r124655 - in /llvm/trunk: include/llvm/Constants.h include/llvm/Support/PatternMatch.h lib/Analysis/InstructionSimplify.cpp lib/VMCore/Constants.cpp test/Transforms/InstSimplify/2011-02-01-Vector.ll

Duncan Sands baldrick at free.fr
Tue Feb 1 00:39:12 PST 2011


Author: baldrick
Date: Tue Feb  1 02:39:12 2011
New Revision: 124655

URL: http://llvm.org/viewvc/llvm-project?rev=124655&view=rev
Log:
Have m_One also match constant vectors for which every element is 1.

Added:
    llvm/trunk/test/Transforms/InstSimplify/2011-02-01-Vector.ll
Modified:
    llvm/trunk/include/llvm/Constants.h
    llvm/trunk/include/llvm/Support/PatternMatch.h
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp
    llvm/trunk/lib/VMCore/Constants.cpp

Modified: llvm/trunk/include/llvm/Constants.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Constants.h?rev=124655&r1=124654&r2=124655&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Constants.h (original)
+++ llvm/trunk/include/llvm/Constants.h Tue Feb  1 02:39:12 2011
@@ -500,7 +500,7 @@
 
   /// getSplatValue - If this is a splat constant, meaning that all of the
   /// elements have the same value, return that value. Otherwise return NULL.
-  Constant *getSplatValue();
+  Constant *getSplatValue() const;
 
   virtual void destroyConstant();
   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);

Modified: llvm/trunk/include/llvm/Support/PatternMatch.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/PatternMatch.h?rev=124655&r1=124654&r2=124655&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/PatternMatch.h (original)
+++ llvm/trunk/include/llvm/Support/PatternMatch.h Tue Feb  1 02:39:12 2011
@@ -90,13 +90,16 @@
 struct one_ty {
   template<typename ITy>
   bool match(ITy *V) {
-    if (const ConstantInt *C = dyn_cast<ConstantInt>(V))
-      return C->isOne();
+    if (const ConstantInt *CI = dyn_cast<ConstantInt>(V))
+      return CI->isOne();
+    if (const ConstantVector *CV = dyn_cast<ConstantVector>(V))
+      if (ConstantInt *CI = cast_or_null<ConstantInt>(CV->getSplatValue()))
+        return CI->isOne();
     return false;
   }
 };
 
-/// m_One() - Match an integer 1.
+/// m_One() - Match an integer 1 or a vector with all elements equal to 1.
 inline one_ty m_One() { return one_ty(); }
   
 struct all_ones_ty {

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=124655&r1=124654&r2=124655&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Tue Feb  1 02:39:12 2011
@@ -785,12 +785,6 @@
   // X / 1 -> X
   if (match(Op1, m_One()))
     return Op0;
-  // Vector case. TODO: Have m_One match vectors.
-  if (ConstantVector *Op1V = dyn_cast<ConstantVector>(Op1)) {
-    if (ConstantInt *X = cast_or_null<ConstantInt>(Op1V->getSplatValue()))
-      if (X->isOne())
-        return Op0;
-  }
 
   if (Op0->getType()->isIntegerTy(1))
     // It can't be division by zero, hence it must be division by one.

Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=124655&r1=124654&r2=124655&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Tue Feb  1 02:39:12 2011
@@ -1033,7 +1033,7 @@
 
 /// getSplatValue - If this is a splat constant, where all of the
 /// elements have the same value, return that value. Otherwise return null.
-Constant *ConstantVector::getSplatValue() {
+Constant *ConstantVector::getSplatValue() const {
   // Check out first element.
   Constant *Elt = getOperand(0);
   // Then make sure all remaining elements point to the same value.

Added: llvm/trunk/test/Transforms/InstSimplify/2011-02-01-Vector.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/2011-02-01-Vector.ll?rev=124655&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/2011-02-01-Vector.ll (added)
+++ llvm/trunk/test/Transforms/InstSimplify/2011-02-01-Vector.ll Tue Feb  1 02:39:12 2011
@@ -0,0 +1,8 @@
+; RUN: opt < %s -instsimplify -S | FileCheck %s
+
+define <2 x i32> @sdiv(<2 x i32> %x) {
+; CHECK: @sdiv
+  %div = sdiv <2 x i32> %x, <i32 1, i32 1>
+  ret <2 x i32> %div
+; CHECK: ret <2 x i32> %x
+}





More information about the llvm-commits mailing list