<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 - LoopVectorizer calls getCastInstrCost for an illegal trunc instruction"
   href="https://bugs.llvm.org/show_bug.cgi?id=36433">36433</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>LoopVectorizer calls getCastInstrCost for an illegal trunc instruction
          </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>enhancement
          </td>
        </tr>

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

        <tr>
          <th>Component</th>
          <td>Loop Optimizer
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>paulsson@linux.vnet.ibm.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=19895" name="attach_19895" title="reduced testcase">attachment 19895</a> <a href="attachment.cgi?id=19895&action=edit" title="reduced testcase">[details]</a></span>
reduced testcase

getInstructionCost():

(gdb) p I->dump()
  %17 = trunc i32 %16 to i16

(gdb) p SrcVecTy->dump()
<2 x i32>

(gdb) p RetTy->dump()
i8

(gdb) p VectorTy->dump()
<2 x i8>

canTruncateToMinimalBitwidth(I, VF) returns true

(gdb) p SrcVecTy->dump()
<2 x i8>

(gdb) p VectorTy->dump()
<2 x i16>

TargetTransformInfo::getCastInstrCost() :
(gdb) p Dst->dump()
<2 x i16>

(gdb) p Src->dump()
<2 x i8>

These types do not make sense for a truncate.

->

lib/Target/SystemZ/SystemZTargetTransformInfo.cpp:520: unsigned int
llvm::SystemZTTIImpl::getVectorTruncCost(llvm::Type*, llvm::Type*): Assertion
`SrcTy->getPrimitiveSizeInBits() > DstTy->getPrimitiveSizeInBits() && "Packing
must reduce size of vector type."' failed.

I would hope that the SystemZ assert is correct, and that the loop vectorizer
should not have made this call.

---

Please excuse my simple patch for disabling instruction combining, which is how
this test case appeared with csmith.

I first tried to reproduce this with opt -debug-pass=Arguments and then using
opt with all the explicit passes without -O3, but that did not work for some
reason. First I got

'LLVM ERROR: Trying to construct TargetPassConfig without a target machine.
Scheduling a CodeGen pass without a target triple set?'

This is weird, because I passed the triple, and it's also in the input file.

When I removed the -targetpassconfig argument, I didn't get the error.

Also did not know how to do something like -stop-before=loop-vectorize.

So, to rerun (with the patch for -disable-instcombine applied):

bin/opt -O3 -mcpu=z13 -o out.opt.ll tc_loopvec_trunc.ll
-enable-loop-versioning-licm -disable-instcombine -enable-tbaa=false

BTW, I see a *lot* of errors when I use my disable-instcombine option. Given
this, I feel like I must ask if instcombine is truly optional, or if other
passes depend on it? Before rewriting instcombine per some discussion I read a
while back ago, I hope people are aware of this...</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>