aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Friedman <eli.friedman@gmail.com>2009-07-18 23:06:53 +0000
committerEli Friedman <eli.friedman@gmail.com>2009-07-18 23:06:53 +0000
commit2451a64687b52fdc04d5ec5ffc2bfbbfcae19ea7 (patch)
tree20a4be9608d98dd8b8252a0688761ecf6a859203
parent4cb1e13769856716261a4d315f8202bd918502c3 (diff)
downloadexternal_llvm-2451a64687b52fdc04d5ec5ffc2bfbbfcae19ea7.zip
external_llvm-2451a64687b52fdc04d5ec5ffc2bfbbfcae19ea7.tar.gz
external_llvm-2451a64687b52fdc04d5ec5ffc2bfbbfcae19ea7.tar.bz2
Canonicalize bitcasts between types like <1 x i64> and i64 to
insertelement/extractelement. I'm not entirely sure this is precisely what we want to do: should we prefer bitcast(insertelement) or insertelement(bitcast)? Similarly. should we prefer extractelement(bitcast) or bitcast(extractelement)? git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76345 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp24
-rw-r--r--test/Transforms/InstCombine/bitcast-vec-canon.ll22
2 files changed, 46 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 21b51e4..94547b4 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -9033,6 +9033,29 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
}
}
+ if (const VectorType *DestVTy = dyn_cast<VectorType>(DestTy)) {
+ if (DestVTy->getNumElements() == 1) {
+ if (!isa<VectorType>(SrcTy)) {
+ Value *Elem = InsertCastBefore(Instruction::BitCast, Src,
+ DestVTy->getElementType(), CI);
+ return InsertElementInst::Create(Context->getUndef(DestTy), Elem,
+ Context->getNullValue(Type::Int32Ty));
+ }
+ // FIXME: Canonicalize bitcast(insertelement) -> insertelement(bitcast)
+ }
+ }
+
+ if (const VectorType *SrcVTy = dyn_cast<VectorType>(SrcTy)) {
+ if (SrcVTy->getNumElements() == 1) {
+ if (!isa<VectorType>(DestTy)) {
+ Instruction *Elem =
+ new ExtractElementInst(Src, Context->getNullValue(Type::Int32Ty));
+ InsertNewInstBefore(Elem, CI);
+ return CastInst::Create(Instruction::BitCast, Elem, DestTy);
+ }
+ }
+ }
+
if (ShuffleVectorInst *SVI = dyn_cast<ShuffleVectorInst>(Src)) {
if (SVI->hasOneUse()) {
// Okay, we have (bitconvert (shuffle ..)). Check to see if this is
@@ -12477,6 +12500,7 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
Context->getConstantInt(Type::Int32Ty, SrcIdx, false));
}
}
+ // FIXME: Canonicalize extractelement(bitcast) -> bitcast(extractelement)
}
return 0;
}
diff --git a/test/Transforms/InstCombine/bitcast-vec-canon.ll b/test/Transforms/InstCombine/bitcast-vec-canon.ll
new file mode 100644
index 0000000..6bb986a
--- /dev/null
+++ b/test/Transforms/InstCombine/bitcast-vec-canon.ll
@@ -0,0 +1,22 @@
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep element | count 4
+
+define double @a(<1 x i64> %y) {
+ %c = bitcast <1 x i64> %y to double
+ ret double %c
+}
+
+define i64 @b(<1 x i64> %y) {
+ %c = bitcast <1 x i64> %y to i64
+ ret i64 %c
+}
+
+define <1 x i64> @c(double %y) {
+ %c = bitcast double %y to <1 x i64>
+ ret <1 x i64> %c
+}
+
+define <1 x i64> @d(i64 %y) {
+ %c = bitcast i64 %y to <1 x i64>
+ ret <1 x i64> %c
+}
+