diff options
author | Huihui Zhang <huihuiz@quicinc.com> | 2020-01-29 10:48:57 -0800 |
---|---|---|
committer | Huihui Zhang <huihuiz@quicinc.com> | 2020-01-29 10:49:08 -0800 |
commit | d2e2fc450e7a25ba71ffec2914262bfd85b8c5bd (patch) | |
tree | bb6468860e349c919cd61f2042602b9aacad1bfa /llvm/lib | |
parent | b500c49cd4f81f067cda721049cb1fd72a5e7bf5 (diff) | |
download | llvm-d2e2fc450e7a25ba71ffec2914262bfd85b8c5bd.zip llvm-d2e2fc450e7a25ba71ffec2914262bfd85b8c5bd.tar.gz llvm-d2e2fc450e7a25ba71ffec2914262bfd85b8c5bd.tar.bz2 |
[ConstantFold][SVE] Fix constant folding for scalable vector binary operations.
Summary:
Scalable vector should not be evaluated element by element.
Add support to handle scalable vector UndefValue.
Reviewers: sdesmalen, huntergr, spatel, lebedev.ri, apazos, efriedma, willlovett
Reviewed By: efriedma
Subscribers: tschuett, hiraditya, rkruppe, psnobl, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D71445
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/IR/ConstantFold.cpp | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp index 6e24f03..3d8ad88 100644 --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -1013,10 +1013,14 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1, return C1; } - // Handle scalar UndefValue. Vectors are always evaluated per element. - bool HasScalarUndef = !C1->getType()->isVectorTy() && - (isa<UndefValue>(C1) || isa<UndefValue>(C2)); - if (HasScalarUndef) { + // Handle scalar UndefValue and scalable vector UndefValue. Fixed-length + // vectors are always evaluated per element. + bool IsScalableVector = + C1->getType()->isVectorTy() && C1->getType()->getVectorIsScalable(); + bool HasScalarUndefOrScalableVectorUndef = + (!C1->getType()->isVectorTy() || IsScalableVector) && + (isa<UndefValue>(C1) || isa<UndefValue>(C2)); + if (HasScalarUndefOrScalableVectorUndef) { switch (static_cast<Instruction::BinaryOps>(Opcode)) { case Instruction::Xor: if (isa<UndefValue>(C1) && isa<UndefValue>(C2)) @@ -1119,7 +1123,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1, } // Neither constant should be UndefValue, unless these are vector constants. - assert(!HasScalarUndef && "Unexpected UndefValue"); + assert((!HasScalarUndefOrScalableVectorUndef) && "Unexpected UndefValue"); // Handle simplifications when the RHS is a constant int. if (ConstantInt *CI2 = dyn_cast<ConstantInt>(C2)) { @@ -1330,6 +1334,11 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1, } } } else if (VectorType *VTy = dyn_cast<VectorType>(C1->getType())) { + // Do not iterate on scalable vector. The number of elements is unknown at + // compile-time. + if (IsScalableVector) + return nullptr; + // Fold each element and create a vector constant from those constants. SmallVector<Constant*, 16> Result; Type *Ty = IntegerType::get(VTy->getContext(), 32); |