Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4753,7 +4753,7 @@ bool SelectionDAG::isKnownToBeAPowerOfTwo(SDValue Val,

case ISD::ROTL:
case ISD::ROTR:
return isKnownToBeAPowerOfTwo(Val.getOperand(0), /*OrZero=*/false,
return isKnownToBeAPowerOfTwo(Val.getOperand(0), DemandedElts, OrZero,
Depth + 1);

case ISD::SMIN:
Expand Down
72 changes: 72 additions & 0 deletions llvm/test/CodeGen/X86/known-pow2.ll
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ declare i32 @llvm.smin.i32(i32, i32)
declare i32 @llvm.smax.i32(i32, i32)
declare i32 @llvm.fshl.i32(i32, i32, i32)
declare i32 @llvm.fshr.i32(i32, i32, i32)
declare <4 x i32> @llvm.fshl.v4i32(<4 x i32>, <4 x i32>, <4 x i32>)
declare <4 x i32> @llvm.fshr.v4i32(<4 x i32>, <4 x i32>, <4 x i32>)
Comment thread
mirimmad marked this conversation as resolved.
Resolved

define <4 x i32> @pow2_non_splat_vec(<4 x i32> %x) {
; CHECK-LABEL: pow2_non_splat_vec:
Expand Down Expand Up @@ -1006,3 +1008,73 @@ define i32 @pow2_blsi_sub(i32 %x, i32 %a) {
%r = and i32 %x_sub_y, %y
ret i32 %r
}

define i1 @pow2_rotl_extract_vec(<4 x i32> %a0, <4 x i32> %rotamt, i32 %x) {
; CHECK-LABEL: pow2_rotl_extract_vec:
; CHECK: # %bb.0:
; CHECK-NEXT: pxor %xmm2, %xmm2
; CHECK-NEXT: pcmpgtd %xmm0, %xmm2
; CHECK-NEXT: movl $4096, %eax # imm = 0x1000
; CHECK-NEXT: movd %eax, %xmm0
; CHECK-NEXT: movl $1024, %eax # imm = 0x400
; CHECK-NEXT: movd %eax, %xmm3
; CHECK-NEXT: pand %xmm2, %xmm3
; CHECK-NEXT: pandn %xmm0, %xmm2
; CHECK-NEXT: por %xmm2, %xmm3
; CHECK-NEXT: pslld $23, %xmm1
; CHECK-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm1
; CHECK-NEXT: paddd {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm1
; CHECK-NEXT: cvttps2dq %xmm1, %xmm0
; CHECK-NEXT: pmuludq %xmm3, %xmm0
; CHECK-NEXT: pshufd {{.*#+}} xmm1 = xmm0[1,1,3,3]
; CHECK-NEXT: por %xmm0, %xmm1
; CHECK-NEXT: movd %xmm1, %eax
; CHECK-NEXT: notl %edi
; CHECK-NEXT: testl %edi, %eax
; CHECK-NEXT: sete %al
; CHECK-NEXT: retq

%cmp = icmp sgt <4 x i32> zeroinitializer, %a0
Comment thread
mirimmad marked this conversation as resolved.
Resolved
%powvec = select <4 x i1> %cmp, <4 x i32> <i32 1024, i32 1235, i32 2048, i32 4096>, <4 x i32> <i32 4096, i32 5679, i32 8192, i32 16384>
%d = call <4 x i32> @llvm.fshl.v4i32(<4 x i32> %powvec, <4 x i32> %powvec, <4 x i32> %rotamt)
Comment thread
mirimmad marked this conversation as resolved.
Resolved
%elt = extractelement <4 x i32> %d, i32 0
%and = and i32 %x, %elt
%r = icmp eq i32 %and, %elt
Comment thread
mirimmad marked this conversation as resolved.
Resolved
ret i1 %r
}


define i1 @pow2_rotr_extract_vec(<4 x i32> %a0, <4 x i32> %rotamt, i32 %x) {
; CHECK-LABEL: pow2_rotr_extract_vec:
; CHECK: # %bb.0:
; CHECK-NEXT: pxor %xmm2, %xmm2
; CHECK-NEXT: pxor %xmm3, %xmm3
; CHECK-NEXT: pcmpgtd %xmm0, %xmm3
; CHECK-NEXT: movl $4096, %eax # imm = 0x1000
; CHECK-NEXT: movd %eax, %xmm0
; CHECK-NEXT: movl $1024, %eax # imm = 0x400
; CHECK-NEXT: movd %eax, %xmm4
; CHECK-NEXT: pand %xmm3, %xmm4
; CHECK-NEXT: pandn %xmm0, %xmm3
; CHECK-NEXT: por %xmm3, %xmm4
; CHECK-NEXT: psubd %xmm1, %xmm2
; CHECK-NEXT: pslld $23, %xmm2
; CHECK-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm2
; CHECK-NEXT: paddd {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm2
; CHECK-NEXT: cvttps2dq %xmm2, %xmm0
; CHECK-NEXT: pmuludq %xmm4, %xmm0
; CHECK-NEXT: pshufd {{.*#+}} xmm1 = xmm0[1,1,3,3]
; CHECK-NEXT: por %xmm0, %xmm1
; CHECK-NEXT: movd %xmm1, %eax
; CHECK-NEXT: notl %edi
; CHECK-NEXT: testl %edi, %eax
; CHECK-NEXT: sete %al
; CHECK-NEXT: retq
%cmp = icmp sgt <4 x i32> zeroinitializer, %a0
%powvec = select <4 x i1> %cmp, <4 x i32> <i32 1024, i32 1235, i32 2048, i32 4096>, <4 x i32> <i32 4096, i32 5679, i32 8192, i32 16384>
%d = call <4 x i32> @llvm.fshr.v4i32(<4 x i32> %powvec, <4 x i32> %powvec, <4 x i32> %rotamt)
%elt = extractelement <4 x i32> %d, i32 0
%and = and i32 %x, %elt
%r = icmp eq i32 %and, %elt
ret i1 %r
}
Loading