<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Vector constant folding of comparisons does not follow the vector boolean format"
   href="https://llvm.org/bugs/show_bug.cgi?id=25763">25763</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Vector constant folding of comparisons does not follow the vector boolean format
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Common Code Generator Code
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>silviu.baranga@arm.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>r253504 introduced constant folding for vector setcc operations:

r253504 | rksimon | 2015-11-18 21:17:19 +0000 (Wed, 18 Nov 2015) | 7 lines

[DAGCombiner] Vector constant folding for comparisons

This patch adds support for vector constant folding of integer/float
comparisons.

This requires FoldConstantVectorArithmetic to support scalar constant operands
(in this case ISD::CONDCASE). In future we should be able to support other
scalar constant types as necessary (and possibly start calling
FoldConstantVectorArithmetic for all node creations)

Differential Revision: <a href="http://reviews.llvm.org/D14683">http://reviews.llvm.org/D14683</a>



This folds vector comparisons by using scalar logic per-lane. However, boolean
output format can differ between scalar and vector operations (it can be either
one or negative one for true). On targets where there is a difference between
the scalar and vector boolean formats, this will cause a miscompile.

Reproducer:

target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
target triple = "aarch64--linux-gnu"

declare <8 x i8> @llvm.ctlz.v8i8(<8 x i8>, i1)

define <8 x i16> @dotests_458() {
entry:
  %vclz_v.i = call <8 x i8> @llvm.ctlz.v8i8(<8 x i8> <i8 127, i8 38, i8 -1, i8
-128, i8 127, i8 0, i8 0, i8 0>, i1 false) #6
  %vsra_n = lshr <8 x i8> %vclz_v.i, <i8 5, i8 5, i8 5, i8 5, i8 5, i8 5, i8 5,
i8 5>
  %name_6 = or <8 x i8> %vsra_n, <i8 127, i8 -128, i8 -1, i8 67, i8 84, i8 127,
i8 -1, i8 0>
  %cmp.i603 = icmp slt <8 x i8> %name_6, <i8 -57, i8 -128, i8 127, i8 -128, i8
-1, i8 0, i8 -1, i8 -1>
  %vmovl.i4.i = sext <8 x i1> %cmp.i603 to <8 x i16>
  ret <8 x i16> %vmovl.i4.i
}

Compiled with:
llc -O3 test.ll -o -

Produces:

    .text
    .file    "test.ll"
    .section    .rodata.cst8,"aM",@progbits,8
    .align    3
.LCPI0_0:
    .byte    0                       // 0x0
    .byte    0                       // 0x0
    .byte    1                       // 0x1 ; This should be 0xff!
    .byte    0                       // 0x0
    .byte    0                       // 0x0
    .byte    0                       // 0x0
    .byte    0                       // 0x0
    .byte    0                       // 0x0
    .text
    .globl    dotests_458
    .align    2
    .type    dotests_458,@function
dotests_458:                            // @dotests_458
    .cfi_startproc
// BB#0:                                // %entry
    adrp    x8, .LCPI0_0
    ldr    d0, [x8, :lo12:.LCPI0_0]
    sshll    v0.8h, v0.8b, #0
    ret
.Lfunc_end0:
    .size    dotests_458, .Lfunc_end0-dotests_458
    .cfi_endproc</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>