https://bugs.llvm.org/show_bug.cgi?id=39927

            Bug ID: 39927
           Summary: [InstCombine] Attempt to replace MOVMSK with zext
                    (bitcast <X x i1> to iX) to i32
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: unassignedb...@nondot.org
          Reporter: llvm-...@redking.me.uk
                CC: craig.top...@gmail.com, llvm-bugs@lists.llvm.org,
                    llvm-...@redking.me.uk, spatel+l...@rotateright.com

https://godbolt.org/z/SvH3do

Very similar to what we do with SSE BLENDV cases from a comparison+sext that
can be replaced with a select, we should now be able to replace MOVMSK
intrinsics with bitcasts from the comparison result.

PMOVMSKB <X x i8>
MOVMSKPS <X x float>
MOVMSKPD <X x float>

declare i32 @llvm.x86.sse2.pmovmskb.128(<16 x i8>)

define i32 @movmsk_16i8(<16 x i8>, <16 x i8>) {
  %3 = icmp sgt <16 x i8> %0, %1
  %4 = sext <16 x i1> %3 to <16 x i8>
  %5 = tail call i32 @llvm.x86.sse2.pmovmskb.128(<16 x i8> %4)
  ret i32 %5
}

define i32 @movmsk_16i8_select(<16 x i8>, <16 x i8>) {
  %3 = icmp sgt <16 x i8> %0, %1
  %4 = bitcast <16 x i1> %3 to i16
  %5 = zext i16 %4 to i32
  ret i32 %5
}

Cases where the comparison arguments don't match the MOVMSK arguments are
trickier, but this is what I've managed so far (depending on what we do with
the MOVMSK scalar result we should be able to do a lot better):

define i32 @movmsk_8i16(<8 x i16>, <8 x i16>) {
  %3 = icmp sgt <8 x i16> %0, %1
  %4 = sext <8 x i1> %3 to <8 x i16>
  %5 = bitcast <8 x i16> %4 to <16 x i8>
  %6 = tail call i32 @llvm.x86.sse2.pmovmskb.128(<16 x i8> %5)
  ret i32 %6
}

define i32 @movmsk_8i16_select(<8 x i16>, <8 x i16>) {
  %3 = icmp sgt <8 x i16> %0, %1
  %4 = sext <8 x i1> %3 to <8 x i16>
  %5 = bitcast <8 x i16> %4 to <16 x i8>
  %6 = icmp slt <16 x i8> %5, zeroinitializer
  %7 = bitcast <16 x i1> %6 to i16
  %8 = zext i16 %7 to i32
  ret i32 %8
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to