From: Simon Pilgrim Date: Sun, 26 Mar 2017 13:17:55 +0000 (+0000) Subject: [X86][SSE] Add computeKnownBitsForTargetNode support for (V)PSLL/(V)PSRL instructions X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1dc69d0cabeef8feec2ff8baa2c4f16a7f35a68e;p=llvm [X86][SSE] Add computeKnownBitsForTargetNode support for (V)PSLL/(V)PSRL instructions git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298806 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp index fb432a000f0..1cb81d338bd 100644 --- a/lib/Target/X86/X86ISelLowering.cpp +++ b/lib/Target/X86/X86ISelLowering.cpp @@ -26591,6 +26591,7 @@ void X86TargetLowering::computeKnownBitsForTargetNode(const SDValue Op, unsigned Depth) const { unsigned BitWidth = KnownZero.getBitWidth(); unsigned Opc = Op.getOpcode(); + EVT VT = Op.getValueType(); assert((Opc >= ISD::BUILTIN_OP_END || Opc == ISD::INTRINSIC_WO_CHAIN || Opc == ISD::INTRINSIC_W_CHAIN || @@ -26624,9 +26625,33 @@ void X86TargetLowering::computeKnownBitsForTargetNode(const SDValue Op, KnownZero.setBits(NumLoBits, BitWidth); break; } + case X86ISD::VSHLI: + case X86ISD::VSRLI: { + if (auto *ShiftImm = dyn_cast(Op.getOperand(1))) { + if (ShiftImm->getAPIntValue().uge(VT.getScalarSizeInBits())) { + KnownZero = APInt::getAllOnesValue(BitWidth); + break; + } + + DAG.computeKnownBits(Op.getOperand(0), KnownZero, KnownOne, Depth + 1); + unsigned ShAmt = ShiftImm->getZExtValue(); + if (Opc == X86ISD::VSHLI) { + KnownZero = KnownZero << ShAmt; + KnownOne = KnownOne << ShAmt; + // Low bits are known zero. + KnownZero.setLowBits(ShAmt); + } else { + KnownZero = KnownZero.lshr(ShAmt); + KnownOne = KnownOne.lshr(ShAmt); + // High bits are known zero. + KnownZero.setHighBits(ShAmt); + } + } + break; + } case X86ISD::VZEXT: { SDValue N0 = Op.getOperand(0); - unsigned NumElts = Op.getValueType().getVectorNumElements(); + unsigned NumElts = VT.getVectorNumElements(); EVT SrcVT = N0.getValueType(); unsigned InNumElts = SrcVT.getVectorNumElements(); diff --git a/test/CodeGen/X86/combine-abs.ll b/test/CodeGen/X86/combine-abs.ll index 2d71e4f2f27..ac8f790a2ea 100644 --- a/test/CodeGen/X86/combine-abs.ll +++ b/test/CodeGen/X86/combine-abs.ll @@ -84,7 +84,6 @@ define <8 x i32> @combine_v8i32_abs_pos(<8 x i32> %a) { ; CHECK-LABEL: combine_v8i32_abs_pos: ; CHECK: # BB#0: ; CHECK-NEXT: vpsrld $1, %ymm0, %ymm0 -; CHECK-NEXT: vpabsd %ymm0, %ymm0 ; CHECK-NEXT: retq %1 = lshr <8 x i32> %a, %2 = call <8 x i32> @llvm.x86.avx2.pabs.d(<8 x i32> %1)