[llvm] 4d6f4c9 - [X86] Special handle for v1i1 during ExtractBitFromMaskVector

Phoebe Wang via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 2 19:50:05 PDT 2023


Author: Phoebe Wang
Date: 2023-08-03T09:50:31+08:00
New Revision: 4d6f4c9c93c1eebeab9951a48730c4d8bfbd3f20

URL: https://github.com/llvm/llvm-project/commit/4d6f4c9c93c1eebeab9951a48730c4d8bfbd3f20
DIFF: https://github.com/llvm/llvm-project/commit/4d6f4c9c93c1eebeab9951a48730c4d8bfbd3f20.diff

LOG: [X86] Special handle for v1i1 during ExtractBitFromMaskVector

Fixes #64322

Reviewed By: RKSimon

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

Added: 
    llvm/test/CodeGen/X86/pr64322.ll

Modified: 
    llvm/lib/Target/X86/X86ISelLowering.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 4879a8d776c3a7..2aed22c8778389 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -17619,6 +17619,19 @@ static SDValue ExtractBitFromMaskVector(SDValue Op, SelectionDAG &DAG,
     unsigned NumElts = VecVT.getVectorNumElements();
     // Extending v8i1/v16i1 to 512-bit get better performance on KNL
     // than extending to 128/256bit.
+    if (NumElts == 1) {
+      if (Subtarget.hasDQI()) {
+        Vec = DAG.getNode(ISD::INSERT_SUBVECTOR, dl, MVT::v8i1,
+                          DAG.getUNDEF(MVT::v8i1), Vec,
+                          DAG.getIntPtrConstant(0, dl));
+        return DAG.getBitcast(MVT::i8, Vec);
+      }
+      Vec = DAG.getNode(ISD::INSERT_SUBVECTOR, dl, MVT::v16i1,
+                        DAG.getUNDEF(MVT::v16i1), Vec,
+                        DAG.getIntPtrConstant(0, dl));
+      return DAG.getNode(ISD::TRUNCATE, dl, MVT::i8,
+                         DAG.getBitcast(MVT::i16, Vec));
+    }
     MVT ExtEltVT = (NumElts <= 8) ? MVT::getIntegerVT(128 / NumElts) : MVT::i8;
     MVT ExtVecVT = MVT::getVectorVT(ExtEltVT, NumElts);
     SDValue Ext = DAG.getNode(ISD::SIGN_EXTEND, dl, ExtVecVT, Vec);

diff  --git a/llvm/test/CodeGen/X86/pr64322.ll b/llvm/test/CodeGen/X86/pr64322.ll
new file mode 100644
index 00000000000000..7289232cff6793
--- /dev/null
+++ b/llvm/test/CodeGen/X86/pr64322.ll
@@ -0,0 +1,21 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mcpu=icelake-server | FileCheck %s
+
+ at G = global <1 x i1> <i1 true>
+ at G.1 = global i1 false
+
+define void @foo(i32 %x) {
+; CHECK-LABEL: foo:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    movq G at GOTPCREL(%rip), %rax
+; CHECK-NEXT:    kmovb (%rax), %k0
+; CHECK-NEXT:    kmovd %k0, %eax
+; CHECK-NEXT:    andb $1, %al
+; CHECK-NEXT:    movq G.1 at GOTPCREL(%rip), %rcx
+; CHECK-NEXT:    movb %al, (%rcx)
+; CHECK-NEXT:    retq
+  %LGV = load <1 x i1>, ptr @G
+  %E = extractelement <1 x i1> %LGV, i32 %x
+  store i1 %E, ptr @G.1
+  ret void
+}


        


More information about the llvm-commits mailing list