From 1d838d593f84c175d5bd809cef647707954a39bb Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Mon, 12 Aug 2019 10:56:05 +0000 Subject: [PATCH] [TargetLowering] SimplifyDemandedBits - call SimplifyMultipleUseDemandedBits for ISD::TRUNCATE git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368553 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/TargetLowering.cpp | 5 +++++ test/CodeGen/X86/bitcast-vector-bool.ll | 18 ++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/lib/CodeGen/SelectionDAG/TargetLowering.cpp index 411d146e2ab..9027bea0390 100644 --- a/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -1700,6 +1700,11 @@ bool TargetLowering::SimplifyDemandedBits( return true; Known = Known.trunc(BitWidth); + // Attempt to avoid multi-use ops if we don't need anything from them. + if (SDValue NewSrc = SimplifyMultipleUseDemandedBits( + Src, TruncMask, DemandedElts, TLO.DAG, Depth + 1)) + return TLO.CombineTo(Op, TLO.DAG.getNode(ISD::TRUNCATE, dl, VT, NewSrc)); + // If the input is only used by this truncate, see if we can shrink it based // on the known demanded bits. if (Src.getNode()->hasOneUse()) { diff --git a/test/CodeGen/X86/bitcast-vector-bool.ll b/test/CodeGen/X86/bitcast-vector-bool.ll index 07ae428e24b..57aa53199af 100644 --- a/test/CodeGen/X86/bitcast-vector-bool.ll +++ b/test/CodeGen/X86/bitcast-vector-bool.ll @@ -376,12 +376,11 @@ define i16 @bitcast_v32i8_to_v2i16(<32 x i8> %a0) nounwind { ; ; AVX1-LABEL: bitcast_v32i8_to_v2i16: ; AVX1: # %bb.0: -; AVX1-NEXT: vpmovmskb %xmm0, %eax -; AVX1-NEXT: vextractf128 $1, %ymm0, %xmm0 ; AVX1-NEXT: vpmovmskb %xmm0, %ecx -; AVX1-NEXT: shll $16, %ecx -; AVX1-NEXT: orl %eax, %ecx -; AVX1-NEXT: vmovd %ecx, %xmm0 +; AVX1-NEXT: vextractf128 $1, %ymm0, %xmm0 +; AVX1-NEXT: vpmovmskb %xmm0, %eax +; AVX1-NEXT: shll $16, %eax +; AVX1-NEXT: vmovd %eax, %xmm0 ; AVX1-NEXT: vpextrw $1, %xmm0, %eax ; AVX1-NEXT: addl %ecx, %eax ; AVX1-NEXT: # kill: def $ax killed $ax killed $eax @@ -632,13 +631,12 @@ define i16 @bitcast_v32i16_to_v2i16(<32 x i16> %a0) nounwind { ; AVX1: # %bb.0: ; AVX1-NEXT: vextractf128 $1, %ymm0, %xmm2 ; AVX1-NEXT: vpacksswb %xmm2, %xmm0, %xmm0 -; AVX1-NEXT: vpmovmskb %xmm0, %eax +; AVX1-NEXT: vpmovmskb %xmm0, %ecx ; AVX1-NEXT: vextractf128 $1, %ymm1, %xmm0 ; AVX1-NEXT: vpacksswb %xmm0, %xmm1, %xmm0 -; AVX1-NEXT: vpmovmskb %xmm0, %ecx -; AVX1-NEXT: shll $16, %ecx -; AVX1-NEXT: orl %eax, %ecx -; AVX1-NEXT: vmovd %ecx, %xmm0 +; AVX1-NEXT: vpmovmskb %xmm0, %eax +; AVX1-NEXT: shll $16, %eax +; AVX1-NEXT: vmovd %eax, %xmm0 ; AVX1-NEXT: vpextrw $1, %xmm0, %eax ; AVX1-NEXT: addl %ecx, %eax ; AVX1-NEXT: # kill: def $ax killed $ax killed $eax -- 2.50.1