aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ConstantFold.cpp
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-12-18 23:54:43 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-12-18 23:54:43 +0000
commit824e011ad7b400ef79920ae9f84e5f55375720f2 (patch)
treec0f10308543e35c8f479ab06df32bfe20d60637c /llvm/lib/IR/ConstantFold.cpp
parent174476ed963beac6131c0b9c65727452689f6a0b (diff)
downloadllvm-824e011ad7b400ef79920ae9f84e5f55375720f2.zip
llvm-824e011ad7b400ef79920ae9f84e5f55375720f2.tar.gz
llvm-824e011ad7b400ef79920ae9f84e5f55375720f2.tar.bz2
ConstantFold: Shifting undef by zero results in undef
llvm-svn: 224553
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r--llvm/lib/IR/ConstantFold.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 31e962a..9176bf2 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -956,12 +956,18 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
// X >>l undef -> undef
if (isa<UndefValue>(C2))
return C2;
+ // undef >>l 0 -> undef
+ if (match(C2, m_Zero()))
+ return C1;
// undef >>l X -> 0
return Constant::getNullValue(C1->getType());
case Instruction::AShr:
// X >>a undef -> undef
if (isa<UndefValue>(C2))
return C2;
+ // undef >>a 0 -> undef
+ if (match(C2, m_Zero()))
+ return C1;
// TODO: undef >>a X -> undef if the shift is exact
// undef >>a X -> 0
return Constant::getNullValue(C1->getType());
@@ -969,6 +975,9 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
// X << undef -> undef
if (isa<UndefValue>(C2))
return C2;
+ // undef << 0 -> undef
+ if (match(C2, m_Zero()))
+ return C1;
// undef << X -> 0
return Constant::getNullValue(C1->getType());
}