From aafde063aaf09285c701c80cd4b543c2beb523e8 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Sun, 10 Nov 2019 16:20:19 -0800 Subject: [PATCH] [InstCombine] Turn (extractelement <1 x i64/double> (bitcast (x86_mmx))) into a single bitcast from x86_mmx to i64/double. The _m64 type is represented in IR as <1 x i64>. The x86-64 ABI on Linux passes <1 x i64> as a double. MMX intrinsics use x86_mmx type in IR.These things result in a lot of bitcasts in mmx code. There's another instcombine that tries to turn bitcast <1 x i64> to double into extractelement and a bitcast. The combine here tries to reverse this extractelement conversion if we see an mmx type. --- llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp | 7 +++++++ llvm/test/Transforms/InstCombine/bitcast-vec-canon.ll | 3 +-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp index 9c89074..824486c 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp @@ -435,6 +435,13 @@ 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 486a785..21c8e78 100644 --- a/llvm/test/Transforms/InstCombine/bitcast-vec-canon.ll +++ b/llvm/test/Transforms/InstCombine/bitcast-vec-canon.ll @@ -59,8 +59,7 @@ define <1 x i64> @f(x86_mmx %y) { define double @g(x86_mmx %x) { ; CHECK-LABEL: @g( ; CHECK-NEXT: entry: -; CHECK-NEXT: [[BC:%.*]] = bitcast x86_mmx %x to <1 x double> -; CHECK-NEXT: [[TMP0:%.*]] = extractelement <1 x double> [[BC]], i32 0 +; CHECK-NEXT: [[TMP0:%.*]] = bitcast x86_mmx [[X:%.*]] to double ; CHECK-NEXT: ret double [[TMP0]] ; entry: -- 2.7.4