<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 - llvm.bitreverse.i1000 asserts "Invalid use of small shift amount with oversized value!"""
   href="https://bugs.llvm.org/show_bug.cgi?id=43820">43820</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>llvm.bitreverse.i1000 asserts "Invalid use of small shift amount with oversized value!""
          </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>Backend: X86
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>m.gehre@gmx.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, spatel+llvm@rotateright.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The LLVM IR

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

define i1000 @square(i1000 %A) {
  %Z = call i1000 @llvm.bitreverse.i1000(i1000 %A)
  ret i1000 %Z
}

declare i1000 @llvm.bitreverse.i1000(i1000)

causes the assertion
llc: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:5145: llvm::SDValue
llvm::SelectionDAG::getNode(unsigned int, const llvm::SDLoc &, llvm::EVT,
llvm::SDValue, llvm::SDValue, const llvm::SDNodeFlags): Assertion
`N2.getValueSizeInBits() >= Log2_32_Ceil(N1.getValueSizeInBits()) && "Invalid
use of small shift amount with oversized value!"' failed.
Stack dump:
0.      Program arguments: ./build/bin/llc test1000.ll 
1.      Running pass 'Function Pass Manager' on module
'/home/gehre/test1000.ll'.
2.      Running pass 'X86 DAG->DAG Instruction Selection' on function '@square'
 #0 0x000000000205f714 llvm::sys::PrintStackTrace(llvm::raw_ostream&)
llvm/lib/Support/Unix/Signals.inc:532:13
 #1 0x000000000205f714 PrintStackTraceSignalHandler(void*)
/llvm/lib/Support/Unix/Signals.inc:592:0
 #2 0x000000000205d41e llvm::sys::RunSignalHandlers()
llvm/lib/Support/Signals.cpp:69:18
 #3 0x000000000205fb28 SignalHandler(int)
llvm/lib/Support/Unix/Signals.inc:384:1
 #4 0x00007ffff7bc8890 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x12890)
 #5 0x00007ffff689be97 raise
/build/glibc-OTsEL5/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #6 0x00007ffff689d801 abort /build/glibc-OTsEL5/glibc-2.27/stdlib/abort.c:81:0
 #7 0x00007ffff688d39a __assert_fail_base
/build/glibc-OTsEL5/glibc-2.27/assert/assert.c:89:0
 #8 0x00007ffff688d412 (/lib/x86_64-linux-gnu/libc.so.6+0x30412)
 #9 0x0000000001e881e5 llvm::SelectionDAG::getNode(unsigned int, llvm::SDLoc
const&, llvm::EVT, llvm::SDValue, llvm::SDValue, llvm::SDNodeFlags)
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp:0:0
#10 0x0000000001f33fab
llvm::DAGTypeLegalizer::PromoteIntRes_BITREVERSE(llvm::SDNode*)
llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp:399:14
#11 0x0000000001f32cb7
llvm::DAGTypeLegalizer::PromoteIntegerResult(llvm::SDNode*, unsigned int)
llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp:59:32

when running it through llc.

>From looking at it, getShiftAmountTyForConstant tries to avoid the assertion by
increasing the type of the shift amount based on how big the actual shift
amount is, but the assert in SelectionDAG checks if the type is big enough to
hold all possible shift amounts.
In the example above, the actual shift amount is 24 (promoting i1000 to i1024),
so i8 is enough to hold 24. Still SelectionDAG asserts because i8 cannot hold
all possible shift values of an i1000.</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>