summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/ConstantFold.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2017-03-09 20:42:30 +0000
committerSanjay Patel <spatel@rotateright.com>2017-03-09 20:42:30 +0000
commit7e56366204287a513420a2633daa1f92b009f4bf (patch)
tree6b31c15a01faeef7b206323e080418aabf7067d7 /llvm/lib/IR/ConstantFold.cpp
parentefe949cc67607361525c4b3b2e211677b4805caf (diff)
downloadbcm5719-llvm-7e56366204287a513420a2633daa1f92b009f4bf.tar.gz
bcm5719-llvm-7e56366204287a513420a2633daa1f92b009f4bf.zip
[ConstantFold] vector div/rem with any zero element in divisor is undef
Follow-up for: https://reviews.llvm.org/D30665 https://reviews.llvm.org/rL297390 llvm-svn: 297409
Diffstat (limited to 'llvm/lib/IR/ConstantFold.cpp')
-rw-r--r--llvm/lib/IR/ConstantFold.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 13241c37675..dc7728a4841 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -1209,10 +1209,15 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode,
SmallVector<Constant*, 16> Result;
Type *Ty = IntegerType::get(VTy->getContext(), 32);
for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
- Constant *LHS =
- ConstantExpr::getExtractElement(C1, ConstantInt::get(Ty, i));
- Constant *RHS =
- ConstantExpr::getExtractElement(C2, ConstantInt::get(Ty, i));
+ Constant *ExtractIdx = ConstantInt::get(Ty, i);
+ Constant *LHS = ConstantExpr::getExtractElement(C1, ExtractIdx);
+ Constant *RHS = ConstantExpr::getExtractElement(C2, ExtractIdx);
+
+ // If any element of a divisor vector is zero, the whole op is undef.
+ if ((Opcode == Instruction::SDiv || Opcode == Instruction::UDiv ||
+ Opcode == Instruction::SRem || Opcode == Instruction::URem) &&
+ RHS->isNullValue())
+ return UndefValue::get(VTy);
Result.push_back(ConstantExpr::get(Opcode, LHS, RHS));
}
OpenPOWER on IntegriCloud