xref: /llvm-project/llvm/test/Transforms/InstSimplify/simplify-nested-bitcast.ll (revision 10f315dc9c96ec2413881ab55a285e35d80def88)
1; RUN: opt -passes=always-inline -S %s | FileCheck %s
2%0 = type { i64, i64, ptr addrspace(1), ptr addrspace(1) }
3%__aaa_struct = type { { ptr, i32, i32, ptr, ptr addrspace(1) }, %0, [17 x i8], { ptr, i32, i32, ptr, ptr addrspace(1) }, %0, [18 x i8] }
4%struct.__block_descriptor = type { i64, i64 }
5%struct.__block_literal_generic = type { ptr, i32, i32, ptr, ptr addrspace(1) }
6
7@__aaa_struct_ptr = external addrspace(1) global %__aaa_struct
8@__aaa_const_init = constant %__aaa_struct { { ptr, i32, i32, ptr, ptr addrspace(1) } { ptr null, i32 1342177280, i32 0, ptr @bl0_block_invoke, ptr addrspace(1) getelementptr inbounds (%__aaa_struct, ptr addrspace(1) @__aaa_struct_ptr, i32 0, i32 1) }, %0 { i64 0, i64 32, ptr addrspace(1) getelementptr inbounds (%__aaa_struct, ptr addrspace(1) @__aaa_struct_ptr, i32 0, i32 2, i32 0), ptr addrspace(1) null }, [17 x i8] c"bl0_block_invoke\00", { ptr, i32, i32, ptr, ptr addrspace(1) } { ptr null, i32 1342177280, i32 0, ptr @__f1_block_invoke, ptr addrspace(1) getelementptr inbounds (%__aaa_struct, ptr addrspace(1) @__aaa_struct_ptr, i32 0, i32 4) }, %0 { i64 0, i64 32, ptr addrspace(1) getelementptr inbounds (%__aaa_struct, ptr addrspace(1) @__aaa_struct_ptr, i32 0, i32 5, i32 0), ptr addrspace(1) null }, [18 x i8] c"__f1_block_invoke\00" }
9
10; Function Attrs: alwaysinline norecurse nounwind readonly
11define i32 @bl0_block_invoke(ptr addrspace(4) nocapture readnone, ptr addrspace(1) nocapture readonly) #0 {
12entry:
13  %2 = load i32, ptr addrspace(1) %1, align 4
14  %mul = shl nsw i32 %2, 1
15  ret i32 %mul
16}
17
18; Function Attrs: alwaysinline nounwind
19define i32 @f0(ptr addrspace(1), ptr addrspace(4)) #1 {
20entry:
21  %2 = getelementptr inbounds %struct.__block_literal_generic, ptr addrspace(4) %1, i64 0, i32 3
22  %3 = load ptr, ptr addrspace(4) %2, align 8
23  %call = tail call i32 %3(ptr addrspace(4) %1, ptr addrspace(1) %0) #2
24  ret i32 %call
25}
26
27; CHECK-LABEL: define void @f1
28; CHECK: %1 = load ptr, ptr addrspace(4) getelementptr inbounds nuw (i8, ptr addrspace(4) addrspacecast (ptr addrspace(1) @__aaa_struct_ptr to ptr addrspace(4)), i64 16), align 8
29
30; Function Attrs: alwaysinline nounwind
31define void @f1(ptr addrspace(1)) #1 {
32entry:
33  %call = tail call i32 @f0(ptr addrspace(1) %0, ptr addrspace(4) addrspacecast (ptr addrspace(1) @__aaa_struct_ptr to ptr addrspace(4))) #3
34  store i32 %call, ptr addrspace(1) %0, align 4
35  %call1 = tail call i32 @f0(ptr addrspace(1) %0, ptr addrspace(4) addrspacecast (ptr addrspace(1) getelementptr inbounds (%__aaa_struct, ptr addrspace(1) @__aaa_struct_ptr, i32 0, i32 3) to ptr addrspace(4))) #3
36  store i32 %call1, ptr addrspace(1) %0, align 4
37  ret void
38}
39
40; Function Attrs: alwaysinline norecurse nounwind readonly
41define i32 @__f1_block_invoke(ptr addrspace(4) nocapture readnone, ptr addrspace(1) nocapture readonly) #0 {
42entry:
43  %2 = load i32, ptr addrspace(1) %1, align 4
44  %add = add nsw i32 %2, 1
45  ret i32 %add
46}
47
48attributes #0 = { alwaysinline norecurse nounwind readonly }
49attributes #1 = { alwaysinline nounwind }
50attributes #2 = { nobuiltin nounwind }
51attributes #3 = { nobuiltin }
52