[llvm] 2058c98 - [InstCombine] limit bitcast+insertelement transform to x86 MMX type

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Wed May 6 10:12:44 PDT 2020


Author: Sanjay Patel
Date: 2020-05-06T13:12:36-04:00
New Revision: 2058c98715f6baf59fae1e1d617958cea39236b4

URL: https://github.com/llvm/llvm-project/commit/2058c98715f6baf59fae1e1d617958cea39236b4
DIFF: https://github.com/llvm/llvm-project/commit/2058c98715f6baf59fae1e1d617958cea39236b4.diff

LOG: [InstCombine] limit bitcast+insertelement transform to x86 MMX type

This is unusual for the general case because we are replacing
1 instruction with 2.

Splitting from a potential conflicting transform in D79171

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 c8d2f62e19c0..5c748cade372 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -2484,11 +2484,11 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
   }
 
   if (VectorType *DestVTy = dyn_cast<VectorType>(DestTy)) {
-    if (DestVTy->getNumElements() == 1 && !SrcTy->isVectorTy()) {
+    // Beware: messing with this target-specific oddity may cause trouble.
+    if (DestVTy->getNumElements() == 1 && SrcTy->isX86_MMXTy()) {
       Value *Elem = Builder.CreateBitCast(Src, DestVTy->getElementType());
       return InsertElementInst::Create(UndefValue::get(DestTy), Elem,
                      Constant::getNullValue(Type::getInt32Ty(CI.getContext())));
-      // FIXME: Canonicalize bitcast(insertelement) -> insertelement(bitcast)
     }
 
     if (isa<IntegerType>(SrcTy)) {

diff  --git a/llvm/test/Transforms/InstCombine/bitcast-vec-canon.ll b/llvm/test/Transforms/InstCombine/bitcast-vec-canon.ll
index 4d39651af34d..73aa226bd586 100644
--- a/llvm/test/Transforms/InstCombine/bitcast-vec-canon.ll
+++ b/llvm/test/Transforms/InstCombine/bitcast-vec-canon.ll
@@ -22,8 +22,7 @@ define i64 @b(<1 x i64> %y) {
 
 define <1 x i64> @c(double %y) {
 ; CHECK-LABEL: @c(
-; CHECK-NEXT:    [[TMP1:%.*]] = bitcast double [[Y:%.*]] to i64
-; CHECK-NEXT:    [[C:%.*]] = insertelement <1 x i64> undef, i64 [[TMP1]], i32 0
+; CHECK-NEXT:    [[C:%.*]] = bitcast double [[Y:%.*]] to <1 x i64>
 ; CHECK-NEXT:    ret <1 x i64> [[C]]
 ;
   %c = bitcast double %y to <1 x i64>


        


More information about the llvm-commits mailing list