<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 --- - GVN crashes on the following example"
   href="https://llvm.org/bugs/show_bug.cgi?id=24397">24397</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>GVN crashes on the following example
          </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>All
          </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>Scalar Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>michael.v.zolotukhin@gmail.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>Test case:
----------------------
; RUN: opt -basicaa -gvn -march arm64 < %s | FileCheck %s
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"

%struct.A = type { [30 x %struct.B*] }
%struct.B = type {  %struct.B* }

@A = external global %struct.A, align 8
@B = external global [50 x %struct.B], align 8

; CHECK-LABEL: @foo
; CHECK: ret void
define void @foo()  {
entry:
  br  label %BB1

entry2:
  br  label %BB2

BB1:
  %idxprom = load i64, i64* undef, align 1
  %arrayidx = getelementptr inbounds %struct.A, %struct.A* @A, i64 0, i32 0,
i64 %idxprom
  %p = load %struct.B*, %struct.B** %arrayidx, align 8
  %cmpnull = icmp eq %struct.B* %p, null
  br i1 %cmpnull, label %BB2, label %exit

BB2:
  %bc = bitcast %struct.B** %arrayidx to i64*
  %load = load i64, i64* %bc, align 8
  store i64 %load, i64* bitcast (%struct.B** getelementptr inbounds ([50 x
%struct.B], [50 x %struct.B]* @B, i64 0, i64 35, i32 0) to i64*), align 8
  br label %exit

exit:
  ret void
}
----------------------

Stack trace:
$ opt -basicaa -gvn < r.ll -march arm64 -S
Assertion failed: (isa<X>(Val) && "cast<Ty>() argument of incompatible type!"),
function cast, file
/Users/buildslave/devel/llvm.git/include/llvm/Support/Casting.h, line 237.
0  opt                      0x000000010c85cafe
llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 46
...
9  opt                      0x000000010b2f94ec
llvm::cast_retty<llvm::Instruction, llvm::Value*>::ret_type
llvm::cast<llvm::Instruction, llvm::Value>(llvm::Value*) + 108
10 opt                      0x000000010b979f6d
llvm::PHITransAddr::InsertPHITranslatedSubExpr(llvm::Value*, llvm::BasicBlock*,
llvm::BasicBlock*, llvm::DominatorTree const&,
llvm::SmallVectorImpl<llvm::Instruction*>&) + 237
11 opt                      0x000000010b97a224
llvm::PHITransAddr::InsertPHITranslatedSubExpr(llvm::Value*, llvm::BasicBlock*,
llvm::BasicBlock*, llvm::DominatorTree const&,
llvm::SmallVectorImpl<llvm::Instruction*>&) + 932
12 opt                      0x000000010b97a01b
llvm::PHITransAddr::InsertPHITranslatedSubExpr(llvm::Value*, llvm::BasicBlock*,
llvm::BasicBlock*, llvm::DominatorTree const&,
llvm::SmallVectorImpl<llvm::Instruction*>&) + 411
13 opt                      0x000000010b979e06
llvm::PHITransAddr::PHITranslateWithInsertion(llvm::BasicBlock*,
llvm::BasicBlock*, llvm::DominatorTree const&,
llvm::SmallVectorImpl<llvm::Instruction*>&) + 86
14 opt                      0x000000010c5703fe (anonymous
namespace)::GVN::PerformLoadPRE(llvm::LoadInst*, llvm::SmallVector<(anonymous
namespace)::AvailableValueInBlock, 64u>&, llvm::SmallVector<llvm::BasicBlock*,
64u>&) + 2654
15 opt                      0x000000010c56e80e (anonymous
namespace)::GVN::processNonLocalLoad(llvm::LoadInst*) + 1390
16 opt                      0x000000010c56ac8f (anonymous
namespace)::GVN::processLoad(llvm::LoadInst*) + 1551</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>