[PATCH] D25135: [InstCombine] sub X, sext(bool Y) -> add X, zext(bool Y)

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 13 14:44:12 PDT 2016

spatel added a comment.

In https://reviews.llvm.org/D25135#569638, @efriedma wrote:

> Please make sure we have a test to check that we can correctly reverse the transform in SelectionDAG when we need to (for example, make sure we don't genereate an unnecessary AND for a vector compare on x86).

How did you see that one coming? :)
Indeed, x86 doesn't deal with this and gets worse. This might be the same as the fixes needed before https://reviews.llvm.org/D25485 can proceed...

  define <4 x i32> @foo(<4 x i32> %x, <4 x i32> %y, <4 x i32> %z) {
    %cmp = icmp eq <4 x i32> %x, %y
    %sext = sext <4 x i1> %cmp to <4 x i32>
    %sub = sub <4 x i32> %z, %sext
    ret <4 x i32> %sub

We have this:

  vpcmpeqd	%xmm1, %xmm0, %xmm0
  vpsubd	%xmm0, %xmm2, %xmm0

But with this patch, we get this:

  vpcmpeqd	%xmm1, %xmm0, %xmm0
  vpsrld	$31, %xmm0, %xmm0
  vpaddd	%xmm2, %xmm0, %xmm0


More information about the llvm-commits mailing list