Skip to content

Commit f58fbfc

Browse files
committed
[X86][CodeGen] Add a dag pattern to fix #64323
After recent patch 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. Reviewed By: pengfei Differential Revision: https://reviews.llvm.org/D158355
1 parent 7dc6566 commit f58fbfc

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21705,14 +21705,15 @@ SDValue DAGCombiner::visitEXTRACT_VECTOR_ELT(SDNode *N) {
2170521705
if (DAG.isKnownNeverZero(Index))
2170621706
return DAG.getUNDEF(ScalarVT);
2170721707

21708-
// Check if the result type doesn't match the inserted element type. A
21709-
// SCALAR_TO_VECTOR may truncate the inserted element and the
21710-
// EXTRACT_VECTOR_ELT may widen the extracted vector.
21708+
// Check if the result type doesn't match the inserted element type.
21709+
// The inserted element and extracted element may have mismatched bitwidth.
21710+
// As a result, EXTRACT_VECTOR_ELT may extend or truncate the extracted vector.
2171121711
SDValue InOp = VecOp.getOperand(0);
2171221712
if (InOp.getValueType() != ScalarVT) {
21713-
assert(InOp.getValueType().isInteger() && ScalarVT.isInteger() &&
21714-
InOp.getValueType().bitsGT(ScalarVT));
21715-
return DAG.getNode(ISD::TRUNCATE, DL, ScalarVT, InOp);
21713+
assert(InOp.getValueType().isInteger() && ScalarVT.isInteger());
21714+
if (InOp.getValueType().bitsGT(ScalarVT))
21715+
return DAG.getNode(ISD::TRUNCATE, DL, ScalarVT, InOp);
21716+
return DAG.getNode(ISD::ANY_EXTEND, DL, ScalarVT, InOp);
2171621717
}
2171721718
return InOp;
2171821719
}

llvm/test/CodeGen/X86/pr64323.ll

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 2
2+
3+
; RUN: llc < %s -mtriple=x86_64 -mcpu=icelake-server | FileCheck %s
4+
5+
define <1 x i1> @f(<1 x float> %0) nounwind {
6+
; CHECK-LABEL: f:
7+
; CHECK: # %bb.0:
8+
; CHECK-NEXT: pushq %rax
9+
; CHECK-NEXT: vcmpeqss {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0, %k0
10+
; CHECK-NEXT: kmovd %k0, %edi
11+
; CHECK-NEXT: callq g@PLT
12+
; CHECK-NEXT: popq %rcx
13+
; CHECK-NEXT: retq
14+
%A = fcmp oeq <1 x float> %0, <float 0x36A0000000000000>
15+
%B = call <1 x i1> @g(<1 x i1> %A)
16+
ret <1 x i1> %B
17+
}
18+
19+
declare <1 x i1> @g(<1 x i1> %0) nounwind

0 commit comments

Comments
 (0)