1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

Have m_One also match constant vectors for which every element is 1.

llvm-svn: 124655
This commit is contained in:
Duncan Sands 2011-02-01 08:39:12 +00:00
parent 667d5dbdcb
commit 06e82c76ee
5 changed files with 16 additions and 11 deletions

View File

@ -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);

View File

@ -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 {

View File

@ -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.

View File

@ -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.

View File

@ -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
}