[llvm] 5ebbabc - [InstCombine] Revert aafde063aaf09285c701c80cd4b543c2beb523e8 and 6749dc3446671df05235d0a218c426a314ac33cd related to bitcast handling of x86_mmx

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 3 14:03:46 PST 2019


Author: Craig Topper
Date: 2019-12-03T14:02:22-08:00
New Revision: 5ebbabc1af360756f402203ba7704bb480f279a7

URL: https://github.com/llvm/llvm-project/commit/5ebbabc1af360756f402203ba7704bb480f279a7
DIFF: https://github.com/llvm/llvm-project/commit/5ebbabc1af360756f402203ba7704bb480f279a7.diff

LOG: [InstCombine] Revert aafde063aaf09285c701c80cd4b543c2beb523e8 and 6749dc3446671df05235d0a218c426a314ac33cd related to bitcast handling of x86_mmx

This reverts these two commits
[InstCombine] Turn (extractelement <1 x i64/double> (bitcast (x86_mmx))) into a single bitcast from x86_mmx to i64/double.
[InstCombine] Don't transform bitcasts between x86_mmx and v1i64 into insertelement/extractelement

We're seeing at least one internal test failure related to a
bitcast that was previously before an inline assembly block
containing emms being placed after it. This leads to the mmx
state ending up not empty after the emms. IR has no way to
make any specific guarantees about this. Reverting these patches
to get back to previous behavior which at least worked for this
test.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
    llvm/lib/Transforms/InstCombine/InstCombineVectorOps.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 078a80de2df4..2171c819fd9e 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -2394,8 +2394,7 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
   }
 
   if (VectorType *DestVTy = dyn_cast<VectorType>(DestTy)) {
-    if (DestVTy->getNumElements() == 1 &&
-        VectorType::isValidElementType(SrcTy)) {
+    if (DestVTy->getNumElements() == 1 && !SrcTy->isVectorTy()) {
       Value *Elem = Builder.CreateBitCast(Src, DestVTy->getElementType());
       return InsertElementInst::Create(UndefValue::get(DestTy), Elem,
                      Constant::getNullValue(Type::getInt32Ty(CI.getContext())));
@@ -2427,7 +2426,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 (VectorType::isValidElementType(DestTy)) {
+      if (!DestTy->isVectorTy()) {
         Value *Elem =
           Builder.CreateExtractElement(Src,
                      Constant::getNullValue(Type::getInt32Ty(CI.getContext())));

diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
index d31cbc0882ee..9fabe9def110 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp
@@ -435,13 +435,6 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
         Worklist.AddValue(EE);
         return CastInst::Create(CI->getOpcode(), EE, EI.getType());
       }
-
-      // If the input is a bitcast from x86_mmx, turn into a single bitcast from
-      // the mmx type to the scalar type.
-      if (CI->getOpcode() == Instruction::BitCast &&
-          EI.getVectorOperandType()->getNumElements() == 1 &&
-          CI->getOperand(0)->getType()->isX86_MMXTy())
-        return new BitCastInst(CI->getOperand(0), EI.getType());
     }
   }
   return nullptr;

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


        


More information about the llvm-commits mailing list