[llvm-commits] [llvm] r125776 - in /llvm/trunk: include/llvm/ADT/APFloat.h lib/Support/APFloat.cpp lib/VMCore/ConstantFold.cpp lib/VMCore/Constants.cpp test/Transforms/InstCombine/bitcast-vec-uniform.ll
Nadav Rotem
nadav.rotem at intel.com
Thu Feb 17 13:22:27 PST 2011
Author: nadav
Date: Thu Feb 17 15:22:27 2011
New Revision: 125776
URL: http://llvm.org/viewvc/llvm-project?rev=125776&view=rev
Log:
Enhance constant folding of bitcast operations on vectors of floats.
Add getAllOnesValue of FP numbers to Constants and APFloat.
Add more tests.
Modified:
llvm/trunk/include/llvm/ADT/APFloat.h
llvm/trunk/lib/Support/APFloat.cpp
llvm/trunk/lib/VMCore/ConstantFold.cpp
llvm/trunk/lib/VMCore/Constants.cpp
llvm/trunk/test/Transforms/InstCombine/bitcast-vec-uniform.ll
Modified: llvm/trunk/include/llvm/ADT/APFloat.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/APFloat.h?rev=125776&r1=125775&r2=125776&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/APFloat.h (original)
+++ llvm/trunk/include/llvm/ADT/APFloat.h Thu Feb 17 15:22:27 2011
@@ -246,6 +246,13 @@
static APFloat getSmallestNormalized(const fltSemantics &Sem,
bool Negative = false);
+ /// getAllOnesValue - Returns a float which is bitcasted from
+ /// an all one value int.
+ ///
+ /// \param BitWidth - Select float type
+ /// \param isIEEE - If 128 bit number, select between PPC and IEEE
+ static APFloat getAllOnesValue(unsigned BitWidth, bool isIEEE = false);
+
/// Profile - Used to insert APFloat objects, or objects that contain
/// APFloat objects, into FoldingSets.
void Profile(FoldingSetNodeID& NID) const;
Modified: llvm/trunk/lib/Support/APFloat.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/APFloat.cpp?rev=125776&r1=125775&r2=125776&view=diff
==============================================================================
--- llvm/trunk/lib/Support/APFloat.cpp (original)
+++ llvm/trunk/lib/Support/APFloat.cpp Thu Feb 17 15:22:27 2011
@@ -3197,6 +3197,12 @@
llvm_unreachable(0);
}
+APFloat
+APFloat::getAllOnesValue(unsigned BitWidth, bool isIEEE)
+{
+ return APFloat(APInt::getAllOnesValue(BitWidth), isIEEE);
+}
+
APFloat APFloat::getLargest(const fltSemantics &Sem, bool Negative) {
APFloat Val(Sem, fcNormal, Negative);
Modified: llvm/trunk/lib/VMCore/ConstantFold.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/ConstantFold.cpp?rev=125776&r1=125775&r2=125776&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/ConstantFold.cpp (original)
+++ llvm/trunk/lib/VMCore/ConstantFold.cpp Thu Feb 17 15:22:27 2011
@@ -43,8 +43,7 @@
static Constant *BitCastConstantVector(ConstantVector *CV,
const VectorType *DstTy) {
- if (CV->isAllOnesValue() && DstTy->getElementType()->isIntegerTy())
- return Constant::getAllOnesValue(DstTy);
+ if (CV->isAllOnesValue()) return Constant::getAllOnesValue(DstTy);
if (CV->isNullValue()) return Constant::getNullValue(DstTy);
// If this cast changes element count then we can't handle it here:
Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=125776&r1=125775&r2=125776&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Thu Feb 17 15:22:27 2011
@@ -93,7 +93,13 @@
if (const IntegerType *ITy = dyn_cast<IntegerType>(Ty))
return ConstantInt::get(Ty->getContext(),
APInt::getAllOnesValue(ITy->getBitWidth()));
-
+
+ if (Ty->isFloatingPointTy()) {
+ APFloat FL = APFloat::getAllOnesValue(Ty->getPrimitiveSizeInBits(),
+ !Ty->isPPC_FP128Ty());
+ return ConstantFP::get(Ty->getContext(), FL);
+ }
+
SmallVector<Constant*, 16> Elts;
const VectorType *VTy = cast<VectorType>(Ty);
Elts.resize(VTy->getNumElements(), getAllOnesValue(VTy->getElementType()));
Modified: llvm/trunk/test/Transforms/InstCombine/bitcast-vec-uniform.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/bitcast-vec-uniform.ll?rev=125776&r1=125775&r2=125776&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/bitcast-vec-uniform.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/bitcast-vec-uniform.ll Thu Feb 17 15:22:27 2011
@@ -18,7 +18,8 @@
}
; CHECK: @foo
-; CHECK: bitcast
+; CHECK-NOT: bitcast
+; CHECK: ret
; from MultiSource/Benchmarks/Bullet
define <2 x float> @foo() {
@@ -27,4 +28,43 @@
}
+; CHECK: @foo2
+; CHECK-NOT: bitcast
+; CHECK: ret
+define <2 x double> @foo2() {
+ %cast = bitcast i128 -1 to <2 x double>
+ ret <2 x double> %cast
+}
+
+; CHECK: @foo3
+; CHECK-NOT: bitcast
+; CHECK: ret
+define <1 x float> @foo3() {
+ %cast = bitcast i32 -1 to <1 x float>
+ ret <1 x float> %cast
+}
+
+; CHECK: @foo4
+; CHECK-NOT: bitcast
+; CHECK: ret
+define float @foo4() {
+ %cast = bitcast <1 x i32 ><i32 -1> to float
+ ret float %cast
+}
+; CHECK: @foo5
+; CHECK-NOT: bitcast
+; CHECK: ret
+define double @foo5() {
+ %cast = bitcast <2 x i32 ><i32 -1, i32 -1> to double
+ ret double %cast
+}
+
+
+; CHECK: @foo6
+; CHECK-NOT: bitcast
+; CHECK: ret
+define <2 x double> @foo6() {
+ %cast = bitcast <4 x i32><i32 -1, i32 -1, i32 -1, i32 -1> to <2 x double>
+ ret <2 x double> %cast
+}
More information about the llvm-commits
mailing list