1 ; RUN: opt -S -mtriple=mips64-mti-linux-gnu -codegenprepare < %s | FileCheck %s
3 ; Test that if an address that was sunk from a dominating bb, used in a
4 ; select that is erased along with its' trivally dead operand, that the
5 ; sunken address is not reused if the same address computation occurs
6 ; after the select. Previously, this caused a ICE.
8 %struct.az = type { i32, ptr }
9 %struct.bt = type { i32 }
10 %struct.f = type { %struct.ax, %union.anon }
11 %struct.ax = type { ptr }
12 %union.anon = type { %struct.bd }
13 %struct.bd = type { i64 }
14 %struct.bg = type { i32, i32 }
15 %struct.ap = type { i32, i32 }
17 @ch = common global %struct.f zeroinitializer, align 8
18 @j = common global ptr null, align 8
19 @ck = common global i32 0, align 4
20 @h = common global i32 0, align 4
21 @.str = private unnamed_addr constant [1 x i8] zeroinitializer, align 1
23 define internal void @probestart() {
25 %load0 = load ptr, ptr @j, align 8
26 %bw = getelementptr inbounds %struct.az, ptr %load0, i64 0, i32 1
27 %load1 = load i32, ptr @h, align 4
28 %cond = icmp eq i32 %load1, 0
29 br i1 %cond, label %sw.bb, label %cl
31 sw.bb: ; preds = %entry
32 %call = tail call inreg { i64, i64 } @ba(ptr @ch)
35 cl: ; preds = %sw.bb, %entry
36 %load2 = load ptr, ptr %bw, align 8
37 %tobool = icmp eq ptr %load2, null
38 %load3 = load i32, ptr @ck, align 4
39 %.sink5 = select i1 %tobool, ptr getelementptr (%struct.bg, ptr getelementptr inbounds (%struct.f, ptr @ch, i64 0, i32 1), i64 0, i32 1), ptr getelementptr (%struct.ap, ptr getelementptr inbounds (%struct.f, ptr @ch, i64 0, i32 1), i64 0, i32 1)
40 store i32 %load3, ptr %.sink5, align 4
41 store i32 1, ptr getelementptr inbounds (%struct.f, ptr @ch, i64 0, i32 1, i32 0, i32 0), align 8
42 %load4 = load ptr, ptr %bw, align 8
43 tail call void (ptr, ...) @a(ptr @.str, ptr %load4)
47 ; CHECK-LABEL: @probestart()
49 ; CHECK: %[[I0:[a-z0-9]+]] = load ptr, ptr @j
52 ; CHECK-NOT: %{{[a-z0-9]+}} = load ptr, ptr %bw
53 ; CHECK-NOT: %{{[.a-z0-9]}} = select
54 ; CHECK-NOT: %{{[a-z0-9]+}} = load ptr, ptr %bw
56 ; CHECK: %sunkaddr = getelementptr inbounds i8, ptr %[[I0]], i64 8
57 ; CHECK-NEXT: %{{[a-z0-9]+}} = load ptr, ptr %sunkaddr
58 ; CHECK-NEXT: tail call void (ptr, ...) @a
60 declare inreg { i64, i64 } @ba(ptr)
62 declare void @a(ptr, ...)