diff options
author | David Majnemer <david.majnemer@gmail.com> | 2014-12-10 21:38:05 +0000 |
---|---|---|
committer | David Majnemer <david.majnemer@gmail.com> | 2014-12-10 21:38:05 +0000 |
commit | 89cf6d79ebc573647c562e5f2bd6c4d11a839f8b (patch) | |
tree | 7f32ef6048967398e371ab3a82d2942c9dc71dc8 /llvm/lib/IR/ConstantFold.cpp | |
parent | db0b13cef02411caadddf91a57c7c1ffafe34cd2 (diff) | |
download | llvm-89cf6d79ebc573647c562e5f2bd6c4d11a839f8b.zip llvm-89cf6d79ebc573647c562e5f2bd6c4d11a839f8b.tar.gz llvm-89cf6d79ebc573647c562e5f2bd6c4d11a839f8b.tar.bz2 |
ConstantFold: an undef shift amount results in undef
X shifted by undef results in undef because the undef value can
represent values greater than the width of the operands.
llvm-svn: 223968
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index cd40908..49ef302 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -951,21 +951,22 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, return C1; return Constant::getAllOnesValue(C1->getType()); // undef | X -> ~0 case Instruction::LShr: - if (isa<UndefValue>(C2) && isa<UndefValue>(C1)) - return C1; // undef lshr undef -> undef - return Constant::getNullValue(C1->getType()); // X lshr undef -> 0 - // undef lshr X -> 0 + // X >>l undef -> undef + if (isa<UndefValue>(C2)) + return C2; + // undef >>l X -> 0 + return Constant::getNullValue(C1->getType()); case Instruction::AShr: - if (!isa<UndefValue>(C2)) // undef ashr X --> all ones - return Constant::getAllOnesValue(C1->getType()); - else if (isa<UndefValue>(C1)) - return C1; // undef ashr undef -> undef - else - return C1; // X ashr undef --> X + // X >>a undef -> undef + if (isa<UndefValue>(C2)) + return C2; + // undef >>a X -> all ones + return Constant::getAllOnesValue(C1->getType()); case Instruction::Shl: - if (isa<UndefValue>(C2) && isa<UndefValue>(C1)) - return C1; // undef shl undef -> undef - // undef << X -> 0 or X << undef -> 0 + // X << undef -> undef + if (isa<UndefValue>(C2)) + return C2; + // undef << X -> 0 return Constant::getNullValue(C1->getType()); } } |