Skip to content

[X86] New VectorCombine regresses vtestps matching #209714

Description

@nikic

https://llvm.godbolt.org/z/dsxerr9Mq

target triple = "x86_64-unknown-linux-gnu"

define i32 @_mm_testc_ps(ptr %a, ptr %b) #0 {
start:
  %0 = load <2 x i64>, ptr %a, align 16
  %1 = load <2 x i64>, ptr %b, align 16
  %_8.i = xor <2 x i64> %0, splat (i64 -1)
  %_7.i = and <2 x i64> %1, %_8.i
  %2 = bitcast <2 x i64> %_7.i to <4 x i32>
  %_51.lobit = ashr <4 x i32> %2, splat (i32 31)
  %_7 = tail call i32 @llvm.vector.reduce.or.v4i32(<4 x i32> %_51.lobit)
  %_6 = icmp eq i32 %_7, 0
  %_0 = zext i1 %_6 to i32
  ret i32 %_0
}

attributes #0 = { "target-features"="+avx"}

VectorCombine transforms this to:

define i32 @_mm_testc_ps(ptr %a, ptr %b) #0 {
start:
  %0 = load <2 x i64>, ptr %a, align 16
  %1 = load <2 x i64>, ptr %b, align 16
  %_8.i = xor <2 x i64> %0, splat (i64 -1)
  %_7.i = and <2 x i64> %1, %_8.i
  %2 = bitcast <2 x i64> %_7.i to <4 x i32>
  %3 = call i32 @llvm.vector.reduce.umax.v4i32(<4 x i32> %2)
  %_6 = icmp sgt i32 %3, -1
  %_0 = zext i1 %_6 to i32
  ret i32 %_0
}

Previous lowering:

_mm_testc_ps:                           # @_mm_testc_ps
        vmovaps xmm0, xmmword ptr [rdi]
        vandnps xmm0, xmm0, xmmword ptr [rsi]
        xor     eax, eax
        vtestps xmm0, xmm0
        sete    al
        ret

New lowering:

_mm_testc_ps:                           # @_mm_testc_ps
        vmovdqa xmm0, xmmword ptr [rdi]
        vpandn  xmm0, xmm0, xmmword ptr [rsi]
        vpshufd xmm1, xmm0, 238                 # xmm1 = xmm0[2,3,2,3]
        vpmaxud xmm0, xmm0, xmm1
        vpshufd xmm1, xmm0, 85                  # xmm1 = xmm0[1,1,1,1]
        vpor    xmm0, xmm0, xmm1
        vmovd   eax, xmm0
        not     eax
        shr     eax, 31
        ret

The expected vtestps is no longer produced.

Relevant VectorCombine changes are presumably #175194 #181998. I think those transforms are fine by themselves though, so this probably needs a backend fix.

Metadata

Metadata

Assignees

Type

Projects

Status
Done

Relationships

None yet

Development

No branches or pull requests

Issue actions