From 72f991cdedeeabc72d00b3d79ecc55a3a025dd81 Mon Sep 17 00:00:00 2001 From: Elena Demikhovsky Date: Sun, 25 Jun 2017 13:36:20 +0000 Subject: [PATCH] AVX-512: Fixed a crash during legalization of <3 x i8> type The compiler fails with assertion during legalization of SETCC for <3 x i8> operands. The result is extended to <4 x i8> and then truncated <4 x i1>. It does not happen on AVX2, because the final result of SETCC is <4 x i32>. Differential Revision: https://reviews.llvm.org/D34503 llvm-svn: 306242 --- .../SelectionDAG/LegalizeIntegerTypes.cpp | 3 +- llvm/test/CodeGen/X86/avx512-vec3-crash.ll | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 llvm/test/CodeGen/X86/avx512-vec3-crash.ll diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp index a3ba52a148ee..75fec7bd1d48 100644 --- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp @@ -615,9 +615,8 @@ SDValue DAGTypeLegalizer::PromoteIntRes_SETCC(SDNode *N) { SDValue SetCC = DAG.getNode(N->getOpcode(), dl, SVT, LHS, RHS, N->getOperand(2)); - assert(NVT.bitsLE(SVT) && "Integer type overpromoted?"); // Convert to the expected type. - return DAG.getNode(ISD::TRUNCATE, dl, NVT, SetCC); + return DAG.getSExtOrTrunc(SetCC, dl, NVT); } SDValue DAGTypeLegalizer::PromoteIntRes_SHL(SDNode *N) { diff --git a/llvm/test/CodeGen/X86/avx512-vec3-crash.ll b/llvm/test/CodeGen/X86/avx512-vec3-crash.ll new file mode 100644 index 000000000000..281456c235b5 --- /dev/null +++ b/llvm/test/CodeGen/X86/avx512-vec3-crash.ll @@ -0,0 +1,31 @@ +; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py +; RUN: llc -mcpu=skx -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s + +; This test crashed during type legalization of SETCC result type. +define <3 x i8 > @foo(<3 x i8>%x, <3 x i8>%a, <3 x i8>%b) { +; CHECK-LABEL: foo: +; CHECK: # BB#0: +; CHECK-NEXT: vmovd %edi, %xmm0 +; CHECK-NEXT: vpinsrd $1, %esi, %xmm0, %xmm0 +; CHECK-NEXT: vpinsrd $2, %edx, %xmm0, %xmm0 +; CHECK-NEXT: vpslld $24, %xmm0, %xmm0 +; CHECK-NEXT: vpsrad $24, %xmm0, %xmm0 +; CHECK-NEXT: vmovd %ecx, %xmm1 +; CHECK-NEXT: vpinsrd $1, %r8d, %xmm1, %xmm1 +; CHECK-NEXT: vpinsrd $2, %r9d, %xmm1, %xmm1 +; CHECK-NEXT: vpslld $24, %xmm1, %xmm1 +; CHECK-NEXT: vpsrad $24, %xmm1, %xmm1 +; CHECK-NEXT: vpcmpgtd %xmm0, %xmm1, %k0 +; CHECK-NEXT: vpmovm2d %k0, %xmm0 +; CHECK-NEXT: vpextrb $0, %xmm0, %eax +; CHECK-NEXT: vpextrb $4, %xmm0, %edx +; CHECK-NEXT: vpextrb $8, %xmm0, %ecx +; CHECK-NEXT: # kill: %AL %AL %EAX +; CHECK-NEXT: # kill: %DL %DL %EDX +; CHECK-NEXT: # kill: %CL %CL %ECX +; CHECK-NEXT: retq + %cmp.i = icmp slt <3 x i8> %x, %a + %res = sext <3 x i1> %cmp.i to <3 x i8> + ret <3 x i8> %res +} +