Skip to content

[DAG] SimplifyDemandedBits - ICMP_SLT(X,0) - only sign mask of X is required #164589

@RKSimon

Description

@RKSimon

Similar to what we did in #163981 for X86ISD::PCMPGT - when we are testing for a negative value, then we only need to demand the signbit

define <4 x i32> @select(<4 x i32> %x, <4 x i32> %y, <4 x i32> %a, <4 x i32> %b) {
  %umax = tail call <4 x i32> @llvm.umax.v4i32(<4 x i32> %x, <4 x i32> %y)
  %cmp = icmp slt <4 x i32> %umax, zeroinitializer
  %res = select <4 x i1> %cmp, <4 x i32> %a, <4 x i32> %b
  ret <4 x i32> %res
}

llvm -mcpu=x86-64-v4

select: # @select
  vpmaxud %xmm1, %xmm0, %xmm0
  vpmovd2m %xmm0, %k1
  vpblendmd %xmm2, %xmm3, %xmm0 {%k1}
  retq

the VPMAXUD is unnecessary - could be:

select: # @select
  vpor %xmm1, %xmm0, %xmm0
  vpmovd2m %xmm0, %k1
  vpblendmd %xmm2, %xmm3, %xmm0 {%k1}
  retq

We already have the ISD::UMAX -> ISD::OR simplification in place but we don't recursively call SimplifyDemandedBits from the ISD::SETCC node

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions