From 30d519d92487a35136bac458d48694879b4a2060 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Tue, 29 May 2018 20:04:10 +0000 Subject: [PATCH] [X86] Fix a potential crash that occur after r333419. The code could issue a truncate from a small type to larger type. We need to extend in that case instead. llvm-svn: 333460 --- lib/Target/X86/X86ISelLowering.cpp | 3 +-- test/CodeGen/X86/combine-select.ll | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index ad4c9528776..fb1d30b28e1 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -32142,8 +32142,7 @@ static SDValue combineSelect(SDNode *N, SelectionDAG &DAG, cast(AndNode.getOperand(1))->getAPIntValue() == 1) { // LHS and RHS swapped due to // setcc outputting 1 when AND resulted in 0 and vice versa. - if (AndNode.getValueType() != MVT::i8) - AndNode = DAG.getNode(ISD::TRUNCATE, DL, MVT::i8, AndNode); + AndNode = DAG.getZExtOrTrunc(AndNode, DL, MVT::i8); return DAG.getNode(ISD::SELECT, DL, VT, AndNode, RHS, LHS); } } diff --git a/test/CodeGen/X86/combine-select.ll b/test/CodeGen/X86/combine-select.ll index 58be308f505..7cbb9831ba9 100644 --- a/test/CodeGen/X86/combine-select.ll +++ b/test/CodeGen/X86/combine-select.ll @@ -105,3 +105,23 @@ entry: %6 = insertelement <4 x float> %a, float %5, i32 0 ret <4 x float> %6 } + +; Make sure we don't crash trying to truncate the and instruction i4->i8. We need to extend instead. +define <4 x float> @select_mask_add_ss_small_mask_type(<4 x float> %w, i4 %u, <4 x float> %a, <4 x float> %b) { +; CHECK-LABEL: select_mask_add_ss_small_mask_type: +; CHECK: ## %bb.0: ## %entry +; CHECK-NEXT: kmovw %edi, %k1 +; CHECK-NEXT: vaddss %xmm2, %xmm1, %xmm0 {%k1} +; CHECK-NEXT: retq +entry: + %0 = extractelement <4 x float> %b, i32 0 + %1 = extractelement <4 x float> %a, i32 0 + %2 = fadd float %1, %0 + %3 = and i4 %u, 1 + %4 = icmp eq i4 %3, 0 + %5 = extractelement <4 x float> %w, i32 0 + %6 = select i1 %4, float %5, float %2 + %7 = insertelement <4 x float> %a, float %6, i32 0 + ret <4 x float> %7 +} +