diff options
| author | 2019-06-23 21:36:31 +0000 | |
|---|---|---|
| committer | 2019-06-23 21:36:31 +0000 | |
| commit | 23f101f37937a1bd4a29726cab2f76e0fb038b35 (patch) | |
| tree | f7da7d6b32c2e07114da399150bfa88d72187012 /gnu/llvm/lib/IR/ConstantFold.cpp | |
| parent | sort previous; ok deraadt (diff) | |
| download | wireguard-openbsd-23f101f37937a1bd4a29726cab2f76e0fb038b35.tar.xz wireguard-openbsd-23f101f37937a1bd4a29726cab2f76e0fb038b35.zip | |
Import LLVM 8.0.0 release including clang, lld and lldb.
Diffstat (limited to 'gnu/llvm/lib/IR/ConstantFold.cpp')
| -rw-r--r-- | gnu/llvm/lib/IR/ConstantFold.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/gnu/llvm/lib/IR/ConstantFold.cpp b/gnu/llvm/lib/IR/ConstantFold.cpp index 90a8366d169..57de6b04230 100644 --- a/gnu/llvm/lib/IR/ConstantFold.cpp +++ b/gnu/llvm/lib/IR/ConstantFold.cpp @@ -916,13 +916,14 @@ Constant *llvm::ConstantFoldInsertValueInstruction(Constant *Agg, return ConstantVector::get(Result); } - -Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, - Constant *C1, Constant *C2) { +Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1, + Constant *C2) { assert(Instruction::isBinaryOp(Opcode) && "Non-binary instruction detected"); - // Handle UndefValue up front. - if (isa<UndefValue>(C1) || isa<UndefValue>(C2)) { + // Handle scalar UndefValue. Vectors are always evaluated per element. + bool HasScalarUndef = !C1->getType()->isVectorTy() && + (isa<UndefValue>(C1) || isa<UndefValue>(C2)); + if (HasScalarUndef) { switch (static_cast<Instruction::BinaryOps>(Opcode)) { case Instruction::Xor: if (isa<UndefValue>(C1) && isa<UndefValue>(C2)) @@ -1024,9 +1025,8 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, } } - // At this point neither constant should be an UndefValue. - assert(!isa<UndefValue>(C1) && !isa<UndefValue>(C2) && - "Unexpected UndefValue"); + // Neither constant should be UndefValue, unless these are vector constants. + assert(!HasScalarUndef && "Unexpected UndefValue"); // Handle simplifications when the RHS is a constant int. if (ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) { @@ -1218,7 +1218,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, } } } else if (VectorType *VTy = dyn_cast<VectorType>(C1->getType())) { - // Perform elementwise folding. + // Fold each element and create a vector constant from those constants. SmallVector<Constant*, 16> Result; Type *Ty = IntegerType::get(VTy->getContext(), 32); for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) { @@ -2052,7 +2052,7 @@ static bool isInBoundsIndices(ArrayRef<IndexTy> Idxs) { static bool isIndexInRangeOfArrayType(uint64_t NumElements, const ConstantInt *CI) { // We cannot bounds check the index if it doesn't fit in an int64_t. - if (CI->getValue().getActiveBits() > 64) + if (CI->getValue().getMinSignedBits() > 64) return false; // A negative index or an index past the end of our sequential type is |
