]> granicus.if.org Git - llvm/commitdiff
[X86] Improve the type checking fast-isel handling of vector bitcasts.
authorCraig Topper <craig.topper@intel.com>
Mon, 1 Jul 2019 07:09:34 +0000 (07:09 +0000)
committerCraig Topper <craig.topper@intel.com>
Mon, 1 Jul 2019 07:09:34 +0000 (07:09 +0000)
We had a bunch of vector size legality checks for the source type
based on feature flags, but we didn't check the destination type at
all beyond ensuring that it was a "simple" type. But this allowed
the destination to be i128 which isn't legal.

This commit changes the code to use TLI's isTypeLegal logic in
place of the all the subtarget checks. Then additionally checks
that the source and dest are vectors.

Fixes 42452

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364729 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86FastISel.cpp
test/CodeGen/X86/pr42452.ll [new file with mode: 0644]

index 46ebbcbee06045f77c61a2ef2c7b5ac881ded35c..31cd83d942096e96d6a7dae1ebeb54b4d8d4c4fe 100644 (file)
@@ -3646,24 +3646,19 @@ X86FastISel::fastSelectInstruction(const Instruction *I)  {
     return true;
   }
   case Instruction::BitCast: {
-    // Select SSE2/AVX bitcasts between 128/256 bit vector types.
+    // Select SSE2/AVX bitcasts between 128/256/512 bit vector types.
     if (!Subtarget->hasSSE2())
       return false;
 
-    EVT SrcVT = TLI.getValueType(DL, I->getOperand(0)->getType());
-    EVT DstVT = TLI.getValueType(DL, I->getType());
-
-    if (!SrcVT.isSimple() || !DstVT.isSimple())
+    MVT SrcVT, DstVT;
+    if (!isTypeLegal(I->getOperand(0)->getType(), SrcVT) ||
+        !isTypeLegal(I->getType(), DstVT))
       return false;
 
-    MVT SVT = SrcVT.getSimpleVT();
-    MVT DVT = DstVT.getSimpleVT();
-
-    if (!SVT.is128BitVector() &&
-        !(Subtarget->hasAVX() && SVT.is256BitVector()) &&
-        !(Subtarget->hasAVX512() && SVT.is512BitVector() &&
-          (Subtarget->hasBWI() || (SVT.getScalarSizeInBits() >= 32 &&
-                                   DVT.getScalarSizeInBits() >= 32))))
+    // Only allow vectors that use xmm/ymm/zmm.
+    if (!SrcVT.isVector() || !DstVT.isVector() ||
+        SrcVT.getVectorElementType() == MVT::i1 ||
+        DstVT.getVectorElementType() == MVT::i1)
       return false;
 
     unsigned Reg = getRegForValue(I->getOperand(0));
diff --git a/test/CodeGen/X86/pr42452.ll b/test/CodeGen/X86/pr42452.ll
new file mode 100644 (file)
index 0000000..f2f0cd2
--- /dev/null
@@ -0,0 +1,37 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown -O0 | FileCheck %s
+
+@b = external global i64, align 8
+
+define void @foo(i1 %c, <2 x i64> %x) {
+; CHECK-LABEL: foo:
+; CHECK:       # %bb.0: # %entry
+; CHECK-NEXT:    # kill: def $dil killed $dil killed $edi
+; CHECK-NEXT:    movq %xmm0, %rax
+; CHECK-NEXT:    pshufd {{.*#+}} xmm0 = xmm0[2,3,0,1]
+; CHECK-NEXT:    movq %xmm0, %rcx
+; CHECK-NEXT:    movb %dil, {{[-0-9]+}}(%r{{[sb]}}p) # 1-byte Spill
+; CHECK-NEXT:    movq %rcx, {{[-0-9]+}}(%r{{[sb]}}p) # 8-byte Spill
+; CHECK-NEXT:  .LBB0_1: # %for.body
+; CHECK-NEXT:    # =>This Inner Loop Header: Depth=1
+; CHECK-NEXT:    movb {{[-0-9]+}}(%r{{[sb]}}p), %al # 1-byte Reload
+; CHECK-NEXT:    testb $1, %al
+; CHECK-NEXT:    jne .LBB0_1
+; CHECK-NEXT:    jmp .LBB0_2
+; CHECK-NEXT:  .LBB0_2: # %for.end
+; CHECK-NEXT:    movq {{[-0-9]+}}(%r{{[sb]}}p), %rax # 8-byte Reload
+; CHECK-NEXT:    movq %rax, b
+; CHECK-NEXT:    retq
+entry:
+  %0 = bitcast <2 x i64> %x to i128
+  br label %for.body
+
+for.body:                                         ; preds = %for.body, %entry
+  br i1 %c, label %for.body, label %for.end
+
+for.end:                                          ; preds = %for.body
+  %1 = lshr i128 %0, 64
+  %2 = trunc i128 %1 to i64
+  store i64 %2, i64* @b, align 8
+  ret void
+}