diff options
author | David Majnemer <david.majnemer@gmail.com> | 2014-12-17 01:54:33 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2014-12-17 01:54:33 +0000 |
commit | 65c52ae8ca180cf54094cb78045e18ba82aec46e (patch) | |
tree | 9db5d71b17bdd9f65aef0c182cdf2ebe33dd59a4 /llvm/lib | |
parent | ee0a3a7a2f018a5d40015b853210b726a8a8b635 (diff) | |
download | bcm5719-llvm-65c52ae8ca180cf54094cb78045e18ba82aec46e.tar.gz bcm5719-llvm-65c52ae8ca180cf54094cb78045e18ba82aec46e.zip |
InstSimplify: shl nsw/nuw undef, %V -> undef
We can always choose an value for undef which might cause %V to shift
out an important bit except for one case, when %V is zero.
However, shl behaves like an identity function when the right hand side
is zero.
llvm-svn: 224405
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Analysis/InstructionSimplify.cpp | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index 408768e8515..1db7ab7bf03 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -1338,6 +1338,11 @@ static Value *SimplifyRightShift(unsigned Opcode, Value *Op0, Value *Op1, if (Op0 == Op1) return Constant::getNullValue(Op0->getType()); + // undef >> X -> 0 + // undef >> X -> undef (if it's exact) + if (match(Op0, m_Undef())) + return isExact ? Op0 : Constant::getNullValue(Op0->getType()); + // The low bit cannot be shifted out of an exact shift if it is set. if (isExact) { unsigned BitWidth = Op0->getType()->getScalarSizeInBits(); @@ -1360,8 +1365,9 @@ static Value *SimplifyShlInst(Value *Op0, Value *Op1, bool isNSW, bool isNUW, return V; // undef << X -> 0 + // undef << X -> undef if (if it's NSW/NUW) if (match(Op0, m_Undef())) - return Constant::getNullValue(Op0->getType()); + return isNSW || isNUW ? Op0 : Constant::getNullValue(Op0->getType()); // (X >> A) << A -> X Value *X; @@ -1386,12 +1392,6 @@ static Value *SimplifyLShrInst(Value *Op0, Value *Op1, bool isExact, MaxRecurse)) return V; - // undef >>l X -> 0 - // undef >>l X -> undef (if it's exact) - if (match(Op0, m_Undef())) - return isExact ? UndefValue::get(Op0->getType()) - : Constant::getNullValue(Op0->getType()); - // (X << A) >> A -> X Value *X; if (match(Op0, m_NUWShl(m_Value(X), m_Specific(Op1)))) @@ -1422,12 +1422,6 @@ static Value *SimplifyAShrInst(Value *Op0, Value *Op1, bool isExact, if (match(Op0, m_AllOnes())) return Op0; - // undef >>a X -> 0 - // undef >>a X -> undef (if it's exact) - if (match(Op0, m_Undef())) - return isExact ? UndefValue::get(Op0->getType()) - : Constant::getNullValue(Op0->getType()); - // (X << A) >> A -> X Value *X; if (match(Op0, m_NSWShl(m_Value(X), m_Specific(Op1)))) |