[llvm] 6749dc3 - [InstCombine] Don't transform bitcasts between x86_mmx and v1i64 into insertelement/extractelement

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 7 15:44:34 PST 2019


Author: Craig Topper
Date: 2019-11-07T15:14:13-08:00
New Revision: 6749dc3446671df05235d0a218c426a314ac33cd

URL: https://github.com/llvm/llvm-project/commit/6749dc3446671df05235d0a218c426a314ac33cd
DIFF: https://github.com/llvm/llvm-project/commit/6749dc3446671df05235d0a218c426a314ac33cd.diff

LOG: [InstCombine] Don't transform bitcasts between x86_mmx and v1i64 into insertelement/extractelement

x86_mmx is conceptually a vector already. Don't introduce an extra conversion between it and scalar i64.

I'm using VectorType::isValidElementType which checks for floating point, integer, and pointers to hopefully make this more readable than just blacklisting x86_mmx.

Differential Revision: https://reviews.llvm.org/D69964

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
    llvm/test/Transforms/InstCombine/bitcast-vec-canon.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index 65aaef28d87a..0390368c4bb4 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -2359,7 +2359,8 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
   }
 
   if (VectorType *DestVTy = dyn_cast<VectorType>(DestTy)) {
-    if (DestVTy->getNumElements() == 1 && !SrcTy->isVectorTy()) {
+    if (DestVTy->getNumElements() == 1 &&
+        VectorType::isValidElementType(SrcTy)) {
       Value *Elem = Builder.CreateBitCast(Src, DestVTy->getElementType());
       return InsertElementInst::Create(UndefValue::get(DestTy), Elem,
                      Constant::getNullValue(Type::getInt32Ty(CI.getContext())));
@@ -2391,7 +2392,7 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
     if (SrcVTy->getNumElements() == 1) {
       // If our destination is not a vector, then make this a straight
       // scalar-scalar cast.
-      if (!DestTy->isVectorTy()) {
+      if (VectorType::isValidElementType(DestTy)) {
         Value *Elem =
           Builder.CreateExtractElement(Src,
                      Constant::getNullValue(Type::getInt32Ty(CI.getContext())));

diff  --git a/llvm/test/Transforms/InstCombine/bitcast-vec-canon.ll b/llvm/test/Transforms/InstCombine/bitcast-vec-canon.ll
index 8b408e746b4a..ee77e0629f4b 100644
--- a/llvm/test/Transforms/InstCombine/bitcast-vec-canon.ll
+++ b/llvm/test/Transforms/InstCombine/bitcast-vec-canon.ll
@@ -40,8 +40,7 @@ define <1 x i64> @d(i64 %y) {
 
 define x86_mmx @e(<1 x i64> %y) {
 ; CHECK-LABEL: @e(
-; CHECK-NEXT:    [[TMP1:%.*]] = extractelement <1 x i64> %y, i32 0
-; CHECK-NEXT:    [[C:%.*]] = bitcast i64 [[TMP1]] to x86_mmx
+; CHECK-NEXT:    [[C:%.*]] = bitcast <1 x i64> %y to x86_mmx
 ; CHECK-NEXT:    ret x86_mmx [[C]]
 ;
   %c = bitcast <1 x i64> %y to x86_mmx
@@ -50,8 +49,7 @@ define x86_mmx @e(<1 x i64> %y) {
 
 define <1 x i64> @f(x86_mmx %y) {
 ; CHECK-LABEL: @f(
-; CHECK-NEXT:    [[TMP1:%.*]] = bitcast x86_mmx %y to i64
-; CHECK-NEXT:    [[C:%.*]] = insertelement <1 x i64> undef, i64 [[TMP1]], i32 0
+; CHECK-NEXT:    [[C:%.*]] = bitcast x86_mmx %y to <1 x i64>
 ; CHECK-NEXT:    ret <1 x i64> [[C]]
 ;
   %c = bitcast x86_mmx %y to <1 x i64>


        


More information about the llvm-commits mailing list