[llvm] r216149 - Fix a bug around truncating vector in const prop.

Jiangning Liu jiangning.liu at arm.com
Wed Aug 20 19:12:35 PDT 2014


Author: jiangning
Date: Wed Aug 20 21:12:35 2014
New Revision: 216149

URL: http://llvm.org/viewvc/llvm-project?rev=216149&view=rev
Log:
Fix a bug around truncating vector in const prop.

In constant folding stage, "TRUNC" can't handle vector data type.


Added:
    llvm/trunk/test/Transforms/ConstProp/trunc_vec.ll
Modified:
    llvm/trunk/lib/IR/ConstantFold.cpp

Modified: llvm/trunk/lib/IR/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ConstantFold.cpp?rev=216149&r1=216148&r2=216149&view=diff
==============================================================================
--- llvm/trunk/lib/IR/ConstantFold.cpp (original)
+++ llvm/trunk/lib/IR/ConstantFold.cpp Wed Aug 20 21:12:35 2014
@@ -674,6 +674,9 @@ Constant *llvm::ConstantFoldCastInstruct
     }
     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(),

Added: llvm/trunk/test/Transforms/ConstProp/trunc_vec.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ConstProp/trunc_vec.ll?rev=216149&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/ConstProp/trunc_vec.ll (added)
+++ llvm/trunk/test/Transforms/ConstProp/trunc_vec.ll Wed Aug 20 21:12:35 2014
@@ -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
+}





More information about the llvm-commits mailing list