aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncan Sands <baldrick@free.fr>2011-02-01 08:39:12 +0000
committerDuncan Sands <baldrick@free.fr>2011-02-01 08:39:12 +0000
commit7681c6da606efcc392f76b8acea8301cb5fc7a0a (patch)
treec2e5253bcd443580cffc64f2698568c2d3aa3d9d
parente47023d543aecb8ca558721a0259d83ab2b016a3 (diff)
Have m_One also match constant vectors for which every element is 1.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124655 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Constants.h2
-rw-r--r--include/llvm/Support/PatternMatch.h9
-rw-r--r--lib/Analysis/InstructionSimplify.cpp6
-rw-r--r--lib/VMCore/Constants.cpp2
-rw-r--r--test/Transforms/InstSimplify/2011-02-01-Vector.ll8
5 files changed, 16 insertions, 11 deletions
diff --git a/include/llvm/Constants.h b/include/llvm/Constants.h
index 738c90cee7..a7653948f1 100644
--- a/include/llvm/Constants.h
+++ b/include/llvm/Constants.h
@@ -500,7 +500,7 @@ public:
/// 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);
diff --git a/include/llvm/Support/PatternMatch.h b/include/llvm/Support/PatternMatch.h
index 322ed436c9..b203c1ee1a 100644
--- a/include/llvm/Support/PatternMatch.h
+++ b/include/llvm/Support/PatternMatch.h
@@ -90,13 +90,16 @@ inline zero_ty m_Zero() { return zero_ty(); }
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 {
diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp
index a907150b9a..bce9a1fa07 100644
--- a/lib/Analysis/InstructionSimplify.cpp
+++ b/lib/Analysis/InstructionSimplify.cpp
@@ -785,12 +785,6 @@ static Value *SimplifyDiv(unsigned Opcode, Value *Op0, Value *Op1,
// 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.
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 3521ee7b16..62117b22e6 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -1033,7 +1033,7 @@ bool ConstantVector::isAllOnesValue() const {
/// 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.
diff --git a/test/Transforms/InstSimplify/2011-02-01-Vector.ll b/test/Transforms/InstSimplify/2011-02-01-Vector.ll
new file mode 100644
index 0000000000..3039a663fa
--- /dev/null
+++ b/test/Transforms/InstSimplify/2011-02-01-Vector.ll
@@ -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
+}