1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -jump-threading -S < %s | FileCheck %s
3
4; The indirectbr needs a block address. The add can't produce that.
5; This shouldn't crash.
6define void @cast_with_binop() {
7; CHECK-LABEL: @cast_with_binop(
8; CHECK-NEXT:  bb:
9; CHECK-NEXT:    [[OP:%.*]] = add i64 ptrtoint (i8* inttoptr (i32 1 to i8*) to i64), undef
10; CHECK-NEXT:    [[CAST:%.*]] = inttoptr i64 [[OP]] to i8*
11; CHECK-NEXT:    indirectbr i8* [[CAST]], [label [[BB3:%.*]], label %bb2]
12; CHECK:       bb2:
13; CHECK-NEXT:    unreachable
14; CHECK:       bb3:
15; CHECK-NEXT:    ret void
16;
17bb:
18  %op = add i64 ptrtoint (i8* inttoptr (i32 1 to i8*) to i64), undef
19  %cast = inttoptr i64 %op to i8*
20  indirectbr i8* %cast, [label %bb3, label %bb2]
21bb2:
22  unreachable
23bb3:
24  ret void
25}
26
27; The indirectbr needs a block address. The add can't produce that.
28; This shouldn't crash.
29define void @cast_with_i1(i1 %x, i1 %y) {
30; CHECK-LABEL: @cast_with_i1(
31; CHECK-NEXT:  bb:
32; CHECK-NEXT:    [[OP:%.*]] = add i1 [[X:%.*]], [[Y:%.*]]
33; CHECK-NEXT:    [[CAST:%.*]] = inttoptr i1 [[OP]] to i8*
34; CHECK-NEXT:    indirectbr i8* [[CAST]], [label [[BB3:%.*]], label %bb2]
35; CHECK:       bb2:
36; CHECK-NEXT:    unreachable
37; CHECK:       bb3:
38; CHECK-NEXT:    ret void
39;
40bb:
41  %op = add i1 %x, %y
42  %cast = inttoptr i1 %op to i8*
43  indirectbr i8* %cast, [label %bb3, label %bb2]
44bb2:
45  unreachable
46bb3:
47  ret void
48}
49
50; The indirectbr needs a block address. The cmp can't produce that.
51; This shouldn't crash.
52define void @cast_with_cmp(i1 %x, i1 %y) {
53; CHECK-LABEL: @cast_with_cmp(
54; CHECK-NEXT:  bb:
55; CHECK-NEXT:    [[OP:%.*]] = icmp slt i1 [[X:%.*]], [[Y:%.*]]
56; CHECK-NEXT:    [[CAST:%.*]] = inttoptr i1 [[OP]] to i8*
57; CHECK-NEXT:    indirectbr i8* [[CAST]], [label [[BB3:%.*]], label %bb2]
58; CHECK:       bb2:
59; CHECK-NEXT:    unreachable
60; CHECK:       bb3:
61; CHECK-NEXT:    ret void
62;
63bb:
64  %op = icmp slt i1 %x, %y
65  %cast = inttoptr i1 %op to i8*
66  indirectbr i8* %cast, [label %bb3, label %bb2]
67bb2:
68  unreachable
69bb3:
70  ret void
71}
72