diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index 0ec343f07d2..1b50c4aa9dd 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -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: diff --git a/test/Transforms/InstCombine/bitcast-vec-uniform.ll b/test/Transforms/InstCombine/bitcast-vec-uniform.ll index 1fba1632693..ef428894e72 100644 --- a/test/Transforms/InstCombine/bitcast-vec-uniform.ll +++ b/test/Transforms/InstCombine/bitcast-vec-uniform.ll @@ -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> 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> 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 +} +