aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR/ConstantFold.cpp
diff options
context:
space:
mode:
authorHuihui Zhang <huihuiz@quicinc.com>2020-01-30 10:44:20 -0800
committerHuihui Zhang <huihuiz@quicinc.com>2020-01-30 10:45:15 -0800
commit34e6552dcbb4f6647746588bb35591a97a7992a3 (patch)
tree859cf66a961cd1f7d5473cbc85e12558e551741a /llvm/lib/IR/ConstantFold.cpp
parent0610637aac9cf2dedbb92da2d52dfbfd9b6331d2 (diff)
downloadllvm-34e6552dcbb4f6647746588bb35591a97a7992a3.zip
llvm-34e6552dcbb4f6647746588bb35591a97a7992a3.tar.gz
llvm-34e6552dcbb4f6647746588bb35591a97a7992a3.tar.bz2
[ConstantFold][SVE] Fix constant folding for scalable vector unary operations.
Summary: Similar to issue D71445. Scalable vector should not be evaluated element by element. Add support to handle scalable vector UndefValue. Reviewers: sdesmalen, efriedma, apazos, huntergr, willlovett Reviewed By: efriedma Subscribers: tschuett, hiraditya, rkruppe, psnobl, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D73678
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r--llvm/lib/IR/ConstantFold.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 3d8ad88..9fd7dbd 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -953,10 +953,14 @@ Constant *llvm::ConstantFoldInsertValueInstruction(Constant *Agg,
Constant *llvm::ConstantFoldUnaryInstruction(unsigned Opcode, Constant *C) {
assert(Instruction::isUnaryOp(Opcode) && "Non-unary instruction detected");
- // Handle scalar UndefValue. Vectors are always evaluated per element.
- bool HasScalarUndef = !C->getType()->isVectorTy() && isa<UndefValue>(C);
+ // Handle scalar UndefValue and scalable vector UndefValue. Fixed-length
+ // vectors are always evaluated per element.
+ bool IsScalableVector =
+ C->getType()->isVectorTy() && C->getType()->getVectorIsScalable();
+ bool HasScalarUndefOrScalableVectorUndef =
+ (!C->getType()->isVectorTy() || IsScalableVector) && isa<UndefValue>(C);
- if (HasScalarUndef) {
+ if (HasScalarUndefOrScalableVectorUndef) {
switch (static_cast<Instruction::UnaryOps>(Opcode)) {
case Instruction::FNeg:
return C; // -undef -> undef
@@ -966,7 +970,7 @@ Constant *llvm::ConstantFoldUnaryInstruction(unsigned Opcode, Constant *C) {
}
// Constant should not be UndefValue, unless these are vector constants.
- assert(!HasScalarUndef && "Unexpected UndefValue");
+ assert(!HasScalarUndefOrScalableVectorUndef && "Unexpected UndefValue");
// We only have FP UnaryOps right now.
assert(!isa<ConstantInt>(C) && "Unexpected Integer UnaryOp");
@@ -979,6 +983,11 @@ Constant *llvm::ConstantFoldUnaryInstruction(unsigned Opcode, Constant *C) {
return ConstantFP::get(C->getContext(), neg(CV));
}
} else if (VectorType *VTy = dyn_cast<VectorType>(C->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);