Skip to content

Commit 82da0ca

Browse files
committed
[X86] Add computeKnownBits support for PEXT.
The number of zeros in the mask provides a lower bound on the number of leading zeros in the result.
1 parent a4b1fde commit 82da0ca

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34064,6 +34064,14 @@ void X86TargetLowering::computeKnownBitsForTargetNode(const SDValue Op,
3406434064
Known.Zero.setLowBits(Known2.countMinTrailingZeros());
3406534065
break;
3406634066
}
34067+
case X86ISD::PEXT: {
34068+
Known = DAG.computeKnownBits(Op.getOperand(1), DemandedElts, Depth + 1);
34069+
// The result has as many leading zeros as the number of zeroes in the mask.
34070+
unsigned Count = Known.Zero.countPopulation();
34071+
Known.Zero = APInt::getHighBitsSet(BitWidth, Count);
34072+
Known.One.clearAllBits();
34073+
break;
34074+
}
3406734075
case X86ISD::VTRUNC:
3406834076
case X86ISD::VTRUNCS:
3406934077
case X86ISD::VTRUNCUS:

llvm/test/CodeGen/X86/bmi2-x86_64.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ define i64 @pext64_knownbits(i64 %x, i64 %y) {
7979
; CHECK: # %bb.0:
8080
; CHECK-NEXT: movabsq $6148914691236517205, %rax # imm = 0x5555555555555555
8181
; CHECK-NEXT: pextq %rax, %rdi, %rax
82-
; CHECK-NEXT: movl %eax, %eax
8382
; CHECK-NEXT: retq
8483
%tmp = tail call i64 @llvm.x86.bmi.pext.64(i64 %x, i64 6148914691236517205)
8584
%tmp2 = and i64 %tmp, 4294967295

llvm/test/CodeGen/X86/bmi2.ll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,12 @@ define i32 @pext32_knownbits(i32 %x) {
258258
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
259259
; X86-NEXT: movl $1431655765, %ecx # imm = 0x55555555
260260
; X86-NEXT: pextl %ecx, %eax, %eax
261-
; X86-NEXT: movzwl %ax, %eax
262261
; X86-NEXT: retl
263262
;
264263
; X64-LABEL: pext32_knownbits:
265264
; X64: # %bb.0:
266265
; X64-NEXT: movl $1431655765, %eax # imm = 0x55555555
267266
; X64-NEXT: pextl %eax, %edi, %eax
268-
; X64-NEXT: movzwl %ax, %eax
269267
; X64-NEXT: retq
270268
%tmp = tail call i32 @llvm.x86.bmi.pext.32(i32 %x, i32 1431655765)
271269
%tmp2 = and i32 %tmp, 65535

0 commit comments

Comments
 (0)