[PATCH] D158355: [X86][CodeGen] Add a dag pattern to fix #64323

Peter Rong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 19 21:09:48 PDT 2023


Peter created this revision.
Herald added subscribers: steven.zhang, pengfei, hiraditya.
Herald added a project: All.
Peter requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

After recent patch D30189 <https://reviews.llvm.org/D30189>, #64323's error message become a new one.
When DAGCombiner was optimizing `(vextract (scalar_to_vector val, 0) -> val`, it didn't
consider the possibility that the inserted value type has less bit than the dest type.
This patch fixes that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158355

Files:
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/test/CodeGen/X86/pr64323.ll


Index: llvm/test/CodeGen/X86/pr64323.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/pr64323.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 -mcpu=icelake-server | FileCheck %s
+
+define <1 x i1> @f(<1 x float> %0) {
+; CHECK-LABEL: f:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    pushq %rax
+; CHECK-NEXT:    .cfi_def_cfa_offset 16
+; CHECK-NEXT:    vcmpeqss {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0, %k0
+; CHECK-NEXT:    kmovd %k0, %edi
+; CHECK-NEXT:    callq g at PLT
+; CHECK-NEXT:    popq %rcx
+; CHECK-NEXT:    .cfi_def_cfa_offset 8
+; CHECK-NEXT:    retq
+  %A = fcmp oeq <1 x float> %0, <float 0x36A0000000000000>
+  %B = call <1 x i1> @g(<1 x i1> %A)
+  ret <1 x i1> %B
+}
+
+declare <1 x i1> @g(<1 x i1> %0)
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -21708,9 +21708,13 @@
     // EXTRACT_VECTOR_ELT may widen the extracted vector.
     SDValue InOp = VecOp.getOperand(0);
     if (InOp.getValueType() != ScalarVT) {
-      assert(InOp.getValueType().isInteger() && ScalarVT.isInteger() &&
-             InOp.getValueType().bitsGT(ScalarVT));
-      return DAG.getNode(ISD::TRUNCATE, DL, ScalarVT, InOp);
+      assert(InOp.getValueType().isInteger() && ScalarVT.isInteger());
+      if (InOp.getValueType().bitsGT(ScalarVT))
+        return DAG.getNode(ISD::TRUNCATE, DL, ScalarVT, InOp);
+      else if (InOp.getValueType().bitsLE(ScalarVT))
+        return DAG.getNode(ISD::ANY_EXTEND, DL, ScalarVT, InOp);
+      else
+        llvm_unreachable("Insert and extract types should have different bits");
     }
     return InOp;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158355.551803.patch
Type: text/x-patch
Size: 1890 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230820/9a9edfe3/attachment.bin>


More information about the llvm-commits mailing list