<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 - "opt -globalopt" crashes with Assertion `isa<IntegerType>(Elt->getType()) && "Index must be an integer"' failed."
   href="https://bugs.llvm.org/show_bug.cgi?id=39751">39751</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>"opt -globalopt" crashes with Assertion `isa<IntegerType>(Elt->getType()) && "Index must be an integer"' failed.
          </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>Interprocedural Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>mikael.holmen@ericsson.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=21144" name="attach_21144" title="reproducer">attachment 21144</a> <a href="attachment.cgi?id=21144&action=edit" title="reproducer">[details]</a></span>
reproducer

Running
 opt -o - -S bbi-21289.ll -globalopt

gives

opt: ../lib/IR/Constants.cpp:355: llvm::Constant
*llvm::Constant::getAggregateElement(llvm::Constant *) const: Assertion
`isa<IntegerType>(Elt->getType()) && "Index must be an integer"' failed.
Stack dump:
0.      Program arguments: build-all/bin/opt -o - -S bbi-21289.ll -globalopt 
1.      Running pass 'Global Variable Optimizer' on module 'bbi-21289.ll'.
#0 0x00000000023d5534 PrintStackTraceSignalHandler(void*)
(build-all/bin/opt+0x23d5534)
#1 0x00000000023d3660 llvm::sys::RunSignalHandlers()
(build-all/bin/opt+0x23d3660)
#2 0x00000000023d5898 SignalHandler(int) (build-all/bin/opt+0x23d5898)
#3 0x00007fc571e38330 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x10330)
#4 0x00007fc570a27c37 gsignal
/build/eglibc-ripdx6/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
#5 0x00007fc570a2b028 abort
/build/eglibc-ripdx6/eglibc-2.19/stdlib/abort.c:91:0
#6 0x00007fc570a20bf6 __assert_fail_base
/build/eglibc-ripdx6/eglibc-2.19/assert/assert.c:92:0
#7 0x00007fc570a20ca2 (/lib/x86_64-linux-gnu/libc.so.6+0x2fca2)
#8 0x0000000001d20ac5 llvm::Constant::getAggregateElement(llvm::Constant*)
const (build-all/bin/opt+0x1d20ac5)
#9 0x000000000178e61a
llvm::ConstantFoldLoadThroughGEPConstantExpr(llvm::Constant*,
llvm::ConstantExpr*) (build-all/bin/opt+0x178e61a)
#10 0x0000000001eb6be6 CleanupConstantGlobalUsers(llvm::Value*,
llvm::Constant*, llvm::DataLayout const&, llvm::TargetLibraryInfo*)
(build-all/bin/opt+0x1eb6be6)
#11 0x0000000001eb2ae8 processInternalGlobal(llvm::GlobalVariable*,
llvm::GlobalStatus const&, llvm::TargetLibraryInfo*,
llvm::function_ref<llvm::DominatorTree& (llvm::Function&)>)
(build-all/bin/opt+0x1eb2ae8)
#12 0x0000000001eb23e3 processGlobal(llvm::GlobalValue&,
llvm::TargetLibraryInfo*, llvm::function_ref<llvm::DominatorTree&
(llvm::Function&)>) (build-all/bin/opt+0x1eb23e3)
#13 0x0000000001eafc75 optimizeGlobalsInModule(llvm::Module&, llvm::DataLayout
const&, llvm::TargetLibraryInfo*, llvm::function_ref<llvm::TargetTransformInfo&
(llvm::Function&)>, llvm::function_ref<llvm::BlockFrequencyInfo&
(llvm::Function&)>, llvm::function_ref<llvm::DominatorTree& (llvm::Function&)>)
(build-all/bin/opt+0x1eafc75)
#14 0x0000000001eb1569 (anonymous
namespace)::GlobalOptLegacyPass::runOnModule(llvm::Module&)
(build-all/bin/opt+0x1eb1569)
#15 0x0000000001de58ba llvm::legacy::PassManagerImpl::run(llvm::Module&)
(build-all/bin/opt+0x1de58ba)
#16 0x00000000007acc8b main (build-all/bin/opt+0x7acc8b)
#17 0x00007fc570a12f45 __libc_start_main
/build/eglibc-ripdx6/eglibc-2.19/csu/libc-start.c:321:0
#18 0x000000000079219d _start (build-all/bin/opt+0x79219d)
Abort

The problem seems to be that

 llvm::ConstantFoldLoadThroughGEPConstantExpr

in ConstantFolding.cpp called from CleanupConstantGlobalUsers in GlobalOpt.cpp
can't handle GEPs with vector indices.

When it crashes GEP is

  %0 = getelementptr inbounds [2 x i16], [2 x i16]* @a, i32 0, <2 x i32> <i32
0, i32 1>

and CE is

  <2 x i16*> getelementptr inbounds ([2 x i16], [2 x i16]* @a, <2 x i64>
zeroinitializer, <2 x i64> <i64 0, i64 1>)</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>