summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/IR/ConstantFold.cpp3
-rw-r--r--llvm/test/Transforms/ConstProp/trunc_vec.ll9
2 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp
index 9124c111935..b96d1540d71 100644
--- a/llvm/lib/IR/ConstantFold.cpp
+++ b/llvm/lib/IR/ConstantFold.cpp
@@ -674,6 +674,9 @@ Constant *llvm::ConstantFoldCastInstruction(unsigned opc, Constant *V,
}
return nullptr;
case Instruction::Trunc: {
+ if (V->getType()->isVectorTy())
+ return nullptr;
+
uint32_t DestBitWidth = cast<IntegerType>(DestTy)->getBitWidth();
if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
return ConstantInt::get(V->getContext(),
diff --git a/llvm/test/Transforms/ConstProp/trunc_vec.ll b/llvm/test/Transforms/ConstProp/trunc_vec.ll
new file mode 100644
index 00000000000..99db329cdd2
--- /dev/null
+++ b/llvm/test/Transforms/ConstProp/trunc_vec.ll
@@ -0,0 +1,9 @@
+; RUN: opt -constprop < %s
+
+; Make sure we don't crash on this one
+
+define <8 x i8> @test_truc_vec() {
+ %x = bitcast <2 x i64> <i64 1, i64 2> to <8 x i16>
+ %y = trunc <8 x i16> %x to <8 x i8>
+ ret <8 x i8> %y
+}
OpenPOWER on IntegriCloud