From 82f1a8cc092bb814179a2a98cf8c5a1a7a9b8b49 Mon Sep 17 00:00:00 2001 From: Jiangning Liu Date: Thu, 21 Aug 2014 02:12:35 +0000 Subject: [PATCH] Fix a bug around truncating vector in const prop. In constant folding stage, "TRUNC" can't handle vector data type. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216149 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/ConstantFold.cpp | 3 +++ test/Transforms/ConstProp/trunc_vec.ll | 9 +++++++++ 2 files changed, 12 insertions(+) create mode 100644 test/Transforms/ConstProp/trunc_vec.ll diff --git a/lib/IR/ConstantFold.cpp b/lib/IR/ConstantFold.cpp index 9124c111935..b96d1540d71 100644 --- a/lib/IR/ConstantFold.cpp +++ b/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(DestTy)->getBitWidth(); if (ConstantInt *CI = dyn_cast(V)) { return ConstantInt::get(V->getContext(), diff --git a/test/Transforms/ConstProp/trunc_vec.ll b/test/Transforms/ConstProp/trunc_vec.ll new file mode 100644 index 00000000000..99db329cdd2 --- /dev/null +++ b/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> to <8 x i16> + %y = trunc <8 x i16> %x to <8 x i8> + ret <8 x i8> %y +} -- 2.34.1