Fix a regression from r125393;
authorNadav Rotem <nadav.rotem@intel.com>
Sun, 13 Feb 2011 15:45:34 +0000 (15:45 +0000)
committerNadav Rotem <nadav.rotem@intel.com>
Sun, 13 Feb 2011 15:45:34 +0000 (15:45 +0000)
It caused a crash in MultiSource/Benchmarks/Bullet.
Opt hit an assertion with "opt -std-compile-opts" because
Constant::getAllOnesValue doesn't know how to handle floats.

This patch added a test to reproduce the problem and a check that the
destination vector is of integer type.

Thank you Benjamin!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@125459 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/ConstantFold.cpp
test/Transforms/InstCombine/bitcast-vec-uniform.ll

index 0ec343f07d2a0a40e6c13062885c38f0e9bd2f42..1b50c4aa9dde33c4cb572ba8978eda198ca9e31c 100644 (file)
@@ -43,7 +43,8 @@ using namespace llvm;
 static Constant *BitCastConstantVector(ConstantVector *CV,
                                        const VectorType *DstTy) {
 
-  if (CV->isAllOnesValue()) return Constant::getAllOnesValue(DstTy);
+  if (CV->isAllOnesValue() && DstTy->getElementType()->isIntegerTy())
+      return Constant::getAllOnesValue(DstTy);
   if (CV->isNullValue()) return Constant::getNullValue(DstTy);
 
   // If this cast changes element count then we can't handle it here:
index 1fba1632693306eccb58f7cc6c41aa78f227157b..ef428894e72489e69e5ac67b897c2b45e7309d50 100644 (file)
@@ -1,14 +1,30 @@
-; RUN: opt < %s -instcombine -S | not grep bitcast
+; RUN: opt < %s -instcombine -S | FileCheck %s
 
+; CHECK: @a
+; CHECK-NOT: bitcast
+; CHECK: ret
 define <4 x i32> @a(<1 x i64> %y) {
   %c = bitcast <2 x i64> <i64 0, i64 0> to <4 x i32>
   ret <4 x i32> %c
 }
 
+; CHECK: @b
+; CHECK: bitcast
+; CHECK: ret
+
 define <4 x i32> @b(<1 x i64> %y) {
   %c = bitcast <2 x i64> <i64 -1, i64 -1> to <4 x i32>
   ret <4 x i32> %c
 }
 
+; CHECK: @foo
+; CHECK: bitcast
+
+; from MultiSource/Benchmarks/Bullet
+define <2 x float> @foo() {
+  %cast = bitcast i64 -1 to <2 x float>
+  ret <2 x float> %cast
+}
+