[X86] computeKnownBitsForTargetNode - add BEXTR support (PR39153)

Add a KnownBits::extractBits helper
This commit is contained in:
Simon Pilgrim 2020-02-03 15:43:40 +00:00
parent 1cc3db1a66
commit 8ead5df0b1
3 changed files with 30 additions and 1 deletions

View File

@ -157,6 +157,13 @@ public:
return KnownBits(Zero.zextOrTrunc(BitWidth), One.zextOrTrunc(BitWidth));
}
/// Return a KnownBits with the extracted bits
/// [bitPosition,bitPosition+numBits).
KnownBits extractBits(unsigned NumBits, unsigned BitPosition) const {
return KnownBits(Zero.extractBits(NumBits, BitPosition),
One.extractBits(NumBits, BitPosition));
}
/// Returns the minimum number of trailing zero bits.
unsigned countMinTrailingZeros() const {
return Zero.countTrailingOnes();

View File

@ -32721,6 +32721,28 @@ void X86TargetLowering::computeKnownBitsForTargetNode(const SDValue Op,
Known.Zero &= Known2.Zero;
break;
}
case X86ISD::BEXTR: {
SDValue Op0 = Op.getOperand(0);
SDValue Op1 = Op.getOperand(1);
if (auto* Cst1 = dyn_cast<ConstantSDNode>(Op1)) {
unsigned Shift = Cst1->getAPIntValue().extractBitsAsZExtValue(8, 0);
unsigned Length = Cst1->getAPIntValue().extractBitsAsZExtValue(8, 8);
// If the length is 0, the result is 0.
if (Length == 0) {
Known.setAllZero();
break;
}
if ((Shift + Length) <= BitWidth) {
Known = DAG.computeKnownBits(Op0, Depth + 1);
Known = Known.extractBits(Length, Shift);
Known = Known.zextOrTrunc(BitWidth, true /* ExtBitsAreKnownZero */);
}
}
break;
}
}
// Handle target shuffles.

View File

@ -62,7 +62,7 @@ define float @bextr_uitofp(i32 %x, i32 %y) {
; X64: # %bb.0:
; X64-NEXT: movl $3855, %eax # imm = 0xF0F
; X64-NEXT: bextrl %eax, %edi, %eax
; X64-NEXT: cvtsi2ss %rax, %xmm0
; X64-NEXT: cvtsi2ss %eax, %xmm0
; X64-NEXT: retq
%1 = tail call i32 @llvm.x86.bmi.bextr.32(i32 %x, i32 3855)
%2 = uitofp i32 %1 to float