[LLVMbugs] [Bug 16776] New: Instcombine transformation causes poor vector codegen [SSE4]

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Aug 2 07:56:05 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=16776

            Bug ID: 16776
           Summary: Instcombine transformation causes poor vector codegen
                    [SSE4]
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: matt at pharr.org
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 10973
  --> http://llvm.org/bugs/attachment.cgi?id=10973&action=edit
test case

The attached test case does a vector compare of a <16 x i8> value with zero and
then a vector select based on the comparison to negate elements that are less
than zero (i.e. computes the absolute value).  If I run it through llc as is, a
single glorious PABSB instruction is generated:

    pabsb    %xmm0, %xmm0

However, if I run "opt -instcombine bug2.ll | llc -o -", I get a 13 instruction
sequence instead of the PABSB:

    movdqa    %xmm0, %xmm1
    pxor    %xmm2, %xmm2
    movdqa    %xmm1, %xmm3
    psrlw    $7, %xmm3
    movdqa    LCPI0_0(%rip), %xmm0
    pand    %xmm0, %xmm3
    pand    %xmm0, %xmm3
    pcmpeqb    %xmm2, %xmm3
    psubb    %xmm1, %xmm2
    pcmpeqd    %xmm0, %xmm0
    pxor    %xmm3, %xmm0
    pblendvb    %xmm2, %xmm1
    movdqa    %xmm1, %xmm0

What seems to be happening is that the "vector (x <s 0) ? -1 : 0 -> ashr x, 31 
 -> all ones if signed." test at the end of InstCombiner::transformSExtICmp()
is kicking in, which in turn leads to the "< 0" test being transformed into a
lshr of 7 and an 'and' of the low bit, which in turn doesn't hit the PABSB
pattern in the X86 code generator.

Interestingly enough, the IR code triggering this transformation is dead code;
if I run "opt -dce -instcombine bug2.ll", then I again get the single PABSB. 
As such, it looks like I can work around this by always running DCE before
InstCombine, but that seems like it may just be plastering over the underlying
issue.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130802/6e2058a3/attachment.html>


More information about the llvm-bugs mailing list